|
1 | | -import js from '@eslint/js'; |
2 | 1 | import globals from 'globals'; |
| 2 | +import js from '@eslint/js'; |
| 3 | +import tseslint from 'typescript-eslint'; |
| 4 | +import react from 'eslint-plugin-react'; |
3 | 5 | import reactHooks from 'eslint-plugin-react-hooks'; |
4 | 6 | import reactRefresh from 'eslint-plugin-react-refresh'; |
5 | | -import tseslint from 'typescript-eslint'; |
| 7 | +import prettier from 'eslint-plugin-prettier/recommended'; |
6 | 8 | import { defineConfig, globalIgnores } from 'eslint/config'; |
7 | | -import prettierPlugin from 'eslint-plugin-prettier'; |
8 | | -import prettierConfig from 'eslint-config-prettier'; |
| 9 | + |
| 10 | +const customRules = { |
| 11 | + // Helps with cleaning debug statements by erroring on console. |
| 12 | + 'no-console': 'error', |
| 13 | + // It's no longer needed to import React, so this just prevents weird |
| 14 | + // errors when you don't. |
| 15 | + 'react/react-in-jsx-scope': 'off', |
| 16 | + // Array indexes as keys should not be used. The occasional time it is |
| 17 | + // needed, an ignore can be added. |
| 18 | + 'react/no-array-index-key': 'error', |
| 19 | + // Helps with enforcing rules of hooks. Very helpful to catch wrongly |
| 20 | + // placed hooks, like conditional usage. |
| 21 | + 'react-hooks/rules-of-hooks': 'error', |
| 22 | + // Ensure that components are PascalCase |
| 23 | + 'react/jsx-pascal-case': 'error', |
| 24 | + // Force self closing components when there are no children. |
| 25 | + // Prevents `<MyComp prop='1'></MyComp>` |
| 26 | + 'react/self-closing-comp': 'error', |
| 27 | +}; |
9 | 28 |
|
10 | 29 | export default defineConfig([ |
11 | 30 | globalIgnores(['dist', 'node_modules', 'build', 'coverage']), |
| 31 | + js.configs.recommended, |
| 32 | + react.configs.flat.recommended, |
| 33 | + prettier, |
| 34 | + // JS/JSX config |
12 | 35 | { |
13 | | - files: ['**/*.{ts,tsx,js,jsx}'], |
14 | | - extends: [ |
15 | | - js.configs.recommended, |
16 | | - tseslint.configs.recommended, |
17 | | - reactHooks.configs['recommended-latest'], |
18 | | - reactRefresh.configs.vite, |
19 | | - prettierConfig, |
20 | | - ], |
| 36 | + files: ['**/*.{js,jsx,mjs,cjs}'], |
| 37 | + languageOptions: { |
| 38 | + ecmaVersion: 2020, |
| 39 | + globals: { ...globals.browser, process: 'readonly' }, |
| 40 | + }, |
| 41 | + settings: { react: { version: 'detect' } }, |
21 | 42 | plugins: { |
22 | | - prettier: prettierPlugin, |
| 43 | + react, |
| 44 | + 'react-hooks': reactHooks, |
| 45 | + 'react-refresh': reactRefresh, |
23 | 46 | }, |
24 | 47 | rules: { |
25 | | - ...prettierPlugin.configs.recommended.rules, |
| 48 | + ...customRules, |
| 49 | + 'no-unused-vars': [ |
| 50 | + 'error', |
| 51 | + { |
| 52 | + args: 'all', |
| 53 | + argsIgnorePattern: '^_', |
| 54 | + caughtErrors: 'all', |
| 55 | + caughtErrorsIgnorePattern: '^_', |
| 56 | + destructuredArrayIgnorePattern: '^_', |
| 57 | + varsIgnorePattern: '^_', |
| 58 | + ignoreRestSiblings: true, |
| 59 | + }, |
| 60 | + ], |
26 | 61 | }, |
| 62 | + }, |
| 63 | + // TS/TSX config |
| 64 | + { |
| 65 | + files: ['**/*.{ts,tsx}'], |
| 66 | + extends: [...tseslint.configs.recommendedTypeChecked], |
27 | 67 | languageOptions: { |
| 68 | + parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname }, |
28 | 69 | ecmaVersion: 2020, |
29 | | - globals: { |
30 | | - ...globals.browser, |
31 | | - process: 'readonly', |
32 | | - }, |
| 70 | + globals: { ...globals.browser, process: 'readonly' }, |
| 71 | + }, |
| 72 | + settings: { react: { version: 'detect' } }, |
| 73 | + plugins: { |
| 74 | + ...tseslint.plugins, |
| 75 | + 'react-hooks': reactHooks, |
| 76 | + 'react-refresh': reactRefresh, |
| 77 | + }, |
| 78 | + rules: { |
| 79 | + ...customRules, |
| 80 | + '@typescript-eslint/no-unused-vars': [ |
| 81 | + 'error', |
| 82 | + { |
| 83 | + args: 'all', |
| 84 | + argsIgnorePattern: '^_', |
| 85 | + caughtErrors: 'all', |
| 86 | + caughtErrorsIgnorePattern: '^_', |
| 87 | + destructuredArrayIgnorePattern: '^_', |
| 88 | + varsIgnorePattern: '^_', |
| 89 | + ignoreRestSiblings: true, |
| 90 | + }, |
| 91 | + ], |
| 92 | + // TODO: Consider making these errors in the future (use recommendedTypeChecked rules!). |
| 93 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 94 | + '@typescript-eslint/no-unsafe-assignment': 'warn', |
| 95 | + '@typescript-eslint/no-unsafe-call': 'warn', |
| 96 | + '@typescript-eslint/no-unsafe-member-access': 'warn', |
| 97 | + '@typescript-eslint/no-unsafe-return': 'warn', |
| 98 | + '@typescript-eslint/no-unsafe-argument': 'warn', |
| 99 | + '@typescript-eslint/no-unsafe-enum-comparison': 'warn', |
33 | 100 | }, |
34 | 101 | }, |
35 | 102 | ]); |
0 commit comments