Skip to content

Instantly share code, notes, and snippets.

@fatihkayan20
Last active December 19, 2024 07:35
Show Gist options
  • Save fatihkayan20/edcf8602c287870cad95d144a41cacf0 to your computer and use it in GitHub Desktop.
Save fatihkayan20/edcf8602c287870cad95d144a41cacf0 to your computer and use it in GitHub Desktop.
Eslint 9
import { fixupPluginRules } from "@eslint/compat";
import pluginJs from "@eslint/js";
import stylistic from "@stylistic/eslint-plugin";
import checkFile from "eslint-plugin-check-file";
import importPlugin from "eslint-plugin-import";
import jest from "eslint-plugin-jest";
import noRelativeImportPathsPlugin from "eslint-plugin-no-relative-import-paths";
import pluginReact from "eslint-plugin-react";
import pluginReactHooks from "eslint-plugin-react-hooks";
import testingLibrary from "eslint-plugin-testing-library";
import globals from "globals";
import tseslint from "typescript-eslint";
export default [
{
files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"],
},
{
ignores: ["lib/*", "dist/*", "build/*"],
},
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
pluginJs.configs.recommended,
importPlugin.flatConfigs.recommended,
...tseslint.configs.recommended,
{
plugins: {
"react-hooks": pluginReactHooks,
"no-relative-import-paths": noRelativeImportPathsPlugin,
"check-file": checkFile,
react: pluginReact,
jest,
"@stylistic": stylistic,
},
},
{
rules: {
"no-console": "error",
"max-lines": ["error", 250],
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_" },
],
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-expressions": "off", // TODO: Enable this when https://github.com/eslint/eslint/issues/19134 is fixed
"func-style": ["error", "declaration", { allowArrowFunctions: true }],
"space-before-function-paren": [
"error",
{
anonymous: "always",
asyncArrow: "always",
named: "never",
},
],
"space-before-blocks": "error",
curly: "error",
"padding-line-between-statements": [
"error",
{ blankLine: "always", prev: "*", next: "return" },
{ blankLine: "always", prev: ["const", "let", "var"], next: "*" },
{
blankLine: "any",
prev: ["singleline-const", "let", "var"],
next: ["singleline-const", "let", "var"],
},
{ blankLine: "always", prev: "directive", next: "*" },
{ blankLine: "any", prev: "directive", next: "directive" },
],
},
},
// Plugin rules
{
rules: {
"react-hooks/exhaustive-deps": "error",
"import/export": "error", // Ensures there's only one export per file
"import/no-default-export": "error", // Disallows default exports
"import/order": [
"error",
{
pathGroups: [
{
pattern: "@/**/types/**",
group: "type",
},
{
pattern: "@/**/components/**",
group: "internal",
position: "after",
},
{
pattern: "@/**/constants/**",
group: "internal",
position: "after",
},
{
pattern: "@/**/stores/**",
group: "internal",
position: "after",
},
{
pattern: "@/**/utils/**",
group: "internal",
position: "after",
},
{
pattern: "@/**/hooks/**",
group: "internal",
position: "after",
},
],
groups: [
"builtin",
"external",
"type",
"internal",
"parent",
"sibling",
"index",
],
"newlines-between": "always",
alphabetize: { order: "asc", caseInsensitive: true },
},
],
"import/no-unresolved": "off",
"import/namespace": "off",
"import/no-named-as-default": "off",
"import/named": "off",
"check-file/filename-naming-convention": [
"error",
{
"src/**/(?!hooks/**/*.{jsx,tsx,ts,js}": "PASCAL_CASE",
"src/**/hooks/**/use*.{ts,tsx}": "CAMEL_CASE",
},
],
"check-file/folder-naming-convention": [
"error",
{
"src/**/(?!app/|app/**/*/)/**/": "KEBAB_CASE",
},
],
"react/jsx-no-bind": ["error", { allowArrowFunctions: true }],
"react/jsx-key": "error",
"react/jsx-curly-brace-presence": [
"error",
{ props: "never", children: "never" },
],
"@stylistic/lines-around-comment": [
"error",
{
beforeLineComment: true,
beforeBlockComment: true,
allowBlockStart: true,
allowClassStart: true,
allowObjectStart: true,
allowArrayStart: true,
},
],
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.jest,
},
},
},
{
files: [
"example/src/app/**",
"example/app.config.ts",
"eslint.config.mjs",
"src/__tests__/**",
],
rules: {
"import/no-default-export": "off",
},
},
{
files: [
"example/metro.config.js",
"example/babel.config.js",
"src/__tests__/__mocks__/**",
],
rules: {
"@typescript-eslint/no-require-imports": "off",
},
},
{
files: ["example/src/**"],
rules: {
"no-relative-import-paths/no-relative-import-paths": ["warn"],
},
},
{
files: ["src/**/*.test.tsx"],
plugins: {
"testing-library": fixupPluginRules({
rules: testingLibrary.rules,
}),
},
rules: {
"max-lines": ["off"],
...testingLibrary.configs.react.rules,
},
},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment