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