|
| 1 | +import jsEslint from '@eslint/js'; |
| 2 | +import eslintReactNativeConfig from '@react-native-community/eslint-config'; |
| 3 | +import eslintPluginReactNativeOfficial from '@react-native-community/eslint-plugin'; |
| 4 | +import eslintPluginComments from 'eslint-plugin-eslint-comments'; |
| 5 | +import eslintPluginImport from 'eslint-plugin-import'; |
| 6 | +import eslintPluginJest from 'eslint-plugin-jest'; |
| 7 | +import eslintPluginPrettier from 'eslint-plugin-prettier'; |
| 8 | +import eslintPluginReact from 'eslint-plugin-react'; |
| 9 | +import eslintPluginReactHooks from 'eslint-plugin-react-hooks'; |
| 10 | +import eslintPluginReactNative from 'eslint-plugin-react-native'; |
| 11 | +import eslintPluginSortDestructureKeys from 'eslint-plugin-sort-destructure-keys'; |
| 12 | + |
| 13 | +import tsEslint from 'typescript-eslint'; |
| 14 | + |
| 15 | +/** |
| 16 | + * @react-native-community/eslint-config is for some reason still using the old notation |
| 17 | + * for globals. We parse them manually here to make sure they're compatible with |
| 18 | + * the new config. All globals which were previously set to true are now readonly. |
| 19 | + */ |
| 20 | +const reactNativeGlobals = Object.keys(eslintReactNativeConfig.globals).reduce((acc, key) => { |
| 21 | + if (eslintReactNativeConfig.globals[key]) { |
| 22 | + acc[key] = 'readonly'; |
| 23 | + } |
| 24 | + return acc; |
| 25 | +}, {}); |
| 26 | + |
| 27 | +/** |
| 28 | + * We filter out the jest/ rules as they're part of another config layer. |
| 29 | + */ |
| 30 | +const reactNativeRules = Object.keys(eslintReactNativeConfig.rules).reduce((acc, key) => { |
| 31 | + if (!key.startsWith('jest/')) { |
| 32 | + acc[key] = eslintReactNativeConfig.rules[key]; |
| 33 | + } |
| 34 | + return acc; |
| 35 | +}, {}); |
| 36 | + |
| 37 | +export default tsEslint.config( |
| 38 | + jsEslint.configs.recommended, |
| 39 | + tsEslint.configs.recommended, |
| 40 | + eslintPluginReact.configs.flat.recommended, |
| 41 | + { |
| 42 | + ignores: [ |
| 43 | + 'node_modules/', |
| 44 | + 'build/', |
| 45 | + 'dist/', |
| 46 | + '.expo/', |
| 47 | + 'vendor/', |
| 48 | + '*.md', |
| 49 | + 'src/components/docs/', |
| 50 | + 'lib/', |
| 51 | + ], |
| 52 | + }, |
| 53 | + { |
| 54 | + files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'], |
| 55 | + languageOptions: { |
| 56 | + ecmaVersion: 2020, |
| 57 | + globals: { |
| 58 | + ...reactNativeGlobals, |
| 59 | + console: 'readonly', |
| 60 | + }, |
| 61 | + parser: tsEslint.parser, |
| 62 | + parserOptions: { |
| 63 | + ecmaFeatures: { |
| 64 | + modules: true, |
| 65 | + jsx: true, |
| 66 | + }, |
| 67 | + }, |
| 68 | + sourceType: 'module', |
| 69 | + }, |
| 70 | + plugins: { |
| 71 | + '@react-native-community': eslintPluginReactNativeOfficial, |
| 72 | + 'eslint-comments': eslintPluginComments, |
| 73 | + import: eslintPluginImport, |
| 74 | + prettier: eslintPluginPrettier, |
| 75 | + react: eslintPluginReact, |
| 76 | + 'react-hooks': eslintPluginReactHooks, |
| 77 | + 'react-native': eslintPluginReactNative, |
| 78 | + 'sort-destructure-keys': eslintPluginSortDestructureKeys, |
| 79 | + }, |
| 80 | + settings: { |
| 81 | + 'import/resolver': { |
| 82 | + // 'babel-module': {}, |
| 83 | + node: { |
| 84 | + extensions: ['.js', '.jsx', '.ts', '.tsx'], |
| 85 | + paths: ['src'], |
| 86 | + }, |
| 87 | + }, |
| 88 | + 'import/ignore': ['react-native'], |
| 89 | + react: { |
| 90 | + pragma: 'React', |
| 91 | + version: 'detect', |
| 92 | + }, |
| 93 | + }, |
| 94 | + rules: { |
| 95 | + ...reactNativeRules, |
| 96 | + 'array-callback-return': 2, |
| 97 | + 'arrow-body-style': 2, |
| 98 | + 'comma-dangle': 0, |
| 99 | + 'default-case': 2, |
| 100 | + eqeqeq: [2, 'smart'], |
| 101 | + 'import/no-unresolved': ['error', { ignore: ['types'] }], |
| 102 | + 'import/order': [ |
| 103 | + 'error', |
| 104 | + { |
| 105 | + alphabetize: { |
| 106 | + caseInsensitive: true, |
| 107 | + order: 'asc', |
| 108 | + }, |
| 109 | + groups: ['builtin', 'external', 'internal', 'sibling', 'parent', 'index', 'object'], |
| 110 | + 'newlines-between': 'always-and-inside-groups', |
| 111 | + pathGroups: [ |
| 112 | + { |
| 113 | + group: 'external', |
| 114 | + pattern: 'react*', |
| 115 | + position: 'before', |
| 116 | + }, |
| 117 | + ], |
| 118 | + pathGroupsExcludedImportTypes: ['react*'], |
| 119 | + }, |
| 120 | + ], |
| 121 | + 'jsx-quotes': ['error', 'prefer-single'], |
| 122 | + 'linebreak-style': [2, 'unix'], |
| 123 | + 'no-console': 0, |
| 124 | + 'no-mixed-spaces-and-tabs': 1, |
| 125 | + 'no-self-compare': 2, |
| 126 | + 'no-underscore-dangle': [2, { allowAfterThis: true }], |
| 127 | + 'no-unused-vars': 'off', |
| 128 | + 'no-useless-concat': 2, |
| 129 | + 'no-var': 2, |
| 130 | + 'object-shorthand': 1, |
| 131 | + 'prefer-const': 1, |
| 132 | + 'react/jsx-sort-props': [ |
| 133 | + 'error', |
| 134 | + { |
| 135 | + callbacksLast: false, |
| 136 | + ignoreCase: true, |
| 137 | + noSortAlphabetically: false, |
| 138 | + reservedFirst: false, |
| 139 | + shorthandFirst: false, |
| 140 | + shorthandLast: false, |
| 141 | + }, |
| 142 | + ], |
| 143 | + 'react/prop-types': 0, |
| 144 | + 'require-await': 2, |
| 145 | + semi: [1, 'always'], |
| 146 | + 'sort-destructure-keys/sort-destructure-keys': [2, { caseSensitive: false }], |
| 147 | + 'sort-imports': [ |
| 148 | + 'error', |
| 149 | + { |
| 150 | + allowSeparatedGroups: true, |
| 151 | + ignoreCase: true, |
| 152 | + ignoreDeclarationSort: true, |
| 153 | + ignoreMemberSort: false, |
| 154 | + memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], |
| 155 | + }, |
| 156 | + ], |
| 157 | + 'sort-keys': ['error', 'asc', { caseSensitive: false, minKeys: 2, natural: false }], |
| 158 | + 'valid-typeof': 2, |
| 159 | + '@typescript-eslint/explicit-module-boundary-types': 0, |
| 160 | + '@typescript-eslint/no-empty-interface': 0, |
| 161 | + '@typescript-eslint/ban-ts-comment': 0, |
| 162 | + '@typescript-eslint/no-unused-vars': [ |
| 163 | + 'warn', |
| 164 | + { ignoreRestSiblings: false, caughtErrors: 'none' }, |
| 165 | + ], |
| 166 | + '@typescript-eslint/no-var-requires': 0, |
| 167 | + 'react-hooks/exhaustive-deps': 1, |
| 168 | + 'react-native/no-inline-styles': 0, |
| 169 | + 'babel/no-invalid-this': 0, |
| 170 | + '@typescript-eslint/no-invalid-this': 'error', |
| 171 | + 'no-shadow': 0, |
| 172 | + }, |
| 173 | + }, |
| 174 | + { |
| 175 | + name: 'jest', |
| 176 | + files: ['src/**/__tests__/**'], |
| 177 | + plugins: { jest: eslintPluginJest }, |
| 178 | + languageOptions: { |
| 179 | + globals: eslintPluginJest.environments.globals.globals, |
| 180 | + }, |
| 181 | + rules: { |
| 182 | + 'jest/expect-expect': 'off', |
| 183 | + 'jest/no-conditional-expect': 'off', |
| 184 | + 'jest/prefer-inline-snapshots': 'off', |
| 185 | + 'jest/lowercase-name': 'off', |
| 186 | + 'jest/prefer-expect-assertions': 'off', |
| 187 | + 'jest/no-hooks': 'off', |
| 188 | + 'jest/no-if': 'off', |
| 189 | + 'jest/prefer-spy-on': 'warn', |
| 190 | + }, |
| 191 | + }, |
| 192 | +); |
0 commit comments