eslint-config-complete 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,553 @@
1
+ import tseslint from "typescript-eslint";
2
+
3
+ /**
4
+ * This ESLint config only contains rules from `@typescript-eslint/eslint-plugin`:
5
+ * https://typescript-eslint.io/rules/
6
+ */
7
+ export const baseTypeScriptESLint = tseslint.config(
8
+ {
9
+ plugins: {
10
+ "@typescript-eslint": tseslint.plugin,
11
+ },
12
+
13
+ // We need to provide some special configuration to ESLint in order for it to parse TypeScript
14
+ // files. From:
15
+ // https://typescript-eslint.io/packages/typescript-eslint/#advanced-usage
16
+ languageOptions: {
17
+ parser: tseslint.parser,
18
+ parserOptions: {
19
+ projectService: {
20
+ // We whitelist some specific configuration files that downstream users may have in their
21
+ // projects. These files should be linted but should not be included in compiled output.
22
+ allowDefaultProject: [
23
+ "babel.config.js",
24
+ "babel.config.cjs",
25
+ "babel.config.mjs",
26
+ "eslint.config.js",
27
+ "eslint.config.cjs",
28
+ "eslint.config.mjs",
29
+ "jest.config.js",
30
+ "jest.config.cjs",
31
+ "jest.config.mjs",
32
+ "knip.js",
33
+ "knip.ts",
34
+ "knip.config.js",
35
+ "knip.config.ts",
36
+ "prettier.config.js",
37
+ "prettier.config.cjs",
38
+ "prettier.config.mjs",
39
+ "typedoc.config.js",
40
+ "typedoc.config.cjs",
41
+ "typedoc.config.mjs",
42
+ ],
43
+
44
+ // By default, the whitelisted files above will use the default TypeScript compiler
45
+ // options. However, certain ESLint rules such as
46
+ // "@typescript-eslint/no-unnecessary-condition" and
47
+ // "@typescript-eslint/prefer-nullish-coalescing" require "strictNullChecks", which is not
48
+ // a default option. Thus, we need to specify that whitelisted files should use the
49
+ // "tsconfig.json" file that is beside the file in the same directory.
50
+ defaultProject: "tsconfig.json",
51
+ },
52
+ },
53
+ },
54
+
55
+ rules: {
56
+ "@typescript-eslint/adjacent-overload-signatures": "warn",
57
+
58
+ /**
59
+ * The default value is `array`. We choose `array-simple` because it makes complicated arrays
60
+ * easier to understand. This is worth the cost of deviating from the base rule configuration.
61
+ */
62
+ "@typescript-eslint/array-type": [
63
+ "warn",
64
+ {
65
+ default: "array-simple",
66
+ },
67
+ ],
68
+
69
+ "@typescript-eslint/await-thenable": "warn",
70
+ "@typescript-eslint/ban-ts-comment": "warn",
71
+ "@typescript-eslint/ban-tslint-comment": "warn",
72
+ "@typescript-eslint/class-literal-property-style": "warn",
73
+ "@typescript-eslint/consistent-generic-constructors": "warn",
74
+ "@typescript-eslint/consistent-indexed-object-style": "warn",
75
+ "@typescript-eslint/consistent-type-assertions": "warn",
76
+ "@typescript-eslint/consistent-type-definitions": "warn",
77
+ "@typescript-eslint/consistent-type-exports": "warn",
78
+ "@typescript-eslint/consistent-type-imports": "warn",
79
+
80
+ /**
81
+ * Disabled since it would be to cumbersome to require return types for non-exported
82
+ * functions. (It is more reasonable to require it for exported functions only, since it
83
+ * speeds up the type-checker in large codebases.)
84
+ */
85
+ "@typescript-eslint/explicit-function-return-type": "off",
86
+
87
+ /**
88
+ * Disabled since many programs may have internal-only classes that would not benefit from an
89
+ * explicit public/private distinction.
90
+ */
91
+ "@typescript-eslint/explicit-member-accessibility": "off",
92
+
93
+ "@typescript-eslint/explicit-module-boundary-types": "warn",
94
+
95
+ /**
96
+ * Disabled because enforcing an arbitrary parameter number threshold for every function in a
97
+ * project does not provide much value. (Additionally, using TypeScript reduces the value of
98
+ * such a check.)
99
+ */
100
+ "@typescript-eslint/max-params": "off",
101
+
102
+ "@typescript-eslint/member-delimiter-style": "off", // eslint-config-prettier
103
+
104
+ /** Disabled since prescribed class ordering is too project-specific. */
105
+ "@typescript-eslint/member-ordering": "off",
106
+
107
+ "@typescript-eslint/method-signature-style": "warn",
108
+
109
+ /**
110
+ * The options are [copied from
111
+ * Airbnb](https://github.com/iamturns/eslint-config-airbnb-typescript/blob/master/lib/shared.js).
112
+ * We also allow a leading underscore, which signifies that the element is temporarily not
113
+ * being used.
114
+ */
115
+ "@typescript-eslint/naming-convention": [
116
+ "warn",
117
+ // Allow camelCase variables (23.2), PascalCase variables (23.8), and UPPER_CASE variables
118
+ // (23.10).
119
+ {
120
+ selector: "variable",
121
+ format: ["camelCase", "PascalCase", "UPPER_CASE"],
122
+ leadingUnderscore: "allow",
123
+ },
124
+ // Allow camelCase functions (23.2), and PascalCase functions (23.8).
125
+ {
126
+ selector: "function",
127
+ format: ["camelCase", "PascalCase"],
128
+ leadingUnderscore: "allow",
129
+ },
130
+ // Airbnb recommends PascalCase for classes (23.3), and although Airbnb does not make
131
+ // TypeScript recommendations, we are assuming this rule would similarly apply to anything
132
+ // "type like", including interfaces, type aliases, and enums.
133
+ {
134
+ selector: "typeLike",
135
+ format: ["PascalCase"],
136
+ leadingUnderscore: "allow",
137
+ },
138
+ ],
139
+
140
+ "@typescript-eslint/no-base-to-string": "warn",
141
+ "@typescript-eslint/no-confusing-non-null-assertion": "warn",
142
+ "@typescript-eslint/no-confusing-void-expression": "warn",
143
+ "@typescript-eslint/no-duplicate-enum-values": "warn",
144
+ "@typescript-eslint/no-duplicate-type-constituents": "warn",
145
+ "@typescript-eslint/no-dynamic-delete": "warn",
146
+
147
+ /**
148
+ * The `allowSingleExtends` option is enabled to allow for the common pattern of using using
149
+ * interfaces to provide an opaque type. (This can be useful with type-builders such as Zod,
150
+ * since `z.infer` uses `Expand`, which is sometimes not desired since it can lead to
151
+ * verbose/confusing mouseover tooltips and TypeScript errors.)
152
+ */
153
+ "@typescript-eslint/no-empty-interface": [
154
+ "warn",
155
+ {
156
+ allowSingleExtends: true,
157
+ },
158
+ ],
159
+
160
+ "@typescript-eslint/no-empty-object-type": "warn",
161
+ "@typescript-eslint/no-explicit-any": "warn",
162
+ "@typescript-eslint/no-extra-non-null-assertion": "warn",
163
+ "@typescript-eslint/no-extraneous-class": "warn",
164
+
165
+ /**
166
+ * - The `ignoreVoid` option is disabled to make the rule stricter.
167
+ * - The rule is disabled in "*.test.ts" files because the built-in Node test runner returns a
168
+ * promise that is not meant to be awaited.
169
+ */
170
+ "@typescript-eslint/no-floating-promises": [
171
+ "warn",
172
+ {
173
+ ignoreVoid: false,
174
+ },
175
+ ],
176
+
177
+ "@typescript-eslint/no-for-in-array": "warn",
178
+ "@typescript-eslint/no-import-type-side-effects": "warn",
179
+ "@typescript-eslint/no-inferrable-types": "warn",
180
+ "@typescript-eslint/no-invalid-void-type": "warn",
181
+ "@typescript-eslint/no-meaningless-void-operator": "warn",
182
+ "@typescript-eslint/no-misused-new": "warn",
183
+ "@typescript-eslint/no-misused-promises": "warn",
184
+ "@typescript-eslint/no-mixed-enums": "warn",
185
+ "@typescript-eslint/no-namespace": "warn",
186
+ "@typescript-eslint/no-non-null-asserted-nullish-coalescing": "warn",
187
+ "@typescript-eslint/no-non-null-asserted-optional-chain": "warn",
188
+ "@typescript-eslint/no-non-null-assertion": "warn",
189
+ "@typescript-eslint/no-redundant-type-constituents": "warn",
190
+ "@typescript-eslint/no-require-imports": "warn",
191
+
192
+ /** Disabled since this rule is intended to be used for project-specific types. */
193
+ "@typescript-eslint/no-restricted-types": "off",
194
+
195
+ "@typescript-eslint/no-this-alias": "warn",
196
+
197
+ /** Disabled because this rule is deprecated. */
198
+ "@typescript-eslint/no-type-alias": "off",
199
+
200
+ "@typescript-eslint/no-unnecessary-boolean-literal-compare": "warn",
201
+ "@typescript-eslint/no-unnecessary-condition": "warn",
202
+ "@typescript-eslint/no-unnecessary-parameter-property-assignment": "warn",
203
+ "@typescript-eslint/no-unnecessary-qualifier": "warn",
204
+ "@typescript-eslint/no-unnecessary-template-expression": "warn",
205
+ "@typescript-eslint/no-unnecessary-type-arguments": "warn",
206
+ "@typescript-eslint/no-unnecessary-type-assertion": "warn",
207
+ "@typescript-eslint/no-unnecessary-type-constraint": "warn",
208
+ "@typescript-eslint/no-unnecessary-type-parameters": "warn",
209
+ "@typescript-eslint/no-unsafe-argument": "warn",
210
+ "@typescript-eslint/no-unsafe-assignment": "warn",
211
+ "@typescript-eslint/no-unsafe-call": "warn",
212
+ "@typescript-eslint/no-unsafe-declaration-merging": "warn",
213
+ "@typescript-eslint/no-unsafe-enum-comparison": "warn",
214
+ "@typescript-eslint/no-unsafe-function-type": "warn",
215
+ "@typescript-eslint/no-unsafe-member-access": "warn",
216
+ "@typescript-eslint/no-unsafe-return": "warn",
217
+ "@typescript-eslint/no-unsafe-unary-minus": "warn",
218
+ "@typescript-eslint/no-useless-empty-export": "warn",
219
+ "@typescript-eslint/no-var-requires": "warn",
220
+ "@typescript-eslint/no-wrapper-object-types": "warn",
221
+ "@typescript-eslint/non-nullable-type-assertion-style": "warn",
222
+ "@typescript-eslint/only-throw-error": "warn",
223
+ "@typescript-eslint/parameter-properties": "warn",
224
+ "@typescript-eslint/prefer-as-const": "warn",
225
+
226
+ /**
227
+ * Object destructuring is enforced but array destructuring is not. This matches usage in the
228
+ * general TypeScript ecosystem.
229
+ */
230
+ "@typescript-eslint/prefer-destructuring": [
231
+ "warn",
232
+ {
233
+ VariableDeclarator: {
234
+ array: false,
235
+ object: true,
236
+ },
237
+ AssignmentExpression: {
238
+ array: false,
239
+ object: true,
240
+ },
241
+ },
242
+ {
243
+ // We disable this for renamed properties, since code like the following should be valid:
244
+ // `const someSpecificMyEnum = MyEnum.Value1;`
245
+ enforceForRenamedProperties: false,
246
+ },
247
+ ],
248
+
249
+ "@typescript-eslint/prefer-enum-initializers": "warn",
250
+ "@typescript-eslint/prefer-find": "warn",
251
+ "@typescript-eslint/prefer-for-of": "warn",
252
+ "@typescript-eslint/prefer-function-type": "warn",
253
+ "@typescript-eslint/prefer-includes": "warn",
254
+ "@typescript-eslint/prefer-literal-enum-member": "warn",
255
+ "@typescript-eslint/prefer-namespace-keyword": "warn",
256
+ "@typescript-eslint/prefer-nullish-coalescing": "warn",
257
+
258
+ /**
259
+ * Disabled because it can modify the type of `boolean` declarations, which is [undesired in
260
+ * some
261
+ * circumstances](https://github.com/typescript-eslint/typescript-eslint/issues/5269).
262
+ */
263
+ "@typescript-eslint/prefer-optional-chain": "off",
264
+
265
+ "@typescript-eslint/prefer-readonly": "warn",
266
+
267
+ /** Superseded by the `complete/prefer-readonly-parameter-types` rule. */
268
+ "@typescript-eslint/prefer-readonly-parameter-types": "off",
269
+
270
+ "@typescript-eslint/prefer-reduce-type-parameter": "warn",
271
+
272
+ /** Disabled since using the `String.match` form might make code easier to read. */
273
+ "@typescript-eslint/prefer-regexp-exec": "off",
274
+
275
+ "@typescript-eslint/prefer-return-this-type": "warn",
276
+ "@typescript-eslint/prefer-string-starts-ends-with": "warn",
277
+ "@typescript-eslint/prefer-ts-expect-error": "warn",
278
+ "@typescript-eslint/promise-function-async": "warn",
279
+ "@typescript-eslint/require-array-sort-compare": "warn",
280
+
281
+ /** The various "allow" options are disabled to make the rule stricter. */
282
+ "@typescript-eslint/restrict-plus-operands": [
283
+ "warn",
284
+ {
285
+ allowAny: false,
286
+ allowBoolean: false,
287
+ allowNullish: false,
288
+ allowNumberAndString: false,
289
+ allowRegExp: false,
290
+ },
291
+ ],
292
+
293
+ /**
294
+ * Disabled since a common use-case of template strings is to coerce everything to a string.
295
+ */
296
+ "@typescript-eslint/restrict-template-expressions": "off",
297
+
298
+ /** Disabled since in it does not make sense to sort a union alphabetically in many cases. */
299
+ "@typescript-eslint/sort-type-constituents": "off",
300
+
301
+ /** The `allowString` and `allowNumber` options are disabled to make the rule stricter. */
302
+ "@typescript-eslint/strict-boolean-expressions": [
303
+ "warn",
304
+ {
305
+ allowString: false,
306
+ allowNumber: false,
307
+ allowNullableObject: true,
308
+ allowNullableBoolean: false,
309
+ allowNullableString: false,
310
+ allowNullableNumber: false,
311
+ allowNullableEnum: false,
312
+ allowAny: false,
313
+ allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false,
314
+ },
315
+ ],
316
+
317
+ /**
318
+ * The `allowDefaultCaseForExhaustiveSwitch` option is disabled and the
319
+ * `requireDefaultForNonUnion` option is enabled to make the rule stricter.
320
+ */
321
+ "@typescript-eslint/switch-exhaustiveness-check": [
322
+ "warn",
323
+ {
324
+ allowDefaultCaseForExhaustiveSwitch: false,
325
+ requireDefaultForNonUnion: true,
326
+ },
327
+ ],
328
+
329
+ "@typescript-eslint/triple-slash-reference": "warn",
330
+ "@typescript-eslint/type-annotation-spacing": "off", // eslint-config-prettier
331
+
332
+ /**
333
+ * Disabled since it is not recommended by the `typescript-eslint` team. (They recommend using
334
+ * the `noImplicitAny` and `strictPropertyInitialization` TypeScript compiler options
335
+ * instead.)
336
+ */
337
+ "@typescript-eslint/typedef": "off",
338
+
339
+ "@typescript-eslint/unbound-method": "warn",
340
+ "@typescript-eslint/unified-signatures": "warn",
341
+ "@typescript-eslint/use-unknown-in-catch-callback-variable": "warn",
342
+
343
+ "@typescript-eslint/block-spacing": "off", // eslint-config-prettier
344
+ "@typescript-eslint/brace-style": "off", // eslint-config-prettier
345
+ "@typescript-eslint/class-methods-use-this": "warn",
346
+ "@typescript-eslint/comma-dangle": "off", // eslint-config-prettier
347
+ "@typescript-eslint/comma-spacing": "off", // eslint-config-prettier
348
+
349
+ /** Disabled since this is handled by the `noImplicitReturns` TypeScript compiler flag. */
350
+ "@typescript-eslint/consistent-return": "off",
351
+
352
+ "@typescript-eslint/default-param-last": "warn",
353
+ "@typescript-eslint/dot-notation": "warn",
354
+ "@typescript-eslint/func-call-spacing": "off", // eslint-config-prettier
355
+ "@typescript-eslint/indent": "off", // eslint-config-prettier
356
+
357
+ /**
358
+ * Disabled since it is superfluous to require an `= undefined` during variable initialization
359
+ * (and TypeScript will take care of the non-undefined cases).
360
+ */
361
+ "@typescript-eslint/init-declarations": "off",
362
+
363
+ "@typescript-eslint/key-spacing": "off", // eslint-config-prettier
364
+ "@typescript-eslint/keyword-spacing": "off", // eslint-config-prettier
365
+ "@typescript-eslint/no-array-constructor": "warn",
366
+ "@typescript-eslint/no-array-delete": "warn",
367
+
368
+ /**
369
+ * Disabled since it is superfluous when using TypeScript according to [the ESLint
370
+ * documentation](https://eslint.org/docs/latest/rules/no-dupe-class-members#when-not-to-use-it).
371
+ */
372
+ "@typescript-eslint/no-dupe-class-members": "off",
373
+
374
+ "@typescript-eslint/no-empty-function": "warn",
375
+ "@typescript-eslint/no-extra-parens": "off", // eslint-config-prettier
376
+ "@typescript-eslint/no-extra-semi": "off", // eslint-config-prettier
377
+ "@typescript-eslint/no-implied-eval": "warn",
378
+
379
+ /** The `capIsConstructor` option is disabled to make the rule stricter. */
380
+ "@typescript-eslint/no-invalid-this": [
381
+ "warn",
382
+ {
383
+ capIsConstructor: false,
384
+ },
385
+ ],
386
+
387
+ "@typescript-eslint/no-loop-func": "warn",
388
+ "@typescript-eslint/no-loss-of-precision": "warn",
389
+
390
+ /** Disabled since it results in too many false positives. */
391
+ "@typescript-eslint/no-magic-numbers": "off",
392
+
393
+ /**
394
+ * Disabled since it is handled by the combination of the TypeScript compiler and the `no-var`
395
+ * ESLint rule.
396
+ */
397
+ "@typescript-eslint/no-redeclare": "off",
398
+
399
+ /**
400
+ * Configured to prevent importing with some common patterns that are almost always a mistake:
401
+ *
402
+ * - "src" directories (but allowed in test files that are in a separate "tests" directory)
403
+ * - "dist" directories
404
+ * - "index" files (things in the same package should directly import instead of use the
405
+ * public API)
406
+ */
407
+ "@typescript-eslint/no-restricted-imports": [
408
+ "warn",
409
+ {
410
+ patterns: [
411
+ // Some "src" directories have an "index.ts" file, which means that importing from the
412
+ // directory is valid. Thus, we check for the "src" directory with no suffix.
413
+ {
414
+ group: ["**/src"],
415
+ message:
416
+ 'You cannot import from a "src" directory. If this is a monorepo, import using the package name like you would in a non-monorepo project.',
417
+ },
418
+
419
+ {
420
+ group: ["**/src/**"],
421
+ message:
422
+ 'You cannot import from a "src" directory. If this is a monorepo, import using the package name like you would in a non-monorepo project.',
423
+ },
424
+
425
+ // Some "dist" directories have an "index.ts" file, which means that importing from the
426
+ // directory is valid. Thus, we check for the "dist" directory with no suffix.
427
+ {
428
+ group: ["**/dist"],
429
+ message:
430
+ 'You cannot import from a "dist" directory. If this is a monorepo, import using the package name like you would in a non-monorepo project.',
431
+ },
432
+
433
+ {
434
+ group: ["**/dist/**"],
435
+ message:
436
+ 'You cannot import from a "dist" directory. If this is a monorepo, import using the package name like you would in a non-monorepo project.',
437
+ },
438
+
439
+ {
440
+ group: ["**/index"],
441
+ message:
442
+ "You cannot import from a package index. Instead, import directly from the file where the code is located.",
443
+ },
444
+
445
+ {
446
+ group: ["**/index.{js,cjs,mjs,ts,cts,mts}"],
447
+ message:
448
+ "You cannot import from a package index. Instead, import directly from the file where the code is located.",
449
+ },
450
+ ],
451
+ },
452
+ ],
453
+
454
+ "@typescript-eslint/no-shadow": "warn",
455
+
456
+ /**
457
+ * The `allowTaggedTemplates` option is enabled to allow the rule to work with libraries like
458
+ * `execa`.
459
+ */
460
+ "@typescript-eslint/no-unused-expressions": [
461
+ "warn",
462
+ {
463
+ allowTaggedTemplates: true,
464
+ },
465
+ ],
466
+
467
+ /**
468
+ * The `args` option is set to `all` make the rule stricter. Additionally, we ignore things
469
+ * that begin with an underscore, since this matches the behavior of the `--noUnusedLocals`
470
+ * TypeScript compiler flag.
471
+ */
472
+ "@typescript-eslint/no-unused-vars": [
473
+ "warn",
474
+ {
475
+ args: "all", // "after-used" is the default.
476
+ argsIgnorePattern: "^_",
477
+ varsIgnorePattern: "^_",
478
+ },
479
+ ],
480
+
481
+ /** Disabled because it can prevent code from being structured sequentially. */
482
+ "@typescript-eslint/no-use-before-define": "off",
483
+
484
+ "@typescript-eslint/no-useless-constructor": "warn",
485
+ "@typescript-eslint/object-curly-spacing": "off", // eslint-config-prettier
486
+
487
+ /**
488
+ * Disabled since it is for inserting extra newlines between specific kinds of statements,
489
+ * which would be project-dependant. (This kind of formatting is not handled by Prettier.)
490
+ */
491
+ "@typescript-eslint/padding-line-between-statements": "off",
492
+
493
+ /** The `allowEmptyReject` option is enabled since this is a common pattern. */
494
+ "@typescript-eslint/prefer-promise-reject-errors": [
495
+ "warn",
496
+ {
497
+ allowEmptyReject: true,
498
+ },
499
+ ],
500
+
501
+ "@typescript-eslint/require-await": "warn",
502
+
503
+ /**
504
+ * Even though the core rule was deprecated, the extended rule uses type information, so it is
505
+ * much better.
506
+ */
507
+ "@typescript-eslint/return-await": "warn",
508
+
509
+ "@typescript-eslint/semi": "off", // eslint-config-prettier
510
+ "@typescript-eslint/space-before-blocks": "off", // eslint-config-prettier
511
+ "@typescript-eslint/space-before-function-paren": "off", // eslint-config-prettier
512
+ "@typescript-eslint/space-infix-ops": "off", // eslint-config-prettier
513
+ },
514
+ },
515
+
516
+ // Enable linting on TypeScript file extensions.
517
+ {
518
+ files: ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
519
+ },
520
+
521
+ // Disable some TypeScript-specific rules in JavaScript files.
522
+ {
523
+ files: ["**/*.js", "**/*.cjs", "**/*.mjs", "**/*.jsx"],
524
+ rules: {
525
+ "@typescript-eslint/explicit-module-boundary-types": "off",
526
+ "@typescript-eslint/no-require-imports": "off",
527
+ "@typescript-eslint/no-unsafe-argument": "off",
528
+ "@typescript-eslint/no-unsafe-assignment": "off",
529
+ "@typescript-eslint/no-unsafe-call": "off",
530
+ "@typescript-eslint/no-unsafe-member-access": "off",
531
+ "@typescript-eslint/no-unsafe-return": "off",
532
+ "@typescript-eslint/no-var-requires": "off",
533
+ "@typescript-eslint/strict-boolean-expressions": "off",
534
+ },
535
+ },
536
+
537
+ // The built-in Node.js test-runner returns a promise which is not meant to be awaited.
538
+ {
539
+ files: ["**/*.test.{js,cjs,mjs,ts,cts,mts}"],
540
+ rules: {
541
+ "@typescript-eslint/no-floating-promises": "off",
542
+ },
543
+ },
544
+
545
+ // We want to be allowed to import from the "src" directory in test files that are located in a
546
+ // separate "tests" directory.
547
+ {
548
+ files: ["**/tests/**"],
549
+ rules: {
550
+ "@typescript-eslint/no-restricted-imports": "off",
551
+ },
552
+ },
553
+ );