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