|
| 1 | +import js from '@eslint/js' |
| 2 | +import { defineConfig } from 'eslint/config' |
| 3 | +import configPrettier from 'eslint-config-prettier' |
| 4 | +import jsonc from 'eslint-plugin-jsonc' |
| 5 | +import pluginPrettier from 'eslint-plugin-prettier/recommended' |
| 6 | +import simpleImportSort from 'eslint-plugin-simple-import-sort' |
| 7 | +import pluginUnicorn from 'eslint-plugin-unicorn' |
| 8 | +import pluginVue from 'eslint-plugin-vue' |
| 9 | +import globals from 'globals' |
| 10 | +import jsoncParser from 'jsonc-eslint-parser' |
| 11 | +import tseslint from 'typescript-eslint' |
| 12 | +import vueParser from 'vue-eslint-parser' |
| 13 | + |
| 14 | +export default defineConfig( |
| 15 | + { |
| 16 | + ignores: [ |
| 17 | + '**/node_modules/**', |
| 18 | + '**/dist/**', |
| 19 | + 'vitest.workspace.mjs', |
| 20 | + 'cases/**', |
| 21 | + 'test/**', |
| 22 | + 'benchmark/**', |
| 23 | + 'webpack.config.js', |
| 24 | + 'bin/*', |
| 25 | + 'vite.config.ts', |
| 26 | + ], |
| 27 | + }, |
| 28 | + js.configs.recommended, |
| 29 | + ...pluginVue.configs['flat/recommended'], |
| 30 | + ...tseslint.configs.recommended, |
| 31 | + ...tseslint.configs.stylistic, |
| 32 | + { |
| 33 | + files: ['**/*.ts', '**/*.d.ts'], |
| 34 | + languageOptions: { |
| 35 | + parser: tseslint.parser, |
| 36 | + sourceType: 'module', |
| 37 | + ecmaVersion: 'latest', |
| 38 | + globals: { |
| 39 | + ...globals.browser, |
| 40 | + ...globals.node, |
| 41 | + }, |
| 42 | + }, |
| 43 | + }, |
| 44 | + { |
| 45 | + files: ['**/*.vue'], |
| 46 | + languageOptions: { |
| 47 | + parser: vueParser, |
| 48 | + parserOptions: { |
| 49 | + parser: tseslint.parser, |
| 50 | + extraFileExtensions: ['.vue'], |
| 51 | + sourceType: 'module', |
| 52 | + ecmaVersion: 'latest', |
| 53 | + }, |
| 54 | + globals: { |
| 55 | + ...globals.browser, |
| 56 | + ...globals.node, |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | + { |
| 61 | + files: ['**/*.ts', '**/*.d.ts', '**/*.vue', 'eslint.config.mjs'], |
| 62 | + plugins: { |
| 63 | + 'simple-import-sort': simpleImportSort, |
| 64 | + unicorn: pluginUnicorn, |
| 65 | + }, |
| 66 | + rules: { |
| 67 | + 'unicorn/prefer-node-protocol': 'error', |
| 68 | + 'unicorn/prefer-module': 'error', |
| 69 | + 'simple-import-sort/imports': 'error', |
| 70 | + 'simple-import-sort/exports': 'error', |
| 71 | + eqeqeq: 'error', |
| 72 | + 'no-caller': 'error', |
| 73 | + 'no-constant-condition': ['error', { checkLoops: false }], |
| 74 | + 'no-eval': 'error', |
| 75 | + 'no-extra-bind': 'error', |
| 76 | + 'no-new-func': 'error', |
| 77 | + 'no-new-wrappers': 'error', |
| 78 | + 'no-throw-literal': 'error', |
| 79 | + 'no-undef-init': 'error', |
| 80 | + 'no-var': 'error', |
| 81 | + 'object-shorthand': 'error', |
| 82 | + 'prefer-const': 'error', |
| 83 | + 'prefer-object-spread': 'error', |
| 84 | + 'unicode-bom': ['error', 'never'], |
| 85 | + 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', |
| 86 | + 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', |
| 87 | + 'no-unused-vars': 'off', |
| 88 | + 'no-extra-boolean-cast': 'off', |
| 89 | + 'no-case-declarations': 'off', |
| 90 | + 'no-cond-assign': 'off', |
| 91 | + 'no-control-regex': 'off', |
| 92 | + 'no-inner-declarations': 'off', |
| 93 | + 'no-empty': 'off', |
| 94 | + // @typescript-eslint/eslint-plugin |
| 95 | + '@typescript-eslint/no-unused-expressions': 'off', |
| 96 | + '@typescript-eslint/ban-ts-comment': 'off', |
| 97 | + '@typescript-eslint/no-empty-function': 'off', |
| 98 | + '@typescript-eslint/no-namespace': 'off', |
| 99 | + '@typescript-eslint/no-non-null-asserted-optional-chain': 'off', |
| 100 | + '@typescript-eslint/no-var-requires': 'off', |
| 101 | + '@typescript-eslint/no-empty-interface': 'off', |
| 102 | + '@typescript-eslint/no-explicit-any': 'off', |
| 103 | + '@typescript-eslint/no-empty-object-type': 'off', // {} is a totally useful and valid type. |
| 104 | + '@typescript-eslint/no-require-imports': 'off', |
| 105 | + '@typescript-eslint/no-inferrable-types': 'off', |
| 106 | + '@typescript-eslint/no-this-alias': 'off', |
| 107 | + // Pending https://github.com/typescript-eslint/typescript-eslint/issues/4820 |
| 108 | + '@typescript-eslint/prefer-optional-chain': 'off', |
| 109 | + '@typescript-eslint/no-unused-vars': [ |
| 110 | + 'error', |
| 111 | + { |
| 112 | + args: 'all', |
| 113 | + argsIgnorePattern: '^_', |
| 114 | + caughtErrors: 'all', |
| 115 | + caughtErrorsIgnorePattern: '^_', |
| 116 | + }, |
| 117 | + ], |
| 118 | + 'vue/no-v-html': 'off', |
| 119 | + 'vue/multi-word-component-names': 'off', |
| 120 | + 'no-undef': 'off', // TypeScript handles this |
| 121 | + 'no-async-promise-executor': 'off', |
| 122 | + }, |
| 123 | + }, |
| 124 | + ...jsonc.configs['flat/recommended-with-jsonc'], |
| 125 | + { |
| 126 | + files: ['**/*.json', '**/*.jsonc', '**/*.json5'], |
| 127 | + languageOptions: { |
| 128 | + parser: jsoncParser, |
| 129 | + }, |
| 130 | + rules: { |
| 131 | + 'jsonc/array-bracket-spacing': ['error', 'never'], |
| 132 | + 'jsonc/comma-dangle': ['error', 'never'], |
| 133 | + 'jsonc/indent': ['error', 2], |
| 134 | + 'jsonc/no-comments': 'off', |
| 135 | + 'jsonc/quotes': ['error', 'double'], |
| 136 | + }, |
| 137 | + }, |
| 138 | + { |
| 139 | + files: ['src/i18n/**/*.json'], |
| 140 | + rules: { |
| 141 | + 'jsonc/sort-keys': [ |
| 142 | + 'error', |
| 143 | + 'asc', // 升序排列 |
| 144 | + { |
| 145 | + caseSensitive: false, |
| 146 | + natural: true, |
| 147 | + }, |
| 148 | + ], |
| 149 | + }, |
| 150 | + }, |
| 151 | + { |
| 152 | + files: ['**/*.mjs', '**/*.mts'], |
| 153 | + rules: { |
| 154 | + // These globals don't exist outside of CJS files. |
| 155 | + 'no-restricted-globals': [ |
| 156 | + 'error', |
| 157 | + { name: '__filename' }, |
| 158 | + { name: '__dirname' }, |
| 159 | + { name: 'require' }, |
| 160 | + { name: 'module' }, |
| 161 | + { name: 'exports' }, |
| 162 | + ], |
| 163 | + }, |
| 164 | + }, |
| 165 | + { |
| 166 | + files: ['*.config.js', 'scripts/*.{js,mjs,cjs}'], |
| 167 | + languageOptions: { |
| 168 | + globals: { |
| 169 | + ...globals.node, |
| 170 | + }, |
| 171 | + }, |
| 172 | + rules: { |
| 173 | + // 在脚本文件中,通常允许使用 console 和 require |
| 174 | + 'no-console': 'off', |
| 175 | + '@typescript-eslint/no-require-imports': 'off', |
| 176 | + '@typescript-eslint/no-var-requires': 'off', |
| 177 | + }, |
| 178 | + }, |
| 179 | + configPrettier, |
| 180 | + pluginPrettier, |
| 181 | +) |
0 commit comments