-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy patheslint.config.mjs
More file actions
541 lines (487 loc) · 16.2 KB
/
eslint.config.mjs
File metadata and controls
541 lines (487 loc) · 16.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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
import { defineConfig } from 'eslint/config';
import cypress from 'eslint-plugin-cypress';
import ngrx from '@ngrx/eslint-plugin/v9';
import nx from '@nx/eslint-plugin';
import perfectionist from 'eslint-plugin-perfectionist';
import stylistic from '@stylistic/eslint-plugin';
import tsdoc from 'eslint-plugin-tsdoc';
import * as jsoncParser from 'jsonc-eslint-parser';
const cypressConfig = defineConfig({
files: ['**/cypress/**/*.ts'],
extends: [cypress.configs.recommended],
rules: {
'cypress/unsafe-to-chain-command': 'off',
},
});
const ngrxConfig = defineConfig({
files: ['**/*.ts'],
extends: [ngrx.configs.allTypeChecked],
rules: {
'@ngrx/on-function-explicit-return-type': 'off',
'@ngrx/prefer-effect-callback-in-block-statement': 'off',
},
languageOptions: {
parserOptions: {
projectService: true,
},
},
});
export default [
...nx.configs['flat/base'],
...nx.configs['flat/typescript'],
...nx.configs['flat/javascript'],
...nx.configs['flat/angular'],
...nx.configs['flat/angular-template'],
...cypressConfig,
...ngrxConfig,
{
ignores: ['**/dist', '**/out-tsc'],
},
{
plugins: {
'@stylistic': stylistic,
perfectionist,
tsdoc,
},
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
rules: {
'@nx/enforce-module-boundaries': [
'error',
{
enforceBuildableLibDependency: true,
allow: ['^.*/eslint(\\.base)?\\.config\\.[cm]?[jt]s$'],
depConstraints: [
{
sourceTag: '*',
onlyDependOnLibsWithTags: ['*'],
},
],
},
],
},
},
{
files: ['**/*.json'],
languageOptions: {
parser: jsoncParser,
},
},
{
files: ['**/*.ts'],
languageOptions: {
parserOptions: {
// Enable typed linting.
projectService: {
// Avoid triggering a parsing error.
allowDefaultProject: ['jest.config.ts'],
},
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
// TODO: Define these for different sectios of the monorepo.
//
// '@angular-eslint/component-selector': [
// 'error',
// {
// type: 'element',
// prefix: 'app',
// style: 'kebab-case',
// },
// ],
// '@angular-eslint/directive-selector': [
// 'error',
// {
// type: 'attribute',
// prefix: 'app',
// style: 'camelCase',
// },
// ],
'@angular-eslint/prefer-inject': 'error',
'@angular-eslint/prefer-on-push-component-change-detection': 'error',
'@angular-eslint/prefer-output-emitter-ref': 'error',
'@angular-eslint/prefer-output-readonly': 'error',
'@angular-eslint/prefer-signals': [
'error',
{
preferReadonlySignalProperties: true,
preferInputSignals: true,
preferQuerySignals: false,
useTypeChecking: true,
},
],
'@angular-eslint/prefer-standalone': 'error',
'@angular-eslint/no-uncalled-signals': 'error',
'@angular-eslint/relative-url-prefix': 'error',
'@angular-eslint/use-component-selector': 'error',
'@angular-eslint/use-component-view-encapsulation': 'error',
'@angular-eslint/use-injectable-provided-in': 'error',
'@angular-eslint/use-lifecycle-interface': 'error',
// Use a single import statement per module. Note that this uses
// the rule built in to eslint instead of something more advanced
// like `import/no-duplicates` from eslint-plugin-import. This is
// simpler to configure and doesn't require any extra
// dependencies (but isn't auto-fixable, alas).
'no-duplicate-imports': 'error',
// Sort and group module import statements, generally from
// least-to-most-specific, with Angular imports pushed closer to
// the top.
'perfectionist/sort-imports': [
'error',
{
type: 'natural',
newlinesBetween: 1,
groups: [
'builtin',
// List imports like `@Component`, `@Injectable`, etc.,
// early, so it's easy to tell at a glance what kind of
// module a file contains.
'angular-core',
// Packages installed by default as part of Angular, like
// `@angular/router`
'angular-defaults',
// RxJS is kind of an honorary default Angular package, at
// least for now, so it sits between `angular-defaults` and
// `angular-other`. When RxJS actually becomes optional,
// this group will probably end up after `angular-other`, or
// may just be folded into `external`.
'rxjs',
// Packages from Angular that require a separate install,
// like `@angular/material`
'angular-other',
'external',
'internal',
// Class materials library code
'class-materials-shared',
'class-materials-other',
// Per-project code, from least-specific to most-specific
'parent',
'sibling',
],
customGroups: [
{
groupName: 'angular-core',
elementNamePattern: '^@angular/core\\b',
},
{
groupName: 'angular-defaults',
// This pattern is based on a subset of the Angular
// default dependencies listed here:
// https://angular.dev/reference/configs/npm-packages
elementNamePattern:
'^@angular/(' +
[
'animations',
'cli',
'common',
'compiler',
'compiler-cli',
'forms',
'platform-browser',
'platform-browser-dynamic',
'router',
].join('|') +
')\\b',
},
{
groupName: 'rxjs',
elementNamePattern: '^rxjs$',
},
{
groupName: 'angular-other',
elementNamePattern: '^@angular/.+\\b',
},
// @class-materials imports could also be handled by tweaking
// `internalPattern`, but this makes it easier to list
// `@class-materials/shared` imports first.
{
groupName: 'class-materials-shared',
elementNamePattern: '^@class-materials/shared\\b',
},
{
groupName: 'class-materials-other',
elementNamePattern: '^@class-materials\\b',
},
],
},
],
'perfectionist/sort-named-imports': [
'error',
{
type: 'natural',
groups: ['all-capitals-and-underscores', 'starts-with-capital'],
// Class, types, important constants, etc., often have
// NAMES_LIKE_THIS or NamesLikeThis, so they're given their
// own groups and placed ahead of other imports.
customGroups: [
{
type: 'natural',
groupName: 'all-capitals-and-underscores',
elementNamePattern: '^[A-Z][A-Z_]+$',
},
{
type: 'natural',
groupName: 'starts-with-capital',
elementNamePattern: '^[A-Z]',
},
],
},
],
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'typeLike',
format: ['PascalCase'],
},
// // Don't start interfaces with an "I".
// {
// selector: 'interface',
// format: ['PascalCase'],
// custom: {
// regex: '^I[A-Z]',
// match: false,
// },
// },
{
selector: ['function', 'method'],
format: ['camelCase'],
},
// Allow constants defined at the top-level scope (which isn't
// truly global, despite what the modifier's called) to be
// either camelCase or UPPER_CASE.
{
selector: 'variable',
modifiers: ['const', 'global'],
format: ['camelCase', 'UPPER_CASE'],
},
// For now, allow Zod schema definitions to be either PascalCase
// or camelCase, since the naming convention isn't settled yet.
{
filter: 'Schema$',
selector: 'variable',
modifiers: ['const'],
format: ['camelCase', 'PascalCase'],
},
// NgRx stores can be camelCase or PascalCase.
{
filter: 'Store$',
selector: 'variable',
modifiers: ['const'],
format: ['camelCase', 'PascalCase'],
},
{
// Note: The 'variable' selector includes identifiers declared
// with `const`, `let`, and `var`.
selector: ['variable', 'parameter'],
format: ['camelCase'],
},
// Require any unused variables and parameters to start with an
// underscore.
{
selector: ['variable', 'parameter'],
modifiers: ['unused'],
format: ['camelCase'],
leadingUnderscore: 'require',
},
// This is more permissive than it should be, but it's probably
// not possible to express the exhaustive set of rules for class
// properties just using '@typescript-eslint/naming-convention'.
//
// What I'd prefer:
// - private properties can (but aren't required to) start with an
// underscore
// - protected and public properties can't start with an underscore
// - readonly properties can be
// - camelCase with an optional leading underscore,
// - or UPPER_CASE without a leading underscore
//
{
selector: 'classProperty',
format: ['camelCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
},
// Types and object literals often describe external data
// structures, so their property names come in several formats.
// (We could technically use a smaller set of formats for type
// properties, since many types are inferred from Zod schemas,
// but it's less confusing to keep the list of formats the same
// for both.)
{
selector: ['typeProperty', 'objectLiteralProperty'],
format: ['camelCase', 'snake_case', 'PascalCase'],
leadingUnderscore: 'allow',
},
// Don't try to enforce a convention for object literal property
// names that require quotes. They can be nearly anything.
{
selector: 'objectLiteralProperty',
modifiers: ['requiresQuotes'],
format: null,
},
],
// Disallow using code marked `@deprecated`. (This rule requires
// typed linting; see `languageOptions` above.)
'@typescript-eslint/no-deprecated': 'error',
// Require class properties to be declared with explicit `public`,
// `private`, or `protected` modifiers.
//
// Now that Angular allows component properties accessed from
// templates to be `protected` instead of requiring them to be
// public, leaving properties public by default no longer makes
// sense. (This rule could be scoped to just Angular components,
// but it's applied to all TypeScript classes for consistency.)
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
accessibility: 'explicit',
overrides: {
accessors: 'explicit',
constructors: 'no-public',
methods: 'off', // for now
properties: 'explicit',
parameterProperties: 'no-public',
},
},
],
},
},
{
files: [
'**/*.ts',
'**/*.tsx',
'**/*.cts',
'**/*.mts',
'**/*.js',
'**/*.jsx',
'**/*.cjs',
'**/*.mjs',
],
rules: {
// Require curly braces around single-line blocks.
curly: 'error',
'no-param-reassign': ['error', { props: true }],
// These are handled by equivalent @typescript-eslint rules, so
// they're disabled to avoid conflicts.
'no-restricted-imports': 'off',
'no-unused-vars': 'off',
'tsdoc/syntax': 'error',
'@stylistic/no-extra-semi': 'error',
'@typescript-eslint/no-empty-function': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-restricted-imports': [
'error',
{
paths: [
{
name: '@angular/common',
importNames: ['CommonModule'],
message: 'Import specific pipes and directives instead',
},
{
name: '@angular/common',
importNames: [
'NgFor',
'NgForOf',
'NgForOfContext',
'NgIf',
'NgIfContext',
'NgSwitch',
'NgSwitchCase',
'NgSwitchDefault',
],
message:
'Use template control flow (@if, @for, etc.) instead',
},
{
name: '@angular/common',
importNames: ['NgClass', 'NgStyle'],
message: 'Use [class] and [style] bindings instead',
},
],
},
],
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'after-used',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
vars: 'all',
varsIgnorePattern: '^_',
},
],
},
},
{
files: ['**/*.html'],
rules: {
// TODO: Convert to errors once applicable code is updated.
'@angular-eslint/template/click-events-have-key-events': 'off',
'@angular-eslint/template/interactive-supports-focus': 'off',
'@angular-eslint/template/mouse-events-have-key-events': 'off',
'@angular-eslint/template/label-has-associated-control': 'off',
// TODO: Convert to error once Angular ESLint can distinguish
// between signals and other types of methods.
'@angular-eslint/template/no-call-expression': 'off',
'@angular-eslint/template/no-any': 'error',
'@angular-eslint/template/no-interpolation-in-attributes': 'error',
'@angular-eslint/template/no-inline-styles': [
'error',
{
allowBindToStyle: true,
},
],
'@angular-eslint/template/prefer-at-empty': 'error',
'@angular-eslint/template/conditional-complexity': 'error',
'@angular-eslint/template/prefer-contextual-for-variables': 'error',
'@angular-eslint/template/prefer-control-flow': 'error',
'@angular-eslint/template/prefer-self-closing-tags': 'error',
'@angular-eslint/template/prefer-static-string-properties': 'error',
// TODO: Gradually decrease maxComplexity as applicable code is updated.
'@angular-eslint/template/cyclomatic-complexity': [
'warn',
{ maxComplexity: 10 },
],
},
},
{
files: ['**/*.spec.ts'],
rules: {
'@angular-eslint/use-component-selector': 'off',
},
},
// Temporarily loosen some restrictions on non-abc apps, just to make
// the WIP linting update less noisy along the way.
{
files: [
'apps/ngrx/**/*.ts',
'apps/rxjs/**/*.ts',
'apps/server/**/*.ts',
],
rules: {
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'no-param-reassign': ['off', { props: true }],
'@angular-eslint/prefer-on-push-component-change-detection': 'off',
'@angular-eslint/prefer-output-emitter-ref': 'off',
'@angular-eslint/prefer-output-readonly': 'off',
'@angular-eslint/prefer-signals': 'off',
},
},
{
files: ['apps/server/**/*.ts'],
rules: {
'@angular-eslint/use-injectable-provided-in': 'off',
},
},
{
files: ['apps/ngrx/**/*.html', 'apps/rxjs/**/*.html'],
rules: {
'@angular-eslint/template/no-inline-styles': ['off'],
},
},
];