|
3 | 3 | * @ref https://eslint.org/ |
4 | 4 | */ |
5 | 5 |
|
6 | | -import { antfu } from '@antfu/eslint-config'; |
7 | | -import imp from 'eslint-plugin-import-x'; |
8 | | - |
9 | | -export default antfu({ |
10 | | - type: 'lib', |
11 | | - ignores: [ |
12 | | - '**/dist/**', |
13 | | - '**/dist-*/**', |
14 | | - ], |
15 | | - files: [ |
16 | | - '**/.*.{js,cjs,mjs}', |
17 | | - '**/*.{js,mjs,cjs,ts,mts,jsx,tsx}', |
18 | | - ], |
19 | | - stylistic: { |
20 | | - semi: true, |
21 | | - }, |
22 | | - typescript: { |
23 | | - overrides: { |
24 | | - // 不必要显式返回类型 |
25 | | - // @ref https://typescript-eslint.io/rules/explicit-function-return-type/ |
26 | | - 'ts/explicit-function-return-type': ['off'], |
27 | | - }, |
28 | | - }, |
29 | | - react: true, |
30 | | - unocss: true, |
31 | | - rules: { |
32 | | - ...imp.configs.recommended.rules, |
33 | | - ...imp.configs.typescript.rules, |
34 | | - // 忽略 virtual: 开头的 import |
35 | | - // @ref https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-unresolved.md |
36 | | - 'import/no-unresolved': ['error', { ignore: ['^virtual:'] }], |
37 | | - // 不必要求如何使用 process |
38 | | - // @ref https://github.com/eslint-community/eslint-plugin-n/blob/HEAD/docs/rules/prefer-global/process.md |
39 | | - 'node/prefer-global/process': ['off'], |
40 | | - }, |
41 | | - settings: { |
42 | | - // 支持在 typeScript 解析 import |
43 | | - // @ref https://github.com/un-ts/eslint-plugin-import-x?tab=readme-ov-file#typescript |
44 | | - 'import-x/resolver': { |
45 | | - typescript: true, |
46 | | - }, |
47 | | - }, |
48 | | -}); |
| 6 | +import javaScript from '@eslint/js'; |
| 7 | +import typeScript from 'typescript-eslint'; |
| 8 | +import tsParser from '@typescript-eslint/parser'; |
| 9 | +import react from 'eslint-plugin-react'; |
| 10 | +import reactHooks from 'eslint-plugin-react-hooks'; |
| 11 | +import reactRefresh from 'eslint-plugin-react-refresh'; |
| 12 | +import importX from 'eslint-plugin-import-x'; |
| 13 | +import globals from 'globals'; |
| 14 | +import uno from '@unocss/eslint-plugin'; |
| 15 | +import prettierRecommended from 'eslint-plugin-prettier/recommended'; |
| 16 | +import prettierConfig from 'eslint-config-prettier'; |
| 17 | + |
| 18 | +export default typeScript.config( |
| 19 | + { |
| 20 | + ignores: ['**/.{git,idea,vscode,husky}/**', '**/dist/**', '**/dist-*/**', '**/coverage/**'], |
| 21 | + }, |
| 22 | + |
| 23 | + // import |
| 24 | + { |
| 25 | + plugins: { |
| 26 | + 'import-x': importX, |
| 27 | + }, |
| 28 | + rules: { |
| 29 | + ...importX.configs.recommended.rules, |
| 30 | + ...importX.configs.typescript.rules, |
| 31 | + |
| 32 | + // 忽略 virtual: 开头的 import |
| 33 | + // @ref https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-unresolved.md |
| 34 | + 'import-x/no-unresolved': ['error', { ignore: ['^virtual:'] }], |
| 35 | + }, |
| 36 | + settings: { |
| 37 | + // 支持在 typeScript 解析 import |
| 38 | + // @ref https://github.com/un-ts/eslint-plugin-import-x?tab=readme-ov-file#typescript |
| 39 | + 'import-x/resolver': { |
| 40 | + typescript: true, |
| 41 | + }, |
| 42 | + }, |
| 43 | + }, |
| 44 | + |
| 45 | + // js |
| 46 | + javaScript.configs.recommended, |
| 47 | + { |
| 48 | + rules: { |
| 49 | + 'no-unused-vars': ['off'], |
| 50 | + }, |
| 51 | + }, |
| 52 | + |
| 53 | + // ts |
| 54 | + ...typeScript.configs.recommended, |
| 55 | + ...typeScript.configs.recommendedTypeChecked, |
| 56 | + { |
| 57 | + languageOptions: { |
| 58 | + parser: tsParser, |
| 59 | + parserOptions: { |
| 60 | + project: true, |
| 61 | + tsconfigRootDir: import.meta.dirname, |
| 62 | + }, |
| 63 | + }, |
| 64 | + rules: { |
| 65 | + '@typescript-eslint/no-unused-vars': 'off', |
| 66 | + }, |
| 67 | + }, |
| 68 | + { |
| 69 | + files: ['**/*.{js,cjs,mjs,jsx}'], |
| 70 | + ...typeScript.configs.disableTypeChecked, |
| 71 | + }, |
| 72 | + |
| 73 | + // react |
| 74 | + { |
| 75 | + files: ['**/*.{jsx,tsx}'], |
| 76 | + plugins: { |
| 77 | + react, |
| 78 | + 'react-hooks': reactHooks, |
| 79 | + 'react-refresh': reactRefresh, |
| 80 | + }, |
| 81 | + settings: { |
| 82 | + react: { |
| 83 | + version: 'detect', |
| 84 | + }, |
| 85 | + }, |
| 86 | + rules: { |
| 87 | + ...react.configs.recommended.rules, |
| 88 | + ...reactHooks.configs.recommended.rules, |
| 89 | + 'react/react-in-jsx-scope': 'off', |
| 90 | + }, |
| 91 | + }, |
| 92 | + |
| 93 | + // uno |
| 94 | + uno.configs.flat, |
| 95 | + { |
| 96 | + files: ['**/*.{jsx,tsx}'], |
| 97 | + }, |
| 98 | + |
| 99 | + // prettier |
| 100 | + prettierRecommended, |
| 101 | + prettierConfig, |
| 102 | + |
| 103 | + { |
| 104 | + languageOptions: { |
| 105 | + globals: { |
| 106 | + ...globals.node, |
| 107 | + ...globals.browser, |
| 108 | + }, |
| 109 | + }, |
| 110 | + }, |
| 111 | +); |
0 commit comments