|
| 1 | +import globals from 'globals'; |
| 2 | +import eslintConfigPrettier from 'eslint-config-prettier'; |
| 3 | +import reactHooks from 'eslint-plugin-react-hooks'; |
| 4 | +import reactRefresh from 'eslint-plugin-react-refresh'; |
| 5 | +import simpleImportSort from 'eslint-plugin-simple-import-sort'; |
| 6 | +import react from 'eslint-plugin-react'; |
| 7 | +import tseslint from 'typescript-eslint'; |
| 8 | +import js from '@eslint/js'; |
| 9 | + |
| 10 | +export default tseslint.config( |
| 11 | + { ignores: ['dist'] }, |
| 12 | + { |
| 13 | + extends: [ |
| 14 | + js.configs.recommended, |
| 15 | + ...tseslint.configs.recommended, |
| 16 | + eslintConfigPrettier |
| 17 | + ], |
| 18 | + files: ['**/*.{ts,tsx}'], |
| 19 | + ignores: ['**/*.d.ts'], |
| 20 | + languageOptions: { |
| 21 | + ecmaVersion: 2020, |
| 22 | + globals: globals.browser |
| 23 | + }, |
| 24 | + plugins: { |
| 25 | + 'react-hooks': reactHooks, |
| 26 | + 'react-refresh': reactRefresh, |
| 27 | + react: react, |
| 28 | + 'simple-import-sort': simpleImportSort |
| 29 | + }, |
| 30 | + linterOptions: { |
| 31 | + reportUnusedDisableDirectives: 'error' |
| 32 | + }, |
| 33 | + rules: { |
| 34 | + ...reactHooks.configs.recommended.rules, |
| 35 | + 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], |
| 36 | + '@typescript-eslint/no-explicit-any': 'error', // Disallow usage of any |
| 37 | + 'no-duplicate-imports': 'error', // Imports should be on one line |
| 38 | + 'no-console': 'warn', |
| 39 | + 'prefer-destructuring': ['error', { object: true, array: true }], |
| 40 | + 'simple-import-sort/imports': 'error', |
| 41 | + 'simple-import-sort/exports': 'error', |
| 42 | + 'simple-import-sort/imports': [ |
| 43 | + 'error', |
| 44 | + { |
| 45 | + groups: [ |
| 46 | + // Packages `react` related packages come first. |
| 47 | + ['^react', '^@?\\w'], |
| 48 | + // Internal packages. |
| 49 | + ['^(@|components)(/.*|$)'], |
| 50 | + // Side effect imports. |
| 51 | + ['^\\u0000'], |
| 52 | + // Parent imports. Put `..` last. |
| 53 | + ['^\\.\\.(?!/?$)', '^\\.\\./?$'], |
| 54 | + // Other relative imports. Put same-folder imports and `.` last. |
| 55 | + ['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'], |
| 56 | + // Style imports. |
| 57 | + ['^.+\\.?(css)$'] |
| 58 | + ] |
| 59 | + } |
| 60 | + ], |
| 61 | + 'react/jsx-curly-brace-presence': [ |
| 62 | + 'error', |
| 63 | + { |
| 64 | + props: 'always', |
| 65 | + children: 'never', |
| 66 | + propElementValues: 'always' |
| 67 | + } |
| 68 | + ], |
| 69 | + // Guards against stupidity |
| 70 | + 'no-self-compare': 'error', |
| 71 | + 'no-unreachable-loop': 'error', |
| 72 | + 'no-template-curly-in-string': 'error', // Catches "${}" template strings |
| 73 | + 'default-case': ['error', { commentPattern: '^skip\\sdefault' }], // require default switch case |
| 74 | + 'default-case-last': 'error' // enforce default switch case last |
| 75 | + } |
| 76 | + } |
| 77 | +); |
0 commit comments