|
| 1 | +// eslint-disable-next-line import/no-extraneous-dependencies |
| 2 | +const appRootPath = require('app-root-path').path; |
| 3 | + |
| 4 | +// Не даем eslint самому фиксить эти правила |
| 5 | +const fixRulesOverride = { |
| 6 | + 'react-hooks/exhaustive-deps': 'off', |
| 7 | +}; |
| 8 | + |
| 9 | +// Отключаем некоторые правила, что сложно исправить, чтобы пройти проверку на прекомит хук |
| 10 | +const cliRulesOverride = {}; |
| 11 | + |
| 12 | +// Временно отключаем старые ошибки, чтобы можно было хоть как-то запускать в ci |
| 13 | +const ciRulesOverride = {}; |
| 14 | + |
| 15 | +module.exports = { |
| 16 | + plugins: ['optimize-regex', 'sonarjs', 'no-loops', 'no-use-extend-native', 'prettier'], |
| 17 | + extends: ['airbnb', 'airbnb/hooks', 'plugin:sonarjs/recommended', 'plugin:prettier/recommended'], |
| 18 | + env: { |
| 19 | + es6: true, |
| 20 | + browser: true, |
| 21 | + }, |
| 22 | + root: true, |
| 23 | + settings: { |
| 24 | + react: { |
| 25 | + version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use |
| 26 | + }, |
| 27 | + // This loads <rootdir>/jsconfig.json to eslint |
| 28 | + 'import/resolver': { |
| 29 | + alias: { |
| 30 | + map: [ |
| 31 | + ['@', `${appRootPath}/src`], |
| 32 | + ['public', `${appRootPath}/public`], |
| 33 | + ], |
| 34 | + extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'], |
| 35 | + }, |
| 36 | + }, |
| 37 | + }, |
| 38 | + rules: { |
| 39 | + 'optimize-regex/optimize-regex': 'warn', |
| 40 | + 'no-loops/no-loops': 'warn', |
| 41 | + 'prettier/prettier': 'warn', |
| 42 | + |
| 43 | + 'react/react-in-jsx-scope': 'off', |
| 44 | + 'react/prop-types': 'off', |
| 45 | + 'react/jsx-filename-extension': [ |
| 46 | + 'warn', |
| 47 | + { |
| 48 | + extensions: ['.jsx', '.tsx'], |
| 49 | + }, |
| 50 | + ], |
| 51 | + 'react/jsx-fragments': 'off', |
| 52 | + 'jsx-a11y/anchor-is-valid': [ |
| 53 | + 'error', |
| 54 | + { |
| 55 | + components: ['Link'], |
| 56 | + specialLink: ['hrefLeft', 'hrefRight'], |
| 57 | + aspects: ['invalidHref', 'preferButton'], |
| 58 | + }, |
| 59 | + ], |
| 60 | + |
| 61 | + // Используем объекты вместо ошибок |
| 62 | + 'prefer-promise-reject-errors': 'off', |
| 63 | + |
| 64 | + // Этому правилу нереально следовать |
| 65 | + 'sonarjs/cognitive-complexity': 'off', |
| 66 | + |
| 67 | + // компромисы с prettier |
| 68 | + 'react/jsx-wrap-multilines': [ |
| 69 | + 'error', |
| 70 | + { |
| 71 | + declaration: false, |
| 72 | + assignment: false, |
| 73 | + }, |
| 74 | + ], |
| 75 | + 'react/jsx-one-expression-per-line': 'off', |
| 76 | + |
| 77 | + 'prefer-destructuring': 'off', |
| 78 | + 'linebreak-style': 'off', |
| 79 | + 'no-underscore-dangle': 'off', |
| 80 | + camelcase: 'off', |
| 81 | + 'prefer-rest-params': 'off', |
| 82 | + curly: ['error', 'all'], |
| 83 | + 'arrow-body-style': ['error', 'always'], |
| 84 | + 'no-implicit-coercion': ['error', { allow: [] }], |
| 85 | + 'no-extra-boolean-cast': ['error', { enforceForLogicalOperands: true }], |
| 86 | + 'no-console': ['error', { allow: ['error'] }], |
| 87 | + 'no-restricted-syntax': ['error', 'SequenceExpression'], |
| 88 | + 'func-style': ['error', 'declaration', { allowArrowFunctions: true }], |
| 89 | + |
| 90 | + // Для работы с immer |
| 91 | + 'no-param-reassign': [ |
| 92 | + 'error', |
| 93 | + { props: true, ignorePropertyModificationsForRegex: ['[dD]raft|it'] }, |
| 94 | + ], |
| 95 | + |
| 96 | + // Стараемся избегать использования default export |
| 97 | + 'import/prefer-default-export': 'off', |
| 98 | + 'import/extensions': 'off', |
| 99 | + // Задаём строгий порядок импортов |
| 100 | + 'import/order': [ |
| 101 | + 'error', |
| 102 | + { |
| 103 | + groups: ['object', 'builtin', 'external', 'internal', 'parent', 'sibling', 'index'], |
| 104 | + pathGroups: [ |
| 105 | + // Разделяем основные компоненты приложение, чтобы не было нагромаждения, |
| 106 | + // все остальные папки из src будут импортироваться вплотную. |
| 107 | + { pattern: '{@/constants,@/constants/**}', group: 'internal', position: 'after' }, |
| 108 | + { pattern: '{@/utils,@/utils/**}', group: 'internal', position: 'after' }, |
| 109 | + { pattern: '{@/components,@/components/**}', group: 'internal', position: 'after' }, |
| 110 | + { pattern: '{@/hooks,@/hooks/**}', group: 'internal', position: 'after' }, |
| 111 | + { pattern: '@/**', group: 'internal', position: 'after' }, |
| 112 | + |
| 113 | + { pattern: './*.module.scss', group: 'index', position: 'after' }, |
| 114 | + ], |
| 115 | + 'newlines-between': 'always', |
| 116 | + pathGroupsExcludedImportTypes: ['builtin'], |
| 117 | + alphabetize: { order: 'asc', caseInsensitive: true }, |
| 118 | + }, |
| 119 | + ], |
| 120 | + |
| 121 | + ...(process.env.ESLINT_MODE_CI ? ciRulesOverride : {}), |
| 122 | + ...(process.env.ESLINT_MODE_CLI ? cliRulesOverride : {}), |
| 123 | + ...(process.env.ESLINT_MODE_FIX ? fixRulesOverride : {}), |
| 124 | + }, |
| 125 | +}; |
0 commit comments