|
1 | | -import tsEslintPlugin from "@typescript-eslint/eslint-plugin"; |
2 | | -import tsEslintParser from "@typescript-eslint/parser"; |
| 1 | +import type { Linter } from "eslint"; |
| 2 | +import tsEslint from "typescript-eslint"; |
3 | 3 | import { merge } from "../merge.js"; |
4 | | -import { nonNull } from "../utils.js"; |
5 | 4 | import { moduleBase } from "./module-base.js"; |
6 | 5 |
|
7 | | -const tsEsEslintRecomRules = nonNull( |
8 | | - nonNull(tsEslintPlugin.configs["eslint-recommended"].overrides)[0].rules, |
9 | | -); |
10 | | - |
11 | | -export const typescript = merge(moduleBase, { |
12 | | - files: ["**/*.{ts,tsx,mts,cts}"], |
13 | | - languageOptions: { |
14 | | - ecmaVersion: "latest", |
15 | | - sourceType: "module", |
16 | | - // @ts-expect-error TSESLint doesn't support flat config typings yet |
17 | | - parser: tsEslintParser, |
18 | | - }, |
19 | | - plugins: { |
20 | | - // @ts-expect-error TSESLint doesn't support flat config typings yet |
21 | | - "@typescript-eslint": tsEslintPlugin, |
22 | | - }, |
23 | | - rules: { |
24 | | - ...tsEsEslintRecomRules, |
25 | | - ...tsEslintPlugin.configs.recommended.rules, |
| 6 | +export const typescript = merge( |
| 7 | + moduleBase, |
| 8 | + ...(tsEslint.configs.recommended as Linter.FlatConfig[]), |
| 9 | + { |
| 10 | + files: ["**/*.{ts,tsx,mts,cts}"], |
| 11 | + languageOptions: { |
| 12 | + ecmaVersion: "latest", |
| 13 | + }, |
| 14 | + rules: { |
| 15 | + // Allow special triple slashes comment: "/// <reference />" |
| 16 | + "spaced-comment": [ |
| 17 | + 2, |
| 18 | + "always", |
| 19 | + { line: { markers: ["/"] }, block: { balanced: true } }, |
| 20 | + ], |
26 | 21 |
|
27 | | - // Allow special triple slashes comment: "/// <reference />" |
28 | | - "spaced-comment": [ |
29 | | - 2, |
30 | | - "always", |
31 | | - { line: { markers: ["/"] }, block: { balanced: true } }, |
32 | | - ], |
| 22 | + // Check with TSC instead |
| 23 | + "n/no-missing-import": 0, |
33 | 24 |
|
34 | | - // Check with TSC instead |
35 | | - "n/no-missing-import": 0, |
| 25 | + // Extend ESLint rules (enabled in base config) |
| 26 | + // NOTE: skip extending stylistic rules that are overrided by prettier |
| 27 | + "no-invalid-this": 0, |
| 28 | + "@typescript-eslint/no-invalid-this": 2, |
| 29 | + "no-loop-func": 0, |
| 30 | + "@typescript-eslint/no-loop-func": 2, |
| 31 | + "no-unused-expressions": 0, |
| 32 | + "@typescript-eslint/no-unused-expressions": [ |
| 33 | + 2, |
| 34 | + { |
| 35 | + allowShortCircuit: true, |
| 36 | + allowTernary: true, |
| 37 | + allowTaggedTemplates: true, |
| 38 | + }, |
| 39 | + ], |
36 | 40 |
|
37 | | - // Extend ESLint rules (enabled in base config) |
38 | | - // NOTE: skip extending stylistic rules that are overrided by prettier |
39 | | - "no-invalid-this": 0, |
40 | | - "@typescript-eslint/no-invalid-this": 2, |
41 | | - "no-loop-func": 0, |
42 | | - "@typescript-eslint/no-loop-func": 2, |
43 | | - "no-unused-expressions": 0, |
44 | | - "@typescript-eslint/no-unused-expressions": [ |
45 | | - 2, |
46 | | - { |
47 | | - allowShortCircuit: true, |
48 | | - allowTernary: true, |
49 | | - allowTaggedTemplates: true, |
50 | | - }, |
51 | | - ], |
| 41 | + // Override recommended rules |
| 42 | + "@typescript-eslint/no-explicit-any": 0, |
| 43 | + "@typescript-eslint/no-namespace": [2, { allowDeclarations: true }], |
| 44 | + "@typescript-eslint/no-unused-vars": [2, { args: "none" }], |
52 | 45 |
|
53 | | - // Override recommended rules |
54 | | - "@typescript-eslint/no-explicit-any": 0, |
55 | | - "@typescript-eslint/no-namespace": [2, { allowDeclarations: true }], |
56 | | - "@typescript-eslint/no-unused-vars": [2, { args: "none" }], |
| 46 | + // Stylistic rules |
| 47 | + "@typescript-eslint/adjacent-overload-signatures": 2, |
| 48 | + "@typescript-eslint/consistent-type-assertions": 2, |
| 49 | + "@typescript-eslint/no-empty-interface": 2, |
| 50 | + "@typescript-eslint/no-non-null-assertion": 2, |
| 51 | + "@typescript-eslint/no-inferrable-types": 2, |
57 | 52 |
|
58 | | - // Stylistic rules |
59 | | - "@typescript-eslint/adjacent-overload-signatures": 2, |
60 | | - "@typescript-eslint/consistent-type-assertions": 2, |
61 | | - "@typescript-eslint/no-empty-interface": 2, |
62 | | - "@typescript-eslint/no-non-null-assertion": 2, |
63 | | - "@typescript-eslint/no-inferrable-types": 2, |
64 | | - |
65 | | - // Additional rules |
66 | | - "@typescript-eslint/consistent-type-imports": 2, |
67 | | - "@typescript-eslint/no-import-type-side-effects": 2, |
68 | | - // allow require for power-assert and verbatimModuleSyntax |
69 | | - // '@typescript-eslint/no-require-imports': 2, |
70 | | - "@typescript-eslint/prefer-literal-enum-member": 2, |
71 | | - "@typescript-eslint/prefer-ts-expect-error": 2, |
72 | | - }, |
73 | | - settings: { |
74 | | - // Don't enable rules that requires TypeScript parser for perf reasons. |
75 | | - "import/resolver": "typescript", |
| 53 | + // Additional rules |
| 54 | + "@typescript-eslint/consistent-type-imports": 2, |
| 55 | + "@typescript-eslint/no-import-type-side-effects": 2, |
| 56 | + // allow require for power-assert and verbatimModuleSyntax |
| 57 | + // '@typescript-eslint/no-require-imports': 2, |
| 58 | + "@typescript-eslint/prefer-literal-enum-member": 2, |
| 59 | + "@typescript-eslint/prefer-ts-expect-error": 2, |
| 60 | + }, |
| 61 | + settings: { |
| 62 | + // Don't enable rules that requires TypeScript parser for perf reasons. |
| 63 | + "import/resolver": "typescript", |
| 64 | + }, |
76 | 65 | }, |
77 | | -}); |
| 66 | +); |
0 commit comments