|
| 1 | +const path = require('path'); |
| 2 | + |
| 3 | +// ESLint configuration |
| 4 | +// http://eslint.org/docs/user-guide/configuring |
| 5 | +module.exports = { |
| 6 | + env: { browser: true, es6: true, node: true }, |
| 7 | + extends: ['react-app', 'prettier', 'prettier/react'], |
| 8 | + parser: 'babel-eslint', |
| 9 | + parserOptions: { |
| 10 | + ecmaFeatures: { jsx: true }, |
| 11 | + ecmaVersion: 2018, |
| 12 | + sourceType: 'module', |
| 13 | + }, |
| 14 | + plugins: ['prettier', 'react-hooks'], |
| 15 | + |
| 16 | + rules: { |
| 17 | + // Forbid the use of extraneous packages |
| 18 | + // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md |
| 19 | + 'import/no-extraneous-dependencies': ['off'], |
| 20 | + |
| 21 | + // Recommend not to leave any console.log in your code |
| 22 | + // Use console.error, console.warn and console.info instead |
| 23 | + // https://eslint.org/docs/rules/no-console |
| 24 | + 'no-console': [ |
| 25 | + 'error', |
| 26 | + { |
| 27 | + allow: ['warn', 'error', 'info', 'log'], |
| 28 | + }, |
| 29 | + ], |
| 30 | + |
| 31 | + // Prefer destructuring from arrays and objects |
| 32 | + // http://eslint.org/docs/rules/prefer-destructuring |
| 33 | + 'prefer-destructuring': [ |
| 34 | + 'error', |
| 35 | + { |
| 36 | + VariableDeclarator: { |
| 37 | + array: false, |
| 38 | + object: true, |
| 39 | + }, |
| 40 | + AssignmentExpression: { |
| 41 | + array: false, |
| 42 | + object: false, |
| 43 | + }, |
| 44 | + }, |
| 45 | + { |
| 46 | + enforceForRenamedProperties: false, |
| 47 | + }, |
| 48 | + ], |
| 49 | + |
| 50 | + // Allow .js files to use JSX syntax |
| 51 | + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md |
| 52 | + 'react/jsx-filename-extension': ['error', { extensions: ['.js', '.jsx'] }], |
| 53 | + |
| 54 | + // Functional and class components are equivalent from React’s point of view |
| 55 | + // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md |
| 56 | + 'react/prefer-stateless-function': 'off', |
| 57 | + |
| 58 | + // ESLint plugin for prettier formatting |
| 59 | + // https://github.com/prettier/eslint-plugin-prettier |
| 60 | + 'prettier/prettier': 'error', |
| 61 | + |
| 62 | + 'react-hooks/rules-of-hooks': 'error', |
| 63 | + 'react-hooks/exhaustive-deps': 'warn', |
| 64 | + }, |
| 65 | + |
| 66 | + settings: { |
| 67 | + // Allow absolute paths in imports, e.g. import Button from 'components/Button' |
| 68 | + // https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers |
| 69 | + 'import/resolver': { |
| 70 | + webpack: { |
| 71 | + config: path.resolve(__dirname, 'config/webpack.config.js'), |
| 72 | + }, |
| 73 | + }, |
| 74 | + }, |
| 75 | + overrides: [ |
| 76 | + { |
| 77 | + files: ['**/*.ts', '**/*.tsx'], |
| 78 | + env: { browser: true, es6: true, node: true }, |
| 79 | + extends: [ |
| 80 | + // 'eslint:recommended', |
| 81 | + // 'plugin:react/recommended', |
| 82 | + // 'plugin:@typescript-eslint/eslint-recommended', |
| 83 | + 'plugin:@typescript-eslint/recommended', |
| 84 | + 'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier |
| 85 | + 'plugin:prettier/recommended', |
| 86 | + ], |
| 87 | + parser: '@typescript-eslint/parser', |
| 88 | + parserOptions: { |
| 89 | + ecmaFeatures: { jsx: true }, |
| 90 | + ecmaVersion: 2018, |
| 91 | + sourceType: 'module', |
| 92 | + project: './tsconfig.json', |
| 93 | + }, |
| 94 | + plugins: ['react', '@typescript-eslint'], |
| 95 | + rules: { |
| 96 | + // indent: ['error', 2, { SwitchCase: 1 }], |
| 97 | + 'linebreak-style': ['error', 'unix'], |
| 98 | + quotes: ['error', 'single'], |
| 99 | + // 'comma-dangle': ['error', 'always-multiline'], |
| 100 | + '@typescript-eslint/no-explicit-any': 0, |
| 101 | + '@typescript-eslint/no-use-before-define': 0, |
| 102 | + '@typescript-eslint/camelcase': 0, |
| 103 | + // '@typescript-eslint/no-unused-vars': 0, |
| 104 | + '@typescript-eslint/explicit-function-return-type': 0, |
| 105 | + '@typescript-eslint/no-empty-function': 0, |
| 106 | + '@typescript-eslint/no-var-requires': 0, |
| 107 | + 'no-case-declarations': 0, |
| 108 | + 'react/display-name': 0, |
| 109 | + 'react/prop-types': 0, |
| 110 | + }, |
| 111 | + settings: { react: { version: 'detect' } }, |
| 112 | + }, |
| 113 | + ], |
| 114 | +}; |
0 commit comments