-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
411 lines (398 loc) · 18.3 KB
/
eslint.config.mjs
File metadata and controls
411 lines (398 loc) · 18.3 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
// @ts-check
import process from 'node:process'
import eslint from '@eslint/js'
import { defineConfig } from 'eslint/config'
import tseslint from 'typescript-eslint'
import stylistic from '@stylistic/eslint-plugin'
import storybook from 'eslint-plugin-storybook'
import angular from 'angular-eslint'
// import importPlugin from 'eslint-plugin-import'
import pluginPromise from 'eslint-plugin-promise'
import nodePlugin from 'eslint-plugin-n'
export default defineConfig(
eslint.configs.recommended,
tseslint.configs.recommended,
tseslint.configs.stylistic,
// @ts-expect-error // Seems related to: https://github.com/typescript-eslint/typescript-eslint/issues/11543
angular.configs.tsRecommended,
// importPlugin.flatConfigs.recommended, // TODO: Decide if we want to use this.
storybook.configs['flat/recommended'],
{
plugins: {
'@stylistic': stylistic,
},
files: ['{src,projects,scripts,.storybook}/**/*.{ts,js,mjs}'],
extends: [
// @ts-expect-error // The 'eslint-plugin-promise' config is defined in a way that Typescript is unable to notice it has a `configs` property.
pluginPromise.configs['flat/recommended'],
nodePlugin.configs['flat/recommended-script'],
],
ignores: [
// '**/*.scss',
// '**/*.html',
// '!.storybook',
'node_modules/**/*',
],
languageOptions: {
parserOptions: {
tsconfigRootDir: process.cwd(),
},
},
rules: {
'accessor-pairs': 'off',
// 'arrow-body-style': ['error', 'as-needed'],
camelcase: ['error', { properties: 'never' }], // TODO: Consider changing to 'always'
// 'complexity': ['error', 10],
complexity: 'off',
// 'curly': ['error', 'multi-line'], // NOTE: Use prettier?
'dot-notation': 'off',
eqeqeq: ['error', 'always', { null: 'ignore' }],
'guard-for-in': 'error',
// 'id-blacklist': [ 'error', 'any', 'Number', 'number', 'String', 'string', 'Boolean', 'boolean', 'Undefined', 'undefined' ],
// 'id-match': 'error',
'new-cap': [
'error',
{ newIsCap: true, capIsNew: false, properties: false },
],
'no-bitwise': 'error',
'no-array-constructor': 'error',
'no-caller': 'error',
'no-constant-condition': ['error', { checkLoops: false }],
'no-console': 'warn',
'no-empty': 'error',
'no-empty-function': 'off', // TODO: Consider enabling
'no-eval': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-extra-boolean-cast': 'error',
'no-implied-eval': 'error',
'no-inner-declarations': ['error', 'functions'],
'no-invalid-this': 'error',
'no-iterator': 'error',
'no-label-var': 'error',
'no-labels': ['error', { allowLoop: false, allowSwitch: false }],
'no-lone-blocks': 'error',
'no-multi-str': 'error',
'no-new': 'error',
'no-new-func': 'error',
'no-object-constructor': 'error',
'no-new-native-nonconstructor': 'error',
'no-new-wrappers': 'error',
'no-octal': 'error',
'no-octal-escape': 'error',
'no-proto': 'error',
'no-param-reassign': 'error',
// 'no-return-assign': ['error', 'except-parens'],
'no-return-assign': 'off',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-shadow': 'off', // Using '@typscript-eslint/no-shadow' instead.
'no-template-curly-in-string': 'error',
'no-throw-literal': 'error',
'no-undef': 'off', // Typescript compiler should handle this.
'no-undef-init': 'error',
'no-unmodified-loop-condition': 'error',
'no-unneeded-ternary': ['error', { defaultAssignment: false }],
'no-unused-expressions': 'off', // Using '@typescript-eslint/no-unused-expressions' instead.
'no-unused-vars': 'off',
'no-use-before-define': 'off',
'no-useless-call': 'error',
'no-useless-computed-key': 'error',
'no-useless-concat': 'error',
'no-useless-constructor': 'off', // Using '@typscript-eslint/no-constructor' instead.
'no-useless-rename': 'error',
'no-useless-return': 'error',
'no-var': 'error',
// 'object-shorthand': 'error',
'object-shorthand': 'off',
'prefer-arrow-callback': 'error',
'prefer-const': 'error',
'prefer-object-spread': 'error',
'prefer-template': 'off', // auto-fix is bugged, so disable for now.
radix: 'error',
'no-underscore-dangle': 'off',
'one-var': ['error', { initialized: 'never' }],
'prefer-promise-reject-errors': 'error',
'symbol-description': 'error',
'unicode-bom': ['error', 'never'],
'valid-typeof': ['error', { requireStringLiterals: true }],
yoda: ['error', 'never'],
// 'sort-imports': ['error', { 'allowSeparatedGroups': true }],
'sort-imports': 'off', // TODO: Consider enabling. This may need a different rule to configure better.
// '@stylistic/semi': 'off', // NOTE: Use prettier
// '@stylistic/semi-spacing': ['error', { 'before': false, 'after': true }], // NOTE: Use prettier
// '@stylistic/quotes': ['error', 'single', { 'avoidEscape': true, 'allowTemplateLiterals': 'always' }], // NOTE: Use prettier?
// '@stylistic/arrow-parens': ['error', 'as-needed'], // NOTE: Use prettier
// '@stylistic/arrow-spacing': ['error', { 'before': true, 'after': true }], // NOTE: Use prettier
// '@stylistic/indent': ['error', 2, {
// 'SwitchCase': 1,
// }], // NOTE: Use prettier?
// '@stylistic/block-spacing': ['error', 'always'], // NOTE: Use prettier
// '@stylistic/brace-style': ['error', '1tbs', { 'allowSingleLine': true }], // NOTE: Use prettier
// '@stylistic/comma-dangle': ['error', 'always-multiline'], // NOTE: Use prettier
// '@stylistic/comma-spacing': ['error', { 'before': false, 'after': true }], // NOTE: Use prettier
// '@stylistic/comma-style': ['error', 'last'], // NOTE: Use prettier
// '@stylistic/dot-location': ['error', 'property'], // NOTE: Use prettier
// '@stylistic/eol-last': ['error', 'always'], // NOTE: Use prettier
// '@stylistic/linebreak-style': ['error', 'unix'], // NOTE: Use prettier
// '@stylistic/function-call-spacing': ['error', 'never'], // NOTE: Use prettier
// '@stylistic/generator-star-spacing': ['error', 'before'], // NOTE: Use prettier
// '@stylistic/key-spacing': ['error', { 'beforeColon': false, 'afterColon': true }], // NOTE: Use prettier
// '@stylistic/keyword-spacing': ['error', { 'before': true, 'after': true }], // NOTE: Use prettier
// '@stylistic/max-len': ['error', {'code': 140, 'ignoreComments': true}], // NOTE: Use prettier?
// '@stylistic/max-len': 'off', // NOTE: Use prettier?
// '@stylistic/new-parens': ['error', 'always'], // NOTE: Use prettier
// '@stylistic/no-extra-parens': ['error', 'functions'], // NOTE: Use prettier
// '@stylistic/no-extra-semi': 'error', // NOTE: Use prettier
// '@stylistic/no-floating-decimal': 'error', // NOTE: Use prettier
// '@stylistic/no-mixed-operators': ['error', {
// 'groups': [
// ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
// ['&&', '||'],
// ['in', 'instanceof'],
// ],
// 'allowSamePrecedence': true,
// }], // NOTE: Use prettier?
// '@stylistic/no-mixed-spaces-and-tabs': 'error', // NOTE: Use prettier
// '@stylistic/no-multi-spaces': 'error', // NOTE: Use prettier
// '@stylistic/no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 0 }], // NOTE: Use prettier
// '@stylistic/no-tabs': 'error', // NOTE: Use prettier?
// '@stylistic/no-trailing-spaces': 'error', // NOTE: Use prettier
// '@stylistic/no-whitespace-before-property': 'error', // NOTE: Use prettier
// '@stylistic/object-curly-spacing': ['error', 'always'], // NOTE: Use prettier
// '@stylistic/object-property-newline': ['error', { 'allowMultiplePropertiesPerLine': true }],
// '@stylistic/object-property-newline': 'off', // NOTE: Use prettier
// '@stylistic/operator-linebreak': ['error', 'after', { 'overrides': { '?': 'before', ':': 'before' } }], // NOTE: Use prettier
// '@stylistic/padded-blocks': ['error', { 'blocks': 'never', 'switches': 'never', 'classes': 'always' }], // TODO: Decide on a rule for 'classes'.
// '@stylistic/padded-blocks': ['error', { 'blocks': 'never', 'switches': 'never' }], // NOTE: Use prettier
// '@stylistic/rest-spread-spacing': ['error', 'never'], // NOTE: Use prettier
// '@stylistic/space-before-blocks': ['error', 'always'], // NOTE: Use prettier
// '@stylistic/space-before-function-paren': ['error', { 'anonymous': 'never', 'named': 'never', 'asyncArrow': 'always' }], // NOTE: Use prettier
// '@stylistic/space-in-parens': ['error', 'never'], // NOTE: Use prettier
// '@stylistic/space-infix-ops': 'error', // NOTE: Use prettier
// '@stylistic/space-unary-ops': ['error', { 'words': true, 'nonwords': false }], // NOTE: Use prettier
// '@stylistic/spaced-comment': ['error', 'always', {
// 'line': { 'markers': ['*package', '!', '/', ',', '='] },
// 'block': { 'balanced': true, 'markers': ['*package', '!', ',', ':', '::', 'flow-include'], 'exceptions': ['*'] }
// }],
'@stylistic/spaced-comment': 'off', // TODO: Consider enabling.
// '@stylistic/template-curly-spacing': 'off', // This missed an ending bracket that caused worse consistency, so disabling for now. // NOTE: Use prettier
// '@stylistic/template-tag-spacing': ['error', 'never'], // NOTE: Use prettier
// '@stylistic/wrap-iife': ['error', 'any', { 'functionPrototypeMethods': true }], // NOTE: Use prettier
// '@stylistic/yield-star-spacing': ['error', 'both'], // NOTE: Use prettier
// 'import/export': 'error',
// 'import/first': 'error',
// // 'import/no-duplicates': 'error', // VERY slow
// 'import/no-named-default': 'error',
// 'import/no-webpack-loader-syntax': 'error',
// // 'import/order': ['error', {
// // 'alphabetize': {
// // 'order': 'asc',
// // 'caseInsensitive': true
// // },
// // 'groups': [
// // 'builtin',
// // 'external',
// // 'internal',
// // 'parent',
// // 'sibling',
// // 'index'
// // ],
// // 'pathGroups': [
// // {
// // 'pattern': '@storybook/**',
// // 'group': 'external',
// // 'position': 'before'
// // },
// // {
// // 'pattern': '@angular/**',
// // 'group': 'external',
// // 'position': 'before'
// // },
// // {
// // 'pattern': 'rxjs',
// // 'group': 'external',
// // 'position': 'before'
// // },
// // {
// // 'pattern': 'rxjs/**',
// // 'group': 'external',
// // 'position': 'before'
// // },
// // {
// // 'pattern': '@lib/**',
// // 'group': 'internal',
// // 'position': 'before'
// // },
// // {
// // 'pattern': '@app/**',
// // 'group': 'internal',
// // 'position': 'before'
// // }
// // ],
// // 'pathGroupsExcludedImportTypes': ['builtin']
// // }],
// 'node/no-deprecated-api': 'error',
// 'node/process-exit-as-throw': 'error',
'promise/param-names': 'error',
'promise/always-return': 'off',
'promise/catch-or-return': 'off',
// 'standard/array-bracket-even-spacing': ['error', 'either'],
// 'standard/computed-property-even-spacing': ['error', 'even'],
// 'standard/no-callback-literal': 'error',
// 'standard/object-curly-even-spacing': ['error', 'either'],
// '@typescript-eslint/consistent-type-assertions': ['error', {'assertionStyle': 'as'}],
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/interface-name-prefix': [
'off',
{ prefixWithI: 'always' },
],
// '@typescript-eslint/member-ordering': ['error', {
// 'default': [
// 'public-static-field',
// 'public-static-method',
// 'protected-static-field',
// 'protected-static-method',
// 'private-static-field',
// 'private-static-method',
// 'public-instance-field',
// 'protected-instance-field',
// 'private-instance-field',
// 'constructor',
// 'public-instance-method',
// 'protected-instance-method',
// 'private-instance-method'
// ]
// }],
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-inferrable-types': [
'error',
{ ignoreParameters: true },
],
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTernary: true,
allowTaggedTemplates: true,
},
],
// '@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-for-of': 'off',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/triple-slash-reference': [
'error',
{ path: 'always', types: 'prefer-import' },
],
'@typescript-eslint/unified-signatures': 'error',
'@typescript-eslint/no-useless-constructor': 'error',
// '@typescript-eslint/no-unused-vars': ['error', { 'vars': 'all', 'args': 'none', 'ignoreRestSiblings': true }],
'@typescript-eslint/no-unused-vars': 'off',
// '@typescript-eslint/no-use-before-define': ['error', { 'classes': true, 'functions': false, 'variables': true }]
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off', // Undecided if we want to enforce this.
// 'n/handle-callback-err': [ 'error', '^(err|error)$' ],
'n/handle-callback-err': 'off', // TODO: Consider enabling
'n/no-new-require': 'error',
'n/no-path-concat': 'error',
'n/no-missing-import': 'off', // TODO: Check why this is giving a lot of false positives. Assumption: Because Typescript handles imports, this rule is not needed.
'n/no-extraneous-import': 'off', // This seems to check the closest package.json, which seems too restricted for our project.
'n/no-extraneous-require': 'off', // Slow and probably not worth the performance cost.
'n/no-unsupported-features/node-builtins': 'off', // Likely not relevant for our project.
'n/no-unpublished-import': 'off', // Very slow.
'@angular-eslint/prefer-inject': 'off', // TODO: Enable after more is migrated.
'@angular-eslint/prefer-standalone': 'off', // TODO: Enable after more is migrated.
},
},
// All Angular typescript files
{
files: ['{src,projects}/**/*.{ts,js,mjs}'],
ignores: ['**/*.spec.ts', '**/*.stories.ts'],
// IMPORTANT: Set the custom processor to enable inline template linting
// This allows your inline Component templates to be extracted and linted with the same
// rules as your external .html template files
processor: angular.processInlineTemplates,
rules: {
'@angular-eslint/no-empty-lifecycle-method': 'off', // TODO: Consider enabling
'@angular-eslint/no-inputs-metadata-property': 'off',
},
},
// App Angular files
{
files: ['src/**/*.{ts,js,mjs}'],
ignores: ['**/*.spec.ts', '**/*.stories.ts'],
rules: {
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'app',
style: 'camelCase',
},
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'app',
style: 'kebab-case',
},
],
},
},
// Lib angular files
{
files: ['projects/**/*.{ts,js,mjs}'],
ignores: ['**/*.spec.ts', '**/*.stories.ts'],
rules: {
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'seam',
style: 'camelCase',
},
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'seam',
style: 'kebab-case',
},
],
},
},
{
// Everything in this config object targets our HTML files (both external template files,
// AND inline templates thanks to the processor set in the TypeScript config above)
files: ['{src,projects,scripts,.storybook}/**/*.html'],
ignores: [
'src/index.html', // Ignore index.html since it's not an Angular template.
'src/index.prod.html',
],
extends: [
// Apply the recommended Angular template rules
...angular.configs.templateRecommended,
// Apply the Angular template rules which focus on accessibility of our apps
...angular.configs.templateAccessibility,
],
rules: {
'@typescript-eslint/ban-ts-comment': 'off', // Threw error on html file, which shouldn't need this rule anyway, as far as I know.
'@typescript-eslint/adjacent-overload-signatures': 'off', // Threw error on html file, which shouldn't need this rule anyway, as far as I know.
'@angular-eslint/template/no-negated-async': 'off', // TODO: Consider enabling. Currently, we have a lot of places that intentionally rely on the falsy logic that can't be auto fixed.
'@angular-eslint/template/click-events-have-key-events': 'off', // TODO: Consider enabling. Likely will not be a straighforward fix.
'@angular-eslint/template/label-has-associated-control': 'off', // TODO: Consider enabling. Likely will not be a straighforward fix.
'@angular-eslint/template/interactive-supports-focus': 'off', // TODO: Consider enabling. Likely will not be a straighforward fix.
'@angular-eslint/template/elements-content': 'off', // TODO: Consider enabling. May be too strict.
},
},
)