|
| 1 | +/* |
| 2 | +* Forked from Create React App's ES Lint rules: |
| 3 | +* https://github.com/facebook/create-react-app/blob/master/packages/eslint-config-react-app/index.js |
| 4 | +*/ |
| 5 | + |
| 6 | +'use strict'; |
| 7 | + |
| 8 | +const restrictedGlobals = require('confusing-browser-globals'); |
| 9 | + |
| 10 | +const jsExtensions = ['.js', '.jsx']; |
| 11 | +const tsExtensions = ['.ts', '.tsx']; |
| 12 | +const allExtensions = jsExtensions.concat(tsExtensions); |
| 13 | + |
| 14 | +module.exports = { |
| 15 | + root: true, |
| 16 | + |
| 17 | + parser: 'babel-eslint', |
| 18 | + |
| 19 | + plugins: ['import', 'jsx-a11y', 'react', 'react-hooks'], |
| 20 | + |
| 21 | + extends: [ |
| 22 | + 'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin |
| 23 | + 'plugin:react/recommended', |
| 24 | + // 'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. |
| 25 | + // 'prettier/standard', // disables standard linting rules that conflict with prettier |
| 26 | + 'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier |
| 27 | + // 'prettier/react', // disables react-specific linting rules that conflict with prettier |
| 28 | + ], |
| 29 | + |
| 30 | + env: { |
| 31 | + browser: true, |
| 32 | + commonjs: true, |
| 33 | + es6: true, |
| 34 | + jest: true, |
| 35 | + node: true, |
| 36 | + }, |
| 37 | + |
| 38 | + parserOptions: { |
| 39 | + ecmaVersion: 2018, |
| 40 | + sourceType: 'module', |
| 41 | + ecmaFeatures: { |
| 42 | + jsx: true, |
| 43 | + }, |
| 44 | + }, |
| 45 | + |
| 46 | + globals: { |
| 47 | + '__DEV__': 'readonly' |
| 48 | + }, |
| 49 | + |
| 50 | + settings: { |
| 51 | + react: { |
| 52 | + version: 'detect', |
| 53 | + }, |
| 54 | + // Fixes import plugin not resolving ts/tsx. |
| 55 | + // See https://github.com/benmosher/eslint-plugin-import/issues/1285 |
| 56 | + 'import/extensions': allExtensions, |
| 57 | + 'import/parsers': { |
| 58 | + '@typescript-eslint/parser': tsExtensions |
| 59 | + }, |
| 60 | + 'import/resolver': { |
| 61 | + 'node': { |
| 62 | + 'extensions': allExtensions |
| 63 | + } |
| 64 | + } |
| 65 | + }, |
| 66 | + |
| 67 | + overrides: { |
| 68 | + files: ['**/*.ts', '**/*.tsx'], |
| 69 | + parser: '@typescript-eslint/parser', |
| 70 | + parserOptions: { |
| 71 | + ecmaVersion: 2018, |
| 72 | + sourceType: 'module', |
| 73 | + ecmaFeatures: { |
| 74 | + jsx: true, |
| 75 | + }, |
| 76 | + |
| 77 | + // typescript-eslint specific options |
| 78 | + warnOnUnsupportedTypeScriptVersion: true, |
| 79 | + }, |
| 80 | + plugins: ['@typescript-eslint'], |
| 81 | + // If adding a typescript-eslint version of an existing ESLint rule, |
| 82 | + // make sure to disable the ESLint rule here. |
| 83 | + rules: { |
| 84 | + // TypeScript's `noFallthroughCasesInSwitch` option is more robust (#6906) |
| 85 | + 'default-case': 'off', |
| 86 | + |
| 87 | + // Add TypeScript specific rules (and turn off ESLint equivalents) |
| 88 | + '@typescript-eslint/no-angle-bracket-type-assertion': 'warn', |
| 89 | + 'no-array-constructor': 'off', |
| 90 | + '@typescript-eslint/no-array-constructor': 'warn', |
| 91 | + '@typescript-eslint/no-namespace': 'error', |
| 92 | + |
| 93 | + 'no-useless-constructor': 'off', // Disable base rule to use TS rule |
| 94 | + '@typescript-eslint/no-useless-constructor': 'warn', |
| 95 | + |
| 96 | + // TCN |
| 97 | + '@typescript-eslint/interface-name-prefix': 'off', |
| 98 | + '@typescript-eslint/explicit-function-return-type': 'off', |
| 99 | + '@typescript-eslint/no-explicit-any': 'off', |
| 100 | + '@typescript-eslint/camelcase': 'warn', |
| 101 | + 'no-unused-vars': 'off', // use @typescrit-eslint/no-unused-vars instead. |
| 102 | + '@typescript-eslint/no-unused-vars': [ |
| 103 | + 'warn', |
| 104 | + { |
| 105 | + args: 'none', |
| 106 | + ignoreRestSiblings: true, |
| 107 | + args: 'after-used', |
| 108 | + varsIgnorePattern: '^_', |
| 109 | + argsIgnorePattern: '^_', |
| 110 | + caughtErrors: 'none', |
| 111 | + }, |
| 112 | + ], |
| 113 | + 'no-use-before-define': 'off', |
| 114 | + '@typescript-eslint/no-use-before-define': 'off', |
| 115 | + '@typescript-eslint/explicit-member-accessibility': 'off', |
| 116 | + |
| 117 | + // Changed to warnings instead of errors: |
| 118 | + '@typescript-eslint/no-object-literal-type-assertion': 'warn', |
| 119 | + '@typescript-eslint/array-type': 'warn', |
| 120 | + '@typescript-eslint/no-inferrable-types': 'warn', |
| 121 | + '@typescript-eslint/no-empty-interface': 'warn', |
| 122 | + '@typescript-eslint/no-var-requires': 'warn', |
| 123 | + }, |
| 124 | + }, |
| 125 | + |
| 126 | + // NOTE: When adding rules here, you need to make sure they are compatible with |
| 127 | + // `typescript-eslint`, as some rules such as `no-array-constructor` aren't compatible. |
| 128 | + rules: { |
| 129 | + // http://eslint.org/docs/rules/ |
| 130 | + 'array-callback-return': 'warn', |
| 131 | + 'default-case': ['warn', { commentPattern: '^no default$' }], |
| 132 | + 'dot-location': ['warn', 'property'], |
| 133 | + eqeqeq: ['warn', 'smart'], |
| 134 | + 'new-parens': 'warn', |
| 135 | + 'no-array-constructor': 'warn', |
| 136 | + 'no-caller': 'warn', |
| 137 | + 'no-cond-assign': ['warn', 'except-parens'], |
| 138 | + 'no-const-assign': 'warn', |
| 139 | + 'no-control-regex': 'warn', |
| 140 | + 'no-delete-var': 'warn', |
| 141 | + 'no-dupe-args': 'warn', |
| 142 | + 'no-dupe-class-members': 'warn', |
| 143 | + 'no-dupe-keys': 'warn', |
| 144 | + 'no-duplicate-case': 'warn', |
| 145 | + 'no-empty-character-class': 'warn', |
| 146 | + 'no-empty-pattern': 'warn', |
| 147 | + 'no-eval': 'warn', |
| 148 | + 'no-ex-assign': 'warn', |
| 149 | + 'no-extend-native': 'warn', |
| 150 | + 'no-extra-bind': 'warn', |
| 151 | + 'no-extra-label': 'warn', |
| 152 | + 'no-func-assign': 'warn', |
| 153 | + 'no-implied-eval': 'warn', |
| 154 | + 'no-invalid-regexp': 'warn', |
| 155 | + 'no-iterator': 'warn', |
| 156 | + 'no-label-var': 'warn', |
| 157 | + 'no-labels': ['warn', { allowLoop: true, allowSwitch: false }], |
| 158 | + 'no-lone-blocks': 'warn', |
| 159 | + 'no-loop-func': 'warn', |
| 160 | + 'no-mixed-operators': [ |
| 161 | + 'warn', |
| 162 | + { |
| 163 | + groups: [ |
| 164 | + ['&', '|', '^', '~', '<<', '>>', '>>>'], |
| 165 | + ['==', '!=', '===', '!==', '>', '>=', '<', '<='], |
| 166 | + ['&&', '||'], |
| 167 | + ['in', 'instanceof'], |
| 168 | + ], |
| 169 | + allowSamePrecedence: false, |
| 170 | + }, |
| 171 | + ], |
| 172 | + 'no-multi-str': 'warn', |
| 173 | + 'no-native-reassign': 'warn', |
| 174 | + 'no-negated-in-lhs': 'warn', |
| 175 | + 'no-new-func': 'warn', |
| 176 | + 'no-new-object': 'warn', |
| 177 | + 'no-new-symbol': 'warn', |
| 178 | + 'no-new-wrappers': 'warn', |
| 179 | + 'no-obj-calls': 'warn', |
| 180 | + 'no-octal': 'warn', |
| 181 | + 'no-octal-escape': 'warn', |
| 182 | + 'no-redeclare': 'warn', |
| 183 | + 'no-regex-spaces': 'warn', |
| 184 | + 'no-restricted-syntax': ['warn', 'WithStatement'], |
| 185 | + 'no-script-url': 'warn', |
| 186 | + 'no-self-assign': 'warn', |
| 187 | + 'no-self-compare': 'warn', |
| 188 | + 'no-sequences': 'warn', |
| 189 | + 'no-shadow-restricted-names': 'warn', |
| 190 | + 'no-sparse-arrays': 'warn', |
| 191 | + 'no-template-curly-in-string': 'warn', |
| 192 | + 'no-this-before-super': 'warn', |
| 193 | + 'no-throw-literal': 'warn', |
| 194 | + 'no-undef': 'error', |
| 195 | + 'no-restricted-globals': ['error'].concat(restrictedGlobals), |
| 196 | + 'no-unexpected-multiline': 'warn', |
| 197 | + 'no-unreachable': 'warn', |
| 198 | + 'no-unused-expressions': [ |
| 199 | + 'error', |
| 200 | + { |
| 201 | + allowShortCircuit: true, |
| 202 | + allowTernary: true, |
| 203 | + allowTaggedTemplates: true, |
| 204 | + }, |
| 205 | + ], |
| 206 | + 'no-unused-labels': 'warn', |
| 207 | + 'no-unused-vars': [ |
| 208 | + 'warn', |
| 209 | + { |
| 210 | + args: 'none', |
| 211 | + ignoreRestSiblings: true, |
| 212 | + }, |
| 213 | + ], |
| 214 | + 'no-use-before-define': [ |
| 215 | + 'warn', |
| 216 | + { |
| 217 | + functions: false, |
| 218 | + classes: false, |
| 219 | + variables: false, |
| 220 | + }, |
| 221 | + ], |
| 222 | + 'no-useless-computed-key': 'warn', |
| 223 | + 'no-useless-concat': 'warn', |
| 224 | + 'no-useless-constructor': 'warn', |
| 225 | + 'no-useless-escape': 'warn', |
| 226 | + 'no-useless-rename': [ |
| 227 | + 'warn', |
| 228 | + { |
| 229 | + ignoreDestructuring: false, |
| 230 | + ignoreImport: false, |
| 231 | + ignoreExport: false, |
| 232 | + }, |
| 233 | + ], |
| 234 | + 'no-with': 'warn', |
| 235 | + 'no-whitespace-before-property': 'warn', |
| 236 | + 'require-yield': 'warn', |
| 237 | + 'rest-spread-spacing': ['warn', 'never'], |
| 238 | + strict: ['warn', 'never'], |
| 239 | + 'unicode-bom': ['warn', 'never'], |
| 240 | + 'use-isnan': 'warn', |
| 241 | + 'valid-typeof': 'warn', |
| 242 | + 'no-restricted-properties': [ |
| 243 | + 'error', |
| 244 | + { |
| 245 | + object: 'require', |
| 246 | + property: 'ensure', |
| 247 | + message: |
| 248 | + 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting', |
| 249 | + }, |
| 250 | + { |
| 251 | + object: 'System', |
| 252 | + property: 'import', |
| 253 | + message: |
| 254 | + 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting', |
| 255 | + }, |
| 256 | + ], |
| 257 | + 'getter-return': 'warn', |
| 258 | + |
| 259 | + // https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules |
| 260 | + 'import/first': 'error', |
| 261 | + 'import/no-amd': 'error', |
| 262 | + 'import/no-webpack-loader-syntax': 'error', |
| 263 | + |
| 264 | + // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules |
| 265 | + 'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }], |
| 266 | + 'react/jsx-no-comment-textnodes': 'warn', |
| 267 | + 'react/jsx-no-duplicate-props': ['warn', { ignoreCase: true }], |
| 268 | + 'react/jsx-no-target-blank': 'warn', |
| 269 | + 'react/jsx-no-undef': 'error', |
| 270 | + 'react/jsx-pascal-case': [ |
| 271 | + 'warn', |
| 272 | + { |
| 273 | + allowAllCaps: true, |
| 274 | + ignore: [], |
| 275 | + }, |
| 276 | + ], |
| 277 | + 'react/jsx-uses-react': 'warn', |
| 278 | + 'react/jsx-uses-vars': 'warn', |
| 279 | + 'react/no-danger-with-children': 'warn', |
| 280 | + // Disabled because of undesirable warnings |
| 281 | + // See https://github.com/facebook/create-react-app/issues/5204 for |
| 282 | + // blockers until its re-enabled |
| 283 | + // 'react/no-deprecated': 'warn', |
| 284 | + 'react/no-direct-mutation-state': 'warn', |
| 285 | + 'react/no-is-mounted': 'warn', |
| 286 | + 'react/no-typos': 'error', |
| 287 | + 'react/react-in-jsx-scope': 'error', |
| 288 | + 'react/require-render-return': 'error', |
| 289 | + 'react/style-prop-object': 'warn', |
| 290 | + |
| 291 | + // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules |
| 292 | + 'jsx-a11y/accessible-emoji': 'warn', |
| 293 | + 'jsx-a11y/alt-text': 'warn', |
| 294 | + 'jsx-a11y/anchor-has-content': 'warn', |
| 295 | + 'jsx-a11y/anchor-is-valid': [ |
| 296 | + 'warn', |
| 297 | + { |
| 298 | + aspects: ['noHref', 'invalidHref'], |
| 299 | + }, |
| 300 | + ], |
| 301 | + 'jsx-a11y/aria-activedescendant-has-tabindex': 'warn', |
| 302 | + 'jsx-a11y/aria-props': 'warn', |
| 303 | + 'jsx-a11y/aria-proptypes': 'warn', |
| 304 | + 'jsx-a11y/aria-role': 'warn', |
| 305 | + 'jsx-a11y/aria-unsupported-elements': 'warn', |
| 306 | + 'jsx-a11y/heading-has-content': 'warn', |
| 307 | + 'jsx-a11y/iframe-has-title': 'warn', |
| 308 | + 'jsx-a11y/img-redundant-alt': 'warn', |
| 309 | + 'jsx-a11y/no-access-key': 'warn', |
| 310 | + 'jsx-a11y/no-distracting-elements': 'warn', |
| 311 | + 'jsx-a11y/no-redundant-roles': 'warn', |
| 312 | + 'jsx-a11y/role-has-required-aria-props': 'warn', |
| 313 | + 'jsx-a11y/role-supports-aria-props': 'warn', |
| 314 | + 'jsx-a11y/scope': 'warn', |
| 315 | + |
| 316 | + 'no-implicit-coercion': 'error', |
| 317 | + 'no-console': [ |
| 318 | + 'warn', |
| 319 | + { |
| 320 | + 'allow': ['error'], |
| 321 | + }, |
| 322 | + ], |
| 323 | + |
| 324 | + 'react/jsx-boolean-value': [ |
| 325 | + 'error', |
| 326 | + 'never', |
| 327 | + ], |
| 328 | + |
| 329 | + 'react/jsx-filename-extension': [ |
| 330 | + 'warn', |
| 331 | + { |
| 332 | + 'extensions': [ |
| 333 | + '.jsx', |
| 334 | + '.tsx', |
| 335 | + ], |
| 336 | + }, |
| 337 | + ], |
| 338 | + |
| 339 | + // Turn off checking on these: |
| 340 | + 'max-len': 'off', |
| 341 | + 'no-underscore-dangle': 'off', |
| 342 | + 'implicit-arrow-linebreak': 'off', |
| 343 | + 'yoda': 'off', |
| 344 | + 'newline-per-chained-call': 'off', |
| 345 | + 'no-fallthrough': 'off', |
| 346 | + 'padded-blocks': 'off', |
| 347 | + 'operator-linebreak': 'off', |
| 348 | + |
| 349 | + 'import/prefer-default-export': 'off', |
| 350 | + 'import/no-unresolved': 'off', |
| 351 | + 'import/export': 'off', // Breaks TS Function Overloads when turned on. |
| 352 | + 'import/order': 'off', |
| 353 | + |
| 354 | + 'react/prop-types': 'off', |
| 355 | + 'react/destructuring-assignment': 'off', |
| 356 | + 'react/jsx-one-expression-per-line': 'off', |
| 357 | + 'react/no-unescaped-entities': 'off', |
| 358 | + 'react/jsx-indent': 'off', |
| 359 | + 'react/jsx-indent-props': 'off', |
| 360 | + |
| 361 | + // https://github.com/facebook/react/tree/master/packages/eslint-plugin-react-hooks |
| 362 | + 'react-hooks/rules-of-hooks': 'error', |
| 363 | + 'react-hooks/exhaustive-deps': 'warn', |
| 364 | + |
| 365 | + 'prettier/prettier': [ |
| 366 | + 'off', |
| 367 | + {"parser": "typescript"} |
| 368 | + ], |
| 369 | + } |
| 370 | +}; |
0 commit comments