|
| 1 | +import babelParser from "@babel/eslint-parser"; |
| 2 | +import js from "@eslint/js"; |
| 3 | +import eslintConfigPrettier from "eslint-config-prettier"; |
| 4 | +import eslintPluginImport from "eslint-plugin-import"; |
| 5 | +import eslintPluginPrettier from "eslint-plugin-prettier"; |
| 6 | +import reactPlugin from "eslint-plugin-react"; |
| 7 | +import reactHooksPlugin from "eslint-plugin-react-hooks"; |
| 8 | +import unusedImportsPlugin from "eslint-plugin-unused-imports"; |
| 9 | +import globals from "globals"; |
| 10 | + |
| 11 | +const extensions = ["js", "jsx"]; |
| 12 | + |
| 13 | +export default [ |
| 14 | + { |
| 15 | + files: [`src/**/*.{${extensions.join(",")}}`], |
| 16 | + plugins: { |
| 17 | + react: reactPlugin, |
| 18 | + "react-hooks": reactHooksPlugin, |
| 19 | + import: eslintPluginImport, |
| 20 | + "unused-imports": unusedImportsPlugin, |
| 21 | + prettier: eslintPluginPrettier |
| 22 | + }, |
| 23 | + languageOptions: { |
| 24 | + parser: babelParser, |
| 25 | + parserOptions: { |
| 26 | + requireConfigFile: false, |
| 27 | + babelOptions: { |
| 28 | + babelrc: false, |
| 29 | + configFile: false, |
| 30 | + presets: ["@babel/preset-react"] |
| 31 | + } |
| 32 | + }, |
| 33 | + ecmaVersion: "latest", |
| 34 | + sourceType: "module", |
| 35 | + globals: { |
| 36 | + ...globals.browser, |
| 37 | + ...globals.builtin |
| 38 | + } |
| 39 | + }, |
| 40 | + settings: { |
| 41 | + "import/resolver": { |
| 42 | + node: { |
| 43 | + extensions: extensions.map((extension) => `.${extension}`), |
| 44 | + moduleDirectory: ["node_modules", "src/"] |
| 45 | + } |
| 46 | + }, |
| 47 | + react: { |
| 48 | + version: "detect" |
| 49 | + } |
| 50 | + }, |
| 51 | + rules: { |
| 52 | + ...js.configs.recommended.rules, |
| 53 | + ...reactPlugin.configs.flat.recommended.rules, |
| 54 | + ...reactHooksPlugin.configs.recommended.rules, |
| 55 | + "class-methods-use-this": "error", |
| 56 | + "no-param-reassign": [ |
| 57 | + "error", |
| 58 | + { |
| 59 | + props: true, |
| 60 | + ignorePropertyModificationsFor: [ |
| 61 | + "acc", // for reduce accumulators |
| 62 | + "accumulator", // for reduce accumulators |
| 63 | + "ctx" // for canvas context |
| 64 | + ] |
| 65 | + } |
| 66 | + ], |
| 67 | + "no-underscore-dangle": [ |
| 68 | + "error", |
| 69 | + { |
| 70 | + allowAfterThis: true, |
| 71 | + allowAfterThisConstructor: true |
| 72 | + } |
| 73 | + ], |
| 74 | + "jsx-quotes": "warn", |
| 75 | + "no-multi-spaces": "warn", |
| 76 | + "no-const-assign": "warn", |
| 77 | + "constructor-super": "warn", |
| 78 | + "valid-typeof": "warn", |
| 79 | + "no-extra-semi": "warn", |
| 80 | + "comma-dangle": [ |
| 81 | + "warn", |
| 82 | + { |
| 83 | + arrays: "never", |
| 84 | + objects: "never" |
| 85 | + } |
| 86 | + ], |
| 87 | + "max-params": ["warn", 3], |
| 88 | + "no-this-before-super": "warn", |
| 89 | + "no-undef": "warn", |
| 90 | + "no-unreachable": "warn", |
| 91 | + "no-bitwise": "off", |
| 92 | + "no-console": "off", |
| 93 | + "default-param-last": "off", |
| 94 | + |
| 95 | + "unused-imports/no-unused-imports": "warn", |
| 96 | + |
| 97 | + "react/jsx-uses-vars": "error", |
| 98 | + "react/no-typos": "warn", |
| 99 | + "react/jsx-tag-spacing": "warn", |
| 100 | + "react/jsx-boolean-value": "warn", |
| 101 | + "react/no-array-index-key": "warn", |
| 102 | + "react/jsx-wrap-multilines": "warn", |
| 103 | + "react/self-closing-comp": "warn", |
| 104 | + "react/jsx-closing-bracket-location": "warn", |
| 105 | + "react/require-render-return": "warn", |
| 106 | + "react/prefer-es6-class": "warn", |
| 107 | + "react/prefer-stateless-function": "warn", |
| 108 | + "react/jsx-uses-react": "warn", |
| 109 | + "react/no-multi-comp": "off", |
| 110 | + "react/display-name": "off", |
| 111 | + "react/react-in-jsx-scope": "off", |
| 112 | + "react/prop-types": "off", |
| 113 | + |
| 114 | + "import/order": [ |
| 115 | + "warn", |
| 116 | + { |
| 117 | + groups: ["builtin", "external", "internal", "parent", "sibling", "index"], |
| 118 | + |
| 119 | + pathGroups: [ |
| 120 | + { |
| 121 | + pattern: "react", |
| 122 | + group: "builtin", |
| 123 | + position: "before" |
| 124 | + } |
| 125 | + ], |
| 126 | + |
| 127 | + pathGroupsExcludedImportTypes: ["react"], |
| 128 | + |
| 129 | + alphabetize: { |
| 130 | + order: "asc", |
| 131 | + caseInsensitive: true |
| 132 | + } |
| 133 | + } |
| 134 | + ], |
| 135 | + "import/no-extraneous-dependencies": "off", |
| 136 | + "import/prefer-default-export": "off", |
| 137 | + |
| 138 | + "prettier/prettier": "error", |
| 139 | + ...eslintConfigPrettier.rules |
| 140 | + } |
| 141 | + } |
| 142 | +]; |
0 commit comments