{{ message }}
Repository navigation
Expand file tree
/
Copy patheslint.config.mjs
More file actions
369 lines (359 loc) · 11.7 KB
/
Copy patheslint.config.mjs
File metadata and controls
369 lines (359 loc) · 11.7 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
// @ts-check
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'
// @ts-expect-error missing types
import noOnlyTests from 'eslint-plugin-no-only-tests'
import typegen from 'eslint-typegen'
import perfectionist from 'eslint-plugin-perfectionist'
import { importX } from 'eslint-plugin-import-x'
import parser from '@typescript-eslint/parser'
import markdown from '@eslint/markdown'
import { runtimeDependencies } from 'nuxt/meta'
import { generatedTemplateCopies } from './packages/ui-templates/lib/paths.mjs'
export default createConfigForNuxt({
features: {
stylistic: {
commaDangle: 'always-multiline',
},
tooling: true,
typescript: true,
},
})
.prepend(
{
// Ignores have to be a separate object to be treated as global ignores
// Don't add other attributes to this object
ignores: [
'.goff/**',
'packages/schema/schema/**',
'packages/nuxt/stubs/**',
...Object.keys(generatedTemplateCopies),
'packages/kit/test/types-fixture/**',
// deliberately does not compile
'test/fixtures/dev-error-sourcemap/app/components/Broken.vue',
'test/fixtures/vite-server-dev-error/app/components/Broken.vue',
],
},
{
languageOptions: {
globals: {
$fetch: 'readonly',
NodeJS: 'readonly',
},
},
name: 'local/settings',
settings: {
jsdoc: {
ignoreInternal: true,
tagNamePreference: {
note: 'note',
warning: 'warning',
},
},
},
},
)
.override('nuxt/javascript', {
rules: {
'curly': ['error', 'all'], // Including if blocks with a single statement
'dot-notation': 'error',
'logical-assignment-operators': ['error', 'always', { enforceForIfStatements: true }],
'no-console': ['warn', { allow: ['warn', 'error', 'debug'] }],
'no-lonely-if': 'error', // No single if in an "else" block
'no-useless-rename': 'error',
'object-shorthand': 'error',
'prefer-const': ['error', { destructuring: 'any', ignoreReadBeforeAssign: false }],
'require-await': 'error',
'sort-imports': ['error', { ignoreDeclarationSort: true }],
},
})
.override('nuxt/typescript/rules', {
rules: {
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-expect-error': 'allow-with-description',
'ts-ignore': true,
},
],
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
ignoreRestSiblings: true,
varsIgnorePattern: '',
},
],
'@typescript-eslint/triple-slash-reference': 'off',
'@typescript-eslint/unified-signatures': 'off',
...{
// TODO: Discuss if we want to enable this
'@typescript-eslint/ban-types': 'off',
// TODO: Discuss if we want to enable this
'@typescript-eslint/no-explicit-any': 'off',
// TODO: Discuss if we want to enable this
'@typescript-eslint/no-invalid-void-type': 'off',
},
},
})
.append({
files: ['packages/**/*.{mjs,js,ts}', '**/*.{spec,test}.{mjs,js,ts}'],
ignores: [
'packages/nuxt/src/app/types/augments.ts',
'test/fixtures/basic/app/plugins/this-should-not-load.spec.js',
],
languageOptions: {
parser,
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'@typescript-eslint/no-deprecated': 'error',
'@typescript-eslint/return-await': ['error', 'in-try-catch'],
'no-return-await': 'off',
},
})
.override('nuxt/tooling/unicorn', {
rules: {
'unicorn/no-new-array': 'off',
'unicorn/prefer-dom-node-text-content': 'off',
},
})
.override('nuxt/vue/rules', {
rules: {
},
})
// Stylistic rules
.override('nuxt/stylistic', {
rules: {
'@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'@stylistic/indent-binary-ops': 'off',
'@stylistic/max-statements-per-line': 'off',
'@stylistic/operator-linebreak': 'off',
'@stylistic/quote-props': ['error', 'consistent'],
'@stylistic/space-before-function-paren': ['error', 'always'],
},
})
// Append local rules
.append(
{
files: ['*.{js,ts}', 'scripts/**/*.{js,ts}', 'packages/**/*.{mts,ts,mjs,js}'],
ignores: ['packages/**/*.client.ts', 'packages/**/*.client.mts', 'packages/**/*.client.js', 'packages/**/*.client.mjs'],
name: 'local/requires/explicit-node-imports',
rules: {
// Ban direct use of restricted global identifiers
'no-restricted-globals': [
'error',
{
message: 'Use explicit import: import process from "node:process" (or a scoped alias). Implicit globals are banned for clarity and tree-shakability.',
name: 'process',
},
{
message: 'Use explicit import: import { performance } from "node:perf_hooks". Implicit global performance is banned in server contexts to ensure Node.js-specific usage.',
name: 'performance',
},
],
},
},
{
files: ['**/*.vue', '**/*.ts', '**/*.mts', '**/*.js', '**/*.cjs', '**/*.mjs'],
name: 'local/rules',
plugins: {
'import-x': importX,
},
rules: {
'import-x/no-restricted-paths': [
'error',
{
zones: [
{
from: 'packages/nuxt/src/!(core)/runtime/*',
message: 'core should not directly import from modules.',
target: 'packages/nuxt/src/core',
},
{
from: 'packages/nuxt/src/!(app)/**/*',
message: 'app should not directly import from modules.',
target: 'packages/nuxt/src/app',
},
{
from: 'packages/nuxt/src/app/**/index.ts',
message: 'should not import from barrel/index files',
target: 'packages/nuxt/src',
},
{
from: 'packages/nitro',
message: 'nitro should not directly import other packages.',
target: 'packages/!(nitro)/**/*',
},
],
},
],
'jsdoc/check-tag-names': [
'error',
{
definedTags: [
'experimental',
'knipignore',
'__NO_SIDE_EFFECTS__',
],
},
],
},
},
{
files: ['packages/*/src/**'],
ignores: ['packages/nuxt/src/app/**', 'packages/nuxt/src/server/**', '**/runtime/**/*'],
name: 'local/import-extensions',
plugins: {
'import-x': importX,
},
rules: {
'import/extensions': ['error', 'always', {
ignorePackages: true,
js: 'always',
ts: 'always',
vue: 'always',
}],
},
},
{
files: ['packages/{nuxt,kit,nitro-server,schema,vite,webpack,rspack}/src/**'],
// vite-node* files execute inside the nitro dev process rather than the
// Nuxt build process, so nostics catalogs do not apply there.
ignores: ['packages/nuxt/src/app/**', '**/runtime/**', '**/*.{spec,test}.{js,mjs,ts,mts}', 'packages/vite/src/vite-node*.ts'],
name: 'local/requires/nostics-diagnostics',
rules: {
'no-restricted-syntax': ['error', {
message: 'Use a nostics diagnostic (see packages/kit/src/diagnostics/) instead of logger/console for build-time warnings and errors.',
selector: 'CallExpression[callee.object.name=/^(logger|console)$/][callee.property.name=/^(warn|error)$/]',
}],
},
},
{
files: ['packages/nuxt/src/app/**', 'test/**', '**/runtime/**', '**/*.test.ts'],
name: 'local/disables/client-console',
rules: {
'no-console': 'off',
},
},
{
// `DefineSetupFnComponent<Props, Emits, Slots>` uses
// `{}` as the default for `Emits`/`Slots` so we suppress
// the warning in our runtime/ dirs.
files: ['packages/nuxt/src/app/**', 'packages/nuxt/src/{components,head,imports,pages}/runtime/**'],
name: 'local/disables/empty-object-type',
rules: {
'@typescript-eslint/no-empty-object-type': ['error', { allowObjectTypes: 'always' }],
},
},
// diagnostics catalogs keep an inline `/* #__PURE__ */` annotation on the
// reporter factory call inside the `reporters` array literal (for
// tree-shaking). array-bracket-spacing's autofix would strip a comment that
// sits right after `[`, so it is disabled in these dirs.
{
files: ['packages/**/diagnostics/**', 'packages/**/diagnostics.ts'],
name: 'local/diagnostics-pure-annotations',
rules: {
'@stylistic/array-bracket-spacing': 'off',
},
},
// manually specify dependencies for nuxt browser app
{
files: ['packages/nuxt/src/app/**', 'packages/nuxt/src/(components,head,imports,pages)/runtime/**'],
name: 'local/client-packages',
rules: {
'@typescript-eslint/no-restricted-imports': ['error', {
'patterns': [
{
allowTypeImports: true,
regex: `^(?!(${
[
// vue ecosystem
'@unhead',
'@vue/shared',
'ofetch',
'vue/server-renderer',
'vue',
'vue-router',
...runtimeDependencies,
'errx', /* only used in dev */
'nostics', /* runtime diagnostics catalog */
// internal deps
'nuxt/app',
].map(r => r.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|')
})($|/))(?!#)(?!\\.)[a-zA-Z@]`,
},
],
}],
},
},
{
files: ['**/fixtures/**', '**/fixture/**', '**/*-fixture/**'],
name: 'local/disables/fixtures',
rules: {
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/triple-slash-reference': 'off',
'nuxt/no-nuxt-config-test-key': 'off',
'vue/multi-word-component-names': 'off',
'vue/valid-v-for': 'off',
},
},
{
files: ['test/**', '**/*.test.ts'],
name: 'local/disables/tests',
plugins: {
'no-only-tests': noOnlyTests,
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-console': 'off',
'no-only-tests/no-only-tests': 'error',
},
},
// Sort rule keys in eslint config
{
files: ['**/eslint.config.mjs'],
name: 'local/sort-eslint-config',
plugins: {
perfectionist,
},
rules: {
'perfectionist/sort-objects': 'error',
},
},
{
files: ['packages/nuxt/src/app/components/welcome.vue'],
rules: {
'vue/multi-word-component-names': 'off',
},
},
{
files: ['**/*.md'],
language: 'markdown/commonmark',
name: 'local/docs-markdown',
plugins: {
markdown,
},
processor: 'markdown/markdown',
},
{
// targets code-blocks in markdown files
files: ['**/*.md/**/*'],
rules: {
'@stylistic/keyword-spacing': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'import/first': 'off',
'no-console': 'off',
'no-unused-vars': 'off',
'vue/no-unused-vars': 'off',
'vue/require-v-for-key': 'off',
},
},
)
// Generate type definitions for the eslint config
.onResolved(configs => typegen(configs))
You can’t perform that action at this time.
