|
| 1 | +const { defineConfig } = require('eslint/config'); |
| 2 | +const js = require('@eslint/js'); |
| 3 | +const globals = require('globals'); |
| 4 | +const importPlugin = require('eslint-plugin-import'); |
| 5 | +const jsxA11y = require('eslint-plugin-jsx-a11y'); |
| 6 | +const react = require('eslint-plugin-react'); |
| 7 | +const reactHooks = require('eslint-plugin-react-hooks'); |
| 8 | +const reactCompiler = require('eslint-plugin-react-compiler'); |
| 9 | +const unusedImports = require('eslint-plugin-unused-imports'); |
| 10 | +const pluginJest = require('eslint-plugin-jest'); |
| 11 | +const playwright = require('eslint-plugin-playwright'); |
| 12 | +const airbnb = require('eslint-config-airbnb-extended/legacy'); |
| 13 | +const prettierRecommended = require('eslint-plugin-prettier/recommended'); |
| 14 | + |
| 15 | +// Helper to disable jsx-a11y rules |
| 16 | +const jsxA11yOffRules = Object.keys(jsxA11y.rules).reduce((acc, rule) => { |
| 17 | + acc[`jsx-a11y/${rule}`] = 'off'; |
| 18 | + return acc; |
| 19 | +}, {}); |
| 20 | + |
| 21 | +module.exports = ({ tsconfigRootDir }) => |
| 22 | + defineConfig( |
| 23 | + js.configs.recommended, |
| 24 | + ...airbnb.configs.react.typescript, |
| 25 | + importPlugin.flatConfigs.recommended, |
| 26 | + react.configs.flat.recommended, |
| 27 | + reactHooks.configs.flat.recommended, |
| 28 | + reactCompiler.configs.recommended, |
| 29 | + prettierRecommended, |
| 30 | + |
| 31 | + { |
| 32 | + files: ['**/*.{ts,tsx,cts,mts}'], |
| 33 | + plugins: { |
| 34 | + 'unused-imports': unusedImports, |
| 35 | + }, |
| 36 | + settings: { |
| 37 | + react: { |
| 38 | + version: 'detect', |
| 39 | + }, |
| 40 | + }, |
| 41 | + languageOptions: { |
| 42 | + parserOptions: { |
| 43 | + // Make sure eslint and VS Code use the same path for the tsconfig.json: |
| 44 | + // https://github.com/typescript-eslint/typescript-eslint/issues/251 |
| 45 | + tsconfigRootDir, |
| 46 | + project: `./tsconfig.eslint.json`, |
| 47 | + }, |
| 48 | + globals: { |
| 49 | + ...globals.node, |
| 50 | + ...globals.browser, |
| 51 | + ...globals.es6, |
| 52 | + Atomics: 'readonly', |
| 53 | + SharedArrayBuffer: 'readonly', |
| 54 | + }, |
| 55 | + }, |
| 56 | + |
| 57 | + rules: { |
| 58 | + ...jsxA11yOffRules, |
| 59 | + 'class-methods-use-this': 'off', |
| 60 | + '@typescript-eslint/class-methods-use-this': 'off', |
| 61 | + curly: [2, 'all'], |
| 62 | + 'linebreak-style': 'off', |
| 63 | + 'no-console': 'off', |
| 64 | + 'no-continue': 'off', |
| 65 | + 'no-multi-assign': 'warn', |
| 66 | + 'no-nested-ternary': 'off', |
| 67 | + 'no-return-assign': 'warn', |
| 68 | + 'no-restricted-exports': 'off', |
| 69 | + 'no-restricted-syntax': [ |
| 70 | + 'warn', |
| 71 | + { |
| 72 | + selector: "MemberExpression[object.name='React'][property.name='useEffect']", |
| 73 | + message: 'You Might Not Need an Effect\nhttps://react.dev/learn/you-might-not-need-an-effect', |
| 74 | + }, |
| 75 | + ], |
| 76 | + 'no-plusplus': 'off', |
| 77 | + 'no-prototype-builtins': 'warn', |
| 78 | + 'no-minusminus': 'off', |
| 79 | + 'no-underscore-dangle': 'off', |
| 80 | + 'no-restricted-imports': [ |
| 81 | + 'error', |
| 82 | + { |
| 83 | + paths: [ |
| 84 | + { |
| 85 | + name: 'lodash', |
| 86 | + message: 'Please import specific methods from lodash/<util> instead.', |
| 87 | + }, |
| 88 | + { |
| 89 | + name: '@fortawesome/free-solid-svg-icons', |
| 90 | + message: 'Please import specific icons from @fortawesome/free-solid-svg-icons/<icon> instead.', |
| 91 | + }, |
| 92 | + { |
| 93 | + name: '@fortawesome/free-regular-svg-icons', |
| 94 | + message: 'Please import specific icons from @fortawesome/free-regular-svg-icons/<icon> instead.', |
| 95 | + }, |
| 96 | + ], |
| 97 | + }, |
| 98 | + ], |
| 99 | + '@typescript-eslint/no-shadow': 'warn', |
| 100 | + '@typescript-eslint/no-use-before-define': 'warn', |
| 101 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 102 | + '@typescript-eslint/no-unused-expressions': [ |
| 103 | + 'error', |
| 104 | + { |
| 105 | + allowShortCircuit: true, |
| 106 | + allowTernary: true, |
| 107 | + allowTaggedTemplates: true, |
| 108 | + }, |
| 109 | + ], |
| 110 | + '@typescript-eslint/no-unused-vars': [ |
| 111 | + 'warn', |
| 112 | + { |
| 113 | + vars: 'all', |
| 114 | + varsIgnorePattern: '^_', |
| 115 | + args: 'after-used', |
| 116 | + argsIgnorePattern: '^_', |
| 117 | + }, |
| 118 | + ], |
| 119 | + 'max-classes-per-file': 'off', |
| 120 | + 'no-param-reassign': ['warn', { props: true, ignorePropertyModificationsFor: ['state'] }], |
| 121 | + 'import/no-extraneous-dependencies': 'off', |
| 122 | + 'import/no-webpack-loader-syntax': 'off', |
| 123 | + 'import/no-unresolved': 'off', |
| 124 | + 'import/prefer-default-export': 'off', |
| 125 | + 'import/order': [ |
| 126 | + 'error', |
| 127 | + { |
| 128 | + groups: [['builtin', 'external'], 'internal', ['sibling', 'parent']], |
| 129 | + pathGroups: [ |
| 130 | + { |
| 131 | + pattern: 'react*', |
| 132 | + group: 'external', |
| 133 | + position: 'before', |
| 134 | + }, |
| 135 | + { pattern: 'src/**', group: 'internal', position: 'after' }, |
| 136 | + ], |
| 137 | + pathGroupsExcludedImportTypes: ['internal', 'react'], |
| 138 | + 'newlines-between': 'always', |
| 139 | + alphabetize: { order: 'asc' }, |
| 140 | + }, |
| 141 | + ], |
| 142 | + 'sort-imports': [ |
| 143 | + 'error', |
| 144 | + { |
| 145 | + ignoreCase: false, |
| 146 | + ignoreDeclarationSort: true, |
| 147 | + ignoreMemberSort: false, |
| 148 | + memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], |
| 149 | + allowSeparatedGroups: true, |
| 150 | + }, |
| 151 | + ], |
| 152 | + 'unused-imports/no-unused-imports': 'error', |
| 153 | + 'unused-imports/no-unused-vars': 'off', |
| 154 | + 'prefer-destructuring': ['warn', { object: true, array: false }], |
| 155 | + 'prefer-promise-reject-errors': 'warn', |
| 156 | + 'prefer-spread': 'warn', |
| 157 | + '@typescript-eslint/ban-ts-comment': 'warn', |
| 158 | + // Not required with the new JSX transform |
| 159 | + 'react/react-in-jsx-scope': 'off', |
| 160 | + 'react/destructuring-assignment': 'off', |
| 161 | + 'react/jsx-curly-brace-presence': 'warn', |
| 162 | + 'react/jsx-props-no-spreading': 'off', |
| 163 | + 'react/no-unused-class-component-methods': 'warn', |
| 164 | + 'react/prop-types': 'off', |
| 165 | + 'react/require-default-props': 'off', |
| 166 | + 'react/static-property-placement': [ |
| 167 | + 'warn', |
| 168 | + 'property assignment', |
| 169 | + { |
| 170 | + childContextTypes: 'static getter', |
| 171 | + contextTypes: 'static public field', |
| 172 | + contextType: 'static public field', |
| 173 | + displayName: 'static public field', |
| 174 | + }, |
| 175 | + ], |
| 176 | + 'react-compiler/react-compiler': 'warn', |
| 177 | + 'react-hooks/exhaustive-deps': [ |
| 178 | + 'error', |
| 179 | + { |
| 180 | + additionalHooks: '(useTriggerFrame|useDeepEffect|useDeepMemo|useDeepCallback|useDeepCompareEffect)', |
| 181 | + }, |
| 182 | + ], |
| 183 | + 'react-hooks/refs': 'warn', |
| 184 | + 'react-hooks/purity': 'warn', |
| 185 | + 'react-hooks/immutability': 'warn', |
| 186 | + 'react-hooks/use-memo': 'warn', |
| 187 | + 'react-hooks/preserve-manual-memoization': 'warn', |
| 188 | + 'react-hooks/set-state-in-render': 'warn', |
| 189 | + 'react-hooks/set-state-in-effect': 'warn', |
| 190 | + 'react-hooks/static-components': 'warn', |
| 191 | + '@stylistic/indent': 'off', |
| 192 | + '@stylistic/comma-dangle': 'off', |
| 193 | + }, |
| 194 | + }, |
| 195 | + |
| 196 | + { |
| 197 | + files: ['{src|tests}/**/*.{test|spec}.ts'], |
| 198 | + plugins: { jest: pluginJest }, |
| 199 | + languageOptions: { |
| 200 | + globals: pluginJest.environments.globals.globals, |
| 201 | + }, |
| 202 | + }, |
| 203 | + |
| 204 | + { |
| 205 | + ...playwright.configs['flat/recommended'], |
| 206 | + files: ['playwright/**/*.{test|spec}.ts'], |
| 207 | + }, |
| 208 | + ); |
0 commit comments