-
-
Notifications
You must be signed in to change notification settings - Fork 704
Expand file tree
/
Copy patheslint.config.mjs
More file actions
390 lines (373 loc) · 11.2 KB
/
eslint.config.mjs
File metadata and controls
390 lines (373 loc) · 11.2 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
import { defineConfig } from 'eslint/config'
import globals from 'globals'
import eslintConfigFlatGitIgnore from 'eslint-config-flat-gitignore'
import eslintPluginEslintPlugin from 'eslint-plugin-eslint-plugin'
import eslintPluginJsonc from 'eslint-plugin-jsonc'
import eslintPluginNodeDependencies from 'eslint-plugin-node-dependencies'
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
import eslintMarkdown from '@eslint/markdown'
import eslintPluginMarkdownPreferences from 'eslint-plugin-markdown-preferences'
import eslintPluginTs from '@typescript-eslint/eslint-plugin'
import tsEslintParser from '@typescript-eslint/parser'
import vueEslintParser from 'vue-eslint-parser'
import noInvalidMeta from './eslint-internal-rules/no-invalid-meta.js'
import noInvalidMetaDocsCategories from './eslint-internal-rules/no-invalid-meta-docs-categories.js'
import requireEslintCommunity from './eslint-internal-rules/require-eslint-community.js'
import rules from './tools/lib/rules.js'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
// @ts-check
/// <reference path="./eslint-typegen.d.ts" />
import typegen from 'eslint-typegen'
const dirname = path.dirname(fileURLToPath(import.meta.url))
const MD_BASE_LINKS = {
'vue-eslint-parser': 'https://github.com/vuejs/vue-eslint-parser',
'@typescript-eslint/parser': 'https://typescript-eslint.io/packages/parser',
'eslint-typegen': 'https://github.com/antfu/eslint-typegen',
'@stylistic/eslint-plugin': 'https://eslint.style/'
}
const MD_LINKS = {
...Object.fromEntries(
rules.map((rule) => [
rule.ruleId,
`https://eslint.vuejs.org/rules/${rule.name}.html`
])
),
...MD_BASE_LINKS
}
// Links to rule docs from files in docs will link to the md file.
const MD_LINKS_FOR_DOCS = {
...Object.fromEntries(
rules.map((rule) => [
rule.ruleId,
path.resolve(dirname, './docs/rules', `./${rule.name}.md`)
])
),
...MD_BASE_LINKS
}
export default typegen([
eslintConfigFlatGitIgnore(),
{
ignores: [
'.changeset/**/*.md',
'tests/fixtures',
'tests/integrations/eslint-plugin-import'
]
},
eslintPluginPrettierRecommended,
...eslintPluginNodeDependencies.configs['flat/recommended'],
{
plugins: {
internal: {
rules: {
'no-invalid-meta': noInvalidMeta,
'no-invalid-meta-docs-categories': noInvalidMetaDocsCategories,
'require-eslint-community': requireEslintCommunity
}
}
}
},
...defineConfig({
files: ['**/*.{js,mjs,ts,mts}'],
extends: [
eslintPluginEslintPlugin.configs.all,
eslintPluginUnicorn.configs.recommended
],
// turn off some rules from shared configs in all files
rules: {
'eslint-plugin/require-meta-default-options': 'off', // TODO: enable when all rules have defaultOptions
'eslint-plugin/require-meta-docs-recommended': 'off', // use `categories` instead
'eslint-plugin/require-meta-schema-description': 'off',
'eslint-plugin/require-test-case-name': 'off',
'unicorn/filename-case': 'off',
'unicorn/no-null': 'off',
'unicorn/no-array-callback-reference': 'off', // doesn't work well with TypeScript's custom type guards
'unicorn/no-array-reverse': 'off', // enable when the minimum supported Node.js version is v20
'unicorn/no-array-sort': 'off', // enable when the minimum supported Node.js version is v20
'unicorn/no-useless-undefined': 'off',
'unicorn/prefer-global-this': 'off',
'unicorn/prefer-module': 'off',
'unicorn/prefer-top-level-await': 'off', // only available in ESM modules
'unicorn/prevent-abbreviations': 'off'
}
}),
{
name: 'typescript/setup',
files: ['**/*.{ts,mts}'],
languageOptions: {
parser: tsEslintParser,
parserOptions: {
sourceType: 'module'
}
},
plugins: {
'@typescript-eslint': eslintPluginTs
}
},
{
files: ['**/*.{js,mjs,ts,mts}'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'commonjs',
globals: {
...globals.es6,
...globals.node,
...globals.vitest
}
},
linterOptions: {
reportUnusedDisableDirectives: true
},
rules: {
'accessor-pairs': 2,
camelcase: [2, { properties: 'never' }],
'constructor-super': 2,
eqeqeq: [2, 'allow-null'],
'handle-callback-err': [2, '^(err|error)$'],
'jsx-quotes': [2, 'prefer-single'],
'new-cap': [2, { newIsCap: true, capIsNew: false }],
'new-parens': 2,
'no-array-constructor': 2,
'no-caller': 2,
'no-class-assign': 2,
'no-cond-assign': 2,
'no-const-assign': 2,
'no-control-regex': 2,
'no-delete-var': 2,
'no-dupe-args': 2,
'no-dupe-class-members': 2,
'no-dupe-keys': 2,
'no-duplicate-case': 2,
'no-empty-character-class': 2,
'no-empty-pattern': 2,
'no-eval': 2,
'no-ex-assign': 2,
'no-extend-native': 2,
'no-extra-bind': 2,
'no-extra-boolean-cast': 2,
'no-extra-parens': [2, 'functions'],
'no-fallthrough': 2,
'no-floating-decimal': 2,
'no-func-assign': 2,
'no-implied-eval': 2,
'no-inner-declarations': [2, 'functions'],
'no-invalid-regexp': 2,
'no-irregular-whitespace': 2,
'no-iterator': 2,
'no-label-var': 2,
'no-labels': [2, { allowLoop: false, allowSwitch: false }],
'no-lone-blocks': 2,
'no-multi-spaces': [2, { ignoreEOLComments: true }],
'no-multi-str': 2,
'no-native-reassign': 2,
'no-negated-in-lhs': 2,
'no-new-object': 2,
'no-new-require': 2,
'no-new-symbol': 2,
'no-new-wrappers': 2,
'no-obj-calls': 2,
'no-octal': 2,
'no-octal-escape': 2,
'no-path-concat': 2,
'no-proto': 2,
'no-redeclare': 2,
'no-regex-spaces': 2,
'no-return-assign': [2, 'except-parens'],
'no-self-assign': 2,
'no-self-compare': 2,
'no-sequences': 2,
'no-shadow-restricted-names': 2,
'no-sparse-arrays': 2,
'no-this-before-super': 2,
'no-throw-literal': 2,
'no-undef': 2,
'no-undef-init': 2,
'no-unexpected-multiline': 2,
'no-unmodified-loop-condition': 2,
'no-unneeded-ternary': [2, { defaultAssignment: false }],
'no-unreachable': 2,
'no-unsafe-finally': 2,
'no-unused-vars': [2, { vars: 'all', args: 'none' }],
'no-useless-call': 2,
'no-useless-computed-key': 2,
'no-useless-constructor': 2,
'no-useless-escape': 0,
'no-with': 2,
'one-var': [2, { initialized: 'never' }],
'use-isnan': 2,
'valid-typeof': 2,
'wrap-iife': [2, 'any'],
yoda: [2, 'never'],
'prefer-const': 2,
'prettier/prettier': 'error',
'eslint-plugin/require-meta-docs-description': [
'error',
{ pattern: '^(enforce|require|disallow).*[^.]$' }
],
'eslint-plugin/require-meta-fixable': [
'error',
{ catchNoFixerButFixableProperty: true }
],
'eslint-plugin/report-message-format': ['error', "^[A-Z`'{].*\\.$"],
'no-debugger': 'error',
'no-console': 'error',
'no-alert': 'error',
'no-void': 'error',
'no-warning-comments': 'warn',
'no-var': 'error',
'prefer-template': 'error',
'object-shorthand': 'error',
'prefer-rest-params': 'error',
'prefer-arrow-callback': 'error',
'prefer-spread': 'error',
'dot-notation': 'error',
'arrow-body-style': 'error',
'no-restricted-properties': [
'error',
{
object: 'context',
property: 'parserServices',
message: 'Use sourceCode.parserServices'
},
{
object: 'context',
property: 'getScope',
message: 'Use utils.getScope'
}
],
'unicorn/consistent-function-scoping': [
'error',
{ checkArrowFunctions: false }
],
'internal/require-eslint-community': ['error']
}
},
{
files: ['**/*.{mjs,ts,mts}'],
languageOptions: {
sourceType: 'module'
}
},
{
files: ['**/*.{ts,mts}'],
rules: {
...eslintPluginTs.configs.strict.rules,
...eslintPluginTs.configs['flat/eslint-recommended'].rules,
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true
}
],
'@typescript-eslint/triple-slash-reference': 'off',
'@typescript-eslint/unified-signatures': 'off',
'@typescript-eslint/ban-ts-comment': [
'error',
{
minimumDescriptionLength: 3
}
]
}
},
{
files: ['./**/*.vue'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parser: vueEslintParser
}
},
{
files: ['lib/rules/*.{js,ts}'],
rules: {
'eslint-plugin/require-meta-docs-url': [
'error',
{ pattern: 'https://eslint.vuejs.org/rules/{{name}}.html' }
],
'internal/no-invalid-meta': 'error',
'internal/no-invalid-meta-docs-categories': 'error'
}
},
{
files: ['eslint-internal-rules/*.js'],
rules: {
'eslint-plugin/require-meta-docs-url': 'off',
'internal/no-invalid-meta': 'error',
'internal/no-invalid-meta-docs-categories': 'error'
}
},
...defineConfig({
files: ['**/*.json'],
extends: [...eslintPluginJsonc.configs['flat/recommended-with-jsonc']],
rules: {
'prettier/prettier': 'off'
}
}),
...defineConfig([
{
files: ['**/*.md'],
extends: [
eslintMarkdown.configs.recommended,
eslintPluginMarkdownPreferences.configs.recommended
],
rules: {
'prettier/prettier': 'off',
'markdown/no-missing-link-fragments': 'off',
'markdown/no-multiple-h1': 'off',
'markdown-preferences/prefer-linked-words': [
'error',
{
words: MD_LINKS,
ignores: [
{
node: { type: 'heading' }
},
{
node: { type: 'footnoteDefinition' }
}
]
}
]
}
},
{
files: ['docs/**/*.md'],
rules: {
'markdown-preferences/prefer-linked-words': [
'error',
{
words: MD_LINKS_FOR_DOCS,
ignores: [
{
node: { type: 'heading' }
},
{
node: { type: 'footnoteDefinition' }
}
]
}
]
}
},
{
files: ['.github/ISSUE_TEMPLATE/*.md'],
rules: {
'prettier/prettier': 'off',
'markdown/no-missing-label-refs': 'off'
}
}
])
])