-
Notifications
You must be signed in to change notification settings - Fork 393
/
eslint.config.mjs
414 lines (391 loc) · 13 KB
/
eslint.config.mjs
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/*
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import lwcInternal from '@lwc/eslint-plugin-lwc-internal';
import _import from 'eslint-plugin-import';
import header from 'eslint-plugin-header';
import globals from 'globals';
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import gitignore from 'eslint-config-flat-gitignore';
import vitest from '@vitest/eslint-plugin';
import { PUBLIC_PACKAGES as publicPackageData } from './scripts/shared/packages.mjs';
// convert filepath to eslint glob
const PUBLIC_PACKAGES = publicPackageData.map(({ path }) => `${path}/**`);
// Workaround for plugin schema validation failing in eslint v9
// Ref: https://github.com/Stuk/eslint-plugin-header/issues/57#issuecomment-2378485611
header.rules.header.meta.schema = false;
export default tseslint.config(
// ------------- //
// Global config //
// ------------- //
gitignore(),
{
ignores: ['**/fixtures'],
},
js.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
plugins: {
'@lwc/lwc-internal': lwcInternal,
import: _import,
header,
},
linterOptions: {
reportUnusedDisableDirectives: true,
},
languageOptions: {
globals: {
...globals.es2021,
},
parserOptions: {
projectService: {
allowDefaultProject: [
// I'm not sure why these files aren't picked up... :\
'packages/@lwc/module-resolver/scripts/test/matchers/to-throw-error-with-code.ts',
'packages/@lwc/module-resolver/scripts/test/matchers/to-throw-error-with-type.ts',
'packages/@lwc/module-resolver/scripts/test/setup-test.ts',
],
},
},
},
rules: {
// Rules without config, sorted alphabetically by namespace, then rule
'@lwc/lwc-internal/no-invalid-todo': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/unbound-method': 'off',
'block-scoped-var': 'error',
'no-alert': 'error',
// Deprecated, replace with rule in eslint-plugin-n when removed
'no-buffer-constructor': 'error',
'no-console': 'error',
'no-eval': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-extra-label': 'error',
'no-iterator': 'error',
'no-lone-blocks': 'error',
'no-proto': 'error',
'no-self-compare': 'error',
'no-undef-init': 'error',
'no-useless-computed-key': 'error',
'no-useless-return': 'error',
// Deprecated, replace with rule in @stylistic/eslint-plugin-js when removed
'template-curly-spacing': 'error',
yoda: 'error',
// Rule with config, sorted alphabetically by namespace, then rule
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
},
],
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'index',
'sibling',
'object',
'type',
],
},
],
'no-restricted-imports': [
'error',
{
name: '@lwc/features',
importNames: ['lwcRuntimeFlags', 'runtimeFlags', 'default'],
message:
'Do not directly import runtime flags from @lwc/features. Use the global lwcRuntimeFlags variable instead.',
},
],
'no-restricted-properties': [
'error',
{
object: 'arguments',
property: 'callee',
message: 'arguments.callee is deprecated',
},
{
object: 'global',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
},
{
object: 'self',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
},
{
object: 'window',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
},
{
object: 'global',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
},
{
object: 'self',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
},
{
object: 'window',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
},
{
property: '__defineGetter__',
message: 'Please use Object.defineProperty instead.',
},
{
property: '__defineSetter__',
message: 'Please use Object.defineProperty instead.',
},
{
object: 'Math',
property: 'pow',
message: 'Use the exponentiation operator (**) instead.',
},
{
object: 'globalThis',
property: 'lwcRuntimeFlags',
message: 'Use the bare global lwcRuntimeFlags instead.',
},
],
'prefer-const': [
'error',
{
destructuring: 'any',
ignoreReadBeforeAssign: true,
},
],
},
},
{
files: ['**/*.js', '**/*.mjs', '**/*.cjs'],
...tseslint.configs.disableTypeChecked,
},
// -------------------------------- //
// Scripts, tests, and config files //
// -------------------------------- //
// aka things that run in node and might still use `require`
{
files: [
'commitlint.config.js',
'**/scripts/**',
'**/rollup.config.js',
'**/rollup.config.mjs',
],
languageOptions: {
globals: {
...globals.node,
},
},
},
{
files: ['**/scripts/**', 'packages/@lwc/integration-tests/src/components/**/*.spec.js'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
},
},
{
files: ['packages/@lwc/integration-karma/**'],
languageOptions: {
globals: {
...globals.jest,
...globals.es2021,
},
},
plugins: {
vitest,
},
rules: {
'vitest/no-focused-tests': 'error',
'vitest/valid-expect': 'error',
'vitest/valid-expect-in-promise': 'error',
'vitest/no-conditional-tests': 'error',
'vitest/no-done-callback': 'error',
},
},
{
files: ['**/__tests__/**'],
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.rules,
'vitest/no-focused-tests': 'error',
'vitest/valid-expect-in-promise': 'error',
'vitest/no-conditional-tests': 'error',
'vitest/no-done-callback': 'error',
},
},
{
files: ['**/scripts/**'],
rules: {
'no-console': 'off',
},
},
// ---------------------- //
// Package-specific rules //
// ---------------------- //
{
// All published files must have a copyright header
files: PUBLIC_PACKAGES,
ignores: PUBLIC_PACKAGES.flatMap((pkg) => [
`${pkg}/vitest.config.mjs`,
`${pkg}/src/__tests__/**`,
]),
rules: {
'header/header': [
'error',
'block',
[
'',
{
pattern:
'^ \\* Copyright \\(c\\) \\d{4}, ([sS]alesforce.com, inc|Salesforce, Inc)\\.$',
// This copyright text should match the text used in the rollup config
template: ` * Copyright (c) ${new Date().getFullYear()}, Salesforce, Inc.`,
},
' * All rights reserved.',
' * SPDX-License-Identifier: MIT',
' * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT',
' ',
],
1 /* newline after header */,
],
},
},
{
files: [
'packages/@lwc/engine-core/**',
'packages/@lwc/engine-dom/**',
'packages/@lwc/synthetic-shadow/**',
],
rules: {
'@lwc/lwc-internal/no-global-node': 'error',
'prefer-rest-params': 'off',
'prefer-spread': 'off',
},
},
{
files: ['packages/@lwc/integration-tests/**'],
languageOptions: {
globals: {
$: true,
browser: true,
...globals.browser,
...globals.mocha,
...globals.node,
},
},
},
{
files: ['packages/@lwc/perf-benchmarks/**'],
languageOptions: {
globals: {
after: true,
before: true,
benchmark: true,
run: true,
browser: true,
...globals.browser,
...globals.node,
},
},
},
{
files: ['packages/@lwc/perf-benchmarks-components/**'],
languageOptions: {
globals: {
browser: true,
...globals.node,
},
},
},
{
files: ['packages/@lwc/integration-karma/**'],
languageOptions: {
globals: {
lwcRuntimeFlags: true,
process: true,
LWC: true,
TestUtils: true,
...globals.browser,
...globals.jasmine,
},
},
rules: {
'no-var': 'off',
'prefer-rest-params': 'off',
},
},
{
files: ['packages/@lwc/synthetic-shadow/**'],
languageOptions: {
globals: {
process: true,
...globals.browser,
},
},
},
{
// We normally restrict importing @lwc/features, but we need to do so in these files
files: ['packages/lwc/features.js', 'packages/lwc/features.d.ts'],
rules: {
'no-restricted-imports': 'off',
},
},
{
files: ['playground/**'],
languageOptions: {
globals: {
...globals.browser,
},
},
},
// --------------------- //
// Weird file extensions //
// --------------------- //
{
// These are empty files used to help debug test fixtures
files: ['**/.only'],
plugins: { '@lwc/lwc-internal': lwcInternal },
rules: {
'@lwc/lwc-internal/forbidden-filename': 'error',
},
},
{
// These are empty files used to help debug test fixtures
files: ['**/.skip'],
plugins: { '@lwc/lwc-internal': lwcInternal },
rules: {
'@lwc/lwc-internal/forbidden-filename': 'off',
},
}
);