eslint-config-isaacscript 4.19.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,537 +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-for-of": "error",
196
- "@typescript-eslint/prefer-function-type": "error",
197
- "@typescript-eslint/prefer-includes": "error",
198
- "@typescript-eslint/prefer-literal-enum-member": "error",
199
- "@typescript-eslint/prefer-namespace-keyword": "error",
200
- "@typescript-eslint/prefer-nullish-coalescing": "error",
201
-
202
- /**
203
- * Disabled because it can modify the type of `boolean` declarations, which is [undesired in some
204
- * circumstances](https://github.com/typescript-eslint/typescript-eslint/issues/5269).
205
- */
206
- "@typescript-eslint/prefer-optional-chain": "off",
207
-
208
- "@typescript-eslint/prefer-readonly": "error",
209
-
210
- /** Superseded by the `isaacscript/prefer-readonly-parameter-types` rule. */
211
- "@typescript-eslint/prefer-readonly-parameter-types": "off",
212
-
213
- "@typescript-eslint/prefer-reduce-type-parameter": "error",
214
-
215
- /** Disabled since using the `String.match` form might make code easier to read. */
216
- "@typescript-eslint/prefer-regexp-exec": "off",
217
-
218
- "@typescript-eslint/prefer-return-this-type": "error",
219
- "@typescript-eslint/prefer-string-starts-ends-with": "error",
220
- "@typescript-eslint/prefer-ts-expect-error": "error",
221
- "@typescript-eslint/promise-function-async": "error",
222
- "@typescript-eslint/require-array-sort-compare": "error",
223
- "@typescript-eslint/restrict-plus-operands": "error",
224
-
225
- /** Disabled since a common use-case of template strings is to coerce everything to a string. */
226
- "@typescript-eslint/restrict-template-expressions": "off",
227
-
228
- /** Disabled since in it does not make sense to sort a union alphabetically in many cases. */
229
- "@typescript-eslint/sort-type-constituents": "off",
230
-
231
- /** The `allowString` and `allowNumber` options are disabled to make the rule stricter. */
232
- "@typescript-eslint/strict-boolean-expressions": [
233
- "error",
234
- {
235
- allowString: false,
236
- allowNumber: false,
237
- allowNullableObject: true,
238
- allowNullableBoolean: false,
239
- allowNullableString: false,
240
- allowNullableNumber: false,
241
- allowNullableEnum: false,
242
- allowAny: false,
243
- allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false,
244
- },
245
- ],
246
-
247
- /** The `allowDefaultCaseForExhaustiveSwitch` option is disabled to make the rule stricter. */
248
- "@typescript-eslint/switch-exhaustiveness-check": [
249
- "error",
250
- {
251
- allowDefaultCaseForExhaustiveSwitch: false,
252
- },
253
- ],
254
-
255
- "@typescript-eslint/triple-slash-reference": "error",
256
- "@typescript-eslint/type-annotation-spacing": "off", // eslint-config-prettier
257
-
258
- /**
259
- * Disabled since it is not recommended by the `typescript-eslint` team. (They recommend using the
260
- * `noImplicitAny` and `strictPropertyInitialization` TypeScript compiler options instead.)
261
- */
262
- "@typescript-eslint/typedef": "off",
263
-
264
- "@typescript-eslint/unbound-method": "error",
265
- "@typescript-eslint/unified-signatures": "error",
266
- };
267
-
268
- /** @type {import("eslint").Linter.RulesRecord} */
269
- const EXTENSION_RULES = {
270
- "@typescript-eslint/block-spacing": "off", // eslint-config-prettier
271
- "@typescript-eslint/brace-style": "off", // eslint-config-prettier
272
- "@typescript-eslint/class-methods-use-this": "error",
273
- "@typescript-eslint/comma-dangle": "off", // eslint-config-prettier
274
- "@typescript-eslint/comma-spacing": "off", // eslint-config-prettier
275
- "@typescript-eslint/default-param-last": "error",
276
- "@typescript-eslint/dot-notation": "error",
277
- "@typescript-eslint/func-call-spacing": "off", // eslint-config-prettier
278
- "@typescript-eslint/indent": "off", // eslint-config-prettier
279
-
280
- /**
281
- * Disabled since it is superfluous to require an `= undefined` during variable initialization
282
- * (and TypeScript will take care of the non-undefined cases).
283
- */
284
- "@typescript-eslint/init-declarations": "off",
285
-
286
- "@typescript-eslint/key-spacing": "off", // eslint-config-prettier
287
- "@typescript-eslint/keyword-spacing": "off", // eslint-config-prettier
288
-
289
- /**
290
- * Even though the `typescript-eslint` team does not recommend using formatting rules, this rule
291
- * is not handled by Prettier, so we must use ESLint to enforce it.
292
- */
293
- "@typescript-eslint/lines-around-comment": [
294
- "error",
295
- {
296
- // All of these properties default to false.
297
- allowBlockStart: true,
298
- allowObjectStart: true,
299
- allowArrayStart: true,
300
- allowClassStart: true,
301
- allowEnumStart: true,
302
- allowInterfaceStart: true,
303
- allowModuleStart: true,
304
- allowTypeStart: true,
305
- },
306
- ],
307
-
308
- /**
309
- * Even though the `typescript-eslint` team does not recommend using formatting rules, this rule
310
- * is not handled by Prettier, so we must use ESLint to enforce it.
311
- */
312
- "@typescript-eslint/lines-between-class-members": [
313
- "error",
314
- "always",
315
- {
316
- exceptAfterSingleLine: true,
317
- },
318
- ],
319
-
320
- "@typescript-eslint/no-array-constructor": "error",
321
-
322
- /**
323
- * Disabled since it is superfluous when using TypeScript according to [the ESLint
324
- * documentation](https://eslint.org/docs/latest/rules/no-dupe-class-members#when-not-to-use-it).
325
- */
326
- "@typescript-eslint/no-dupe-class-members": "off",
327
-
328
- "@typescript-eslint/no-empty-function": "error",
329
- "@typescript-eslint/no-extra-parens": "off", // eslint-config-prettier
330
- "@typescript-eslint/no-extra-semi": "off", // eslint-config-prettier
331
- "@typescript-eslint/no-implied-eval": "error",
332
-
333
- /** The `capIsConstructor` option is disabled to make the rule stricter. */
334
- "@typescript-eslint/no-invalid-this": [
335
- "error",
336
- {
337
- capIsConstructor: false,
338
- },
339
- ],
340
-
341
- "@typescript-eslint/no-loop-func": "error",
342
- "@typescript-eslint/no-loss-of-precision": "error",
343
-
344
- /** Disabled since it results in too many false positives. */
345
- "@typescript-eslint/no-magic-numbers": "off",
346
-
347
- /**
348
- * Disabled since it is handled by the combination of the TypeScript compiler and the `no-var`
349
- * ESLint rule.
350
- */
351
- "@typescript-eslint/no-redeclare": "off",
352
-
353
- /**
354
- * Configured to prevent importing with some common patterns that are almost always a mistake:
355
- *
356
- * - "src" directories (but allowed in test files that are in a separate "tests" directory)
357
- * - "dist" directories
358
- * - "index" files (things in the same package should directly import instead of use the public
359
- * API)
360
- */
361
- "@typescript-eslint/no-restricted-imports": [
362
- "error",
363
- {
364
- patterns: [
365
- // Some "src" directories have an "index.ts" file, which means that importing from the
366
- // directory is valid. Thus, we check for the "src" directory with no suffix.
367
- {
368
- group: ["**/src"],
369
- message:
370
- '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.',
371
- },
372
-
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
- // Some "dist" directories have an "index.ts" file, which means that importing from the
380
- // directory is valid. Thus, we check for the "dist" directory with no suffix.
381
- {
382
- group: ["**/dist"],
383
- message:
384
- '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.',
385
- },
386
-
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: ["**/index"],
395
- message:
396
- "You cannot import from a package index. Instead, import directly from the file where the code is located.",
397
- },
398
-
399
- {
400
- group: ["**/index.{js,cjs,mjs,ts,cts,mts}"],
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
- ],
407
-
408
- "@typescript-eslint/no-shadow": "error",
409
- "@typescript-eslint/no-throw-literal": "error",
410
-
411
- /**
412
- * The `allowTaggedTemplates` option is enabled to allow the rule to work with libraries like
413
- * `execa`.
414
- */
415
- "@typescript-eslint/no-unused-expressions": [
416
- "error",
417
- {
418
- allowTaggedTemplates: true,
419
- },
420
- ],
421
-
422
- /**
423
- * The `args` option is set to `all` make the rule stricter. Additionally, we ignore things that
424
- * begin with an underscore, since this matches the behavior of the `--noUnusedLocals` TypeScript
425
- * compiler flag.
426
- */
427
- "@typescript-eslint/no-unused-vars": [
428
- "error",
429
- {
430
- args: "all", // "after-used" is the default.
431
- argsIgnorePattern: "^_",
432
- varsIgnorePattern: "^_",
433
- },
434
- ],
435
-
436
- /** Disabled because it can prevent code from being structured sequentially. */
437
- "@typescript-eslint/no-use-before-define": "off",
438
-
439
- "@typescript-eslint/no-useless-constructor": "error",
440
- "@typescript-eslint/object-curly-spacing": "off", // eslint-config-prettier
441
-
442
- /**
443
- * Disabled since it is for inserting extra newlines between specific kinds of statements, which
444
- * would be project-dependant. (This kind of formatting is not handled by Prettier.)
445
- */
446
- "@typescript-eslint/padding-line-between-statements": "off",
447
-
448
- /**
449
- * We forbid unnecessary backticks by using the options specified in [the `eslint-config-prettier`
450
- * documentation](https://github.com/prettier/eslint-config-prettier#enforce-backticks).
451
- */
452
- "@typescript-eslint/quotes": [
453
- "error",
454
- "double",
455
- {
456
- avoidEscape: true,
457
- allowTemplateLiterals: false,
458
- },
459
- ],
460
-
461
- "@typescript-eslint/require-await": "error",
462
-
463
- /**
464
- * Even though the core rule was deprecated, the extended rule uses type information, so it is
465
- * much better.
466
- */
467
- "@typescript-eslint/return-await": "error",
468
-
469
- "@typescript-eslint/semi": "off", // eslint-config-prettier
470
- "@typescript-eslint/space-before-blocks": "off", // eslint-config-prettier
471
- "@typescript-eslint/space-before-function-paren": "off", // eslint-config-prettier
472
- "@typescript-eslint/space-infix-ops": "off", // eslint-config-prettier
473
- };
474
-
475
- /** @type {import("eslint").Linter.Config} */
476
- const config = {
477
- // We need to provide some special configuration to ESLint in order for it to parse TypeScript
478
- // files. From:
479
- // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/base.ts
480
- parser: "@typescript-eslint/parser",
481
- parserOptions: {
482
- sourceType: "module",
483
-
484
- // Needed for `eslint-plugin-import` to work properly:
485
- // https://github.com/import-js/eslint-plugin-import/blob/main/config/recommended.js
486
- ecmaVersion: "latest",
487
- },
488
- plugins: ["@typescript-eslint"],
489
-
490
- rules: {
491
- ...SUPPORTED_RULES,
492
- ...EXTENSION_RULES,
493
- },
494
-
495
- overrides: [
496
- // We list a "blank" override for the purposes of enabling new file extensions. (ESLint adds any
497
- // new extensions included in `overrides` to the list of linted extensions.)
498
- {
499
- files: ["*.ts", "*.tsx", "*.mts", "*.cts"],
500
- },
501
-
502
- // Disable some TypeScript-specific rules in JavaScript files.
503
- {
504
- files: ["*.js", "*.cjs", "*.mjs", "*.jsx"],
505
- rules: {
506
- "@typescript-eslint/explicit-module-boundary-types": "off",
507
- "@typescript-eslint/no-require-imports": "off",
508
- "@typescript-eslint/no-unsafe-argument": "off",
509
- "@typescript-eslint/no-unsafe-assignment": "off",
510
- "@typescript-eslint/no-unsafe-call": "off",
511
- "@typescript-eslint/no-unsafe-member-access": "off",
512
- "@typescript-eslint/no-unsafe-return": "off",
513
- "@typescript-eslint/no-var-requires": "off",
514
- "@typescript-eslint/strict-boolean-expressions": "off",
515
- },
516
- },
517
-
518
- // The built-in Node.js test-runner returns a promise which is not meant to be awaited.
519
- {
520
- files: ["*.test.{js,cjs,mjs,ts,cts,mts}"],
521
- rules: {
522
- "@typescript-eslint/no-floating-promises": "off",
523
- },
524
- },
525
-
526
- // We want to be allowed to import from the "src" directory in test files that are located in a
527
- // separate "tests" directory.
528
- {
529
- files: ["**/tests/**"],
530
- rules: {
531
- "@typescript-eslint/no-restricted-imports": "off",
532
- },
533
- },
534
- ],
535
- };
536
-
537
- module.exports = config;