Skip to content

Commit 1528641

Browse files
Alfred-Skybluesxzz
andcommitted
style: add @typescript-eslint/eslint-plugin plugin (#8978)
Co-authored-by: 三咲智子 Kevin Deng <[email protected]>
1 parent 00da674 commit 1528641

File tree

4 files changed

+146
-5
lines changed

4 files changed

+146
-5
lines changed

.eslintrc.cjs

+25-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ const banConstEnum = {
1616
module.exports = {
1717
parser: '@typescript-eslint/parser',
1818
parserOptions: {
19-
sourceType: 'module'
19+
sourceType: 'module',
20+
project: './tsconfig.eslint.json'
2021
},
21-
plugins: ['jest', 'import'],
22+
plugins: ['jest', 'import', '@typescript-eslint'],
2223
rules: {
2324
'no-debugger': 'error',
2425
// most of the codebase are expected to be env agnostic
@@ -38,7 +39,23 @@ module.exports = {
3839
'import/no-nodejs-modules': [
3940
'error',
4041
{ allow: builtinModules.map(mod => `node:${mod}`) }
41-
]
42+
],
43+
// This rule enforces the preference for using '@ts-expect-error' comments in TypeScript
44+
// code to indicate intentional type errors, improving code clarity and maintainability.
45+
'@typescript-eslint/prefer-ts-expect-error': 'error',
46+
// Avoid unnecessary type assertions
47+
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
48+
// Enforce the use of 'import type' for importing types
49+
'@typescript-eslint/consistent-type-imports': [
50+
'error',
51+
{
52+
fixStyle: 'inline-type-imports'
53+
}
54+
],
55+
// Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers
56+
'@typescript-eslint/no-import-type-side-effects': 'error',
57+
// Ensure consistent usage of indexed object access style in TypeScript code.
58+
'@typescript-eslint/consistent-indexed-object-style': 'error'
4259
},
4360
overrides: [
4461
// tests, no restrictions (runs in Node / jest with jsdom)
@@ -103,6 +120,11 @@ module.exports = {
103120
rules: {
104121
'import/no-nodejs-modules': ['error', { allow: builtinModules }]
105122
}
123+
},
124+
{
125+
// disable type checking for JS files
126+
files: ['*.js'],
127+
extends: ['plugin:@typescript-eslint/disable-type-checked']
106128
}
107129
]
108130
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"@types/minimist": "^1.2.5",
7373
"@types/node": "^20.10.4",
7474
"@types/semver": "^7.5.5",
75+
"@typescript-eslint/eslint-plugin": "^6.15.0",
7576
"@typescript-eslint/parser": "^6.13.2",
7677
"@vitest/coverage-istanbul": "^1.0.4",
7778
"@vue/consolidate": "0.17.3",

pnpm-lock.yaml

+116-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.eslint.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["packages", "scripts", "./*.ts"]
4+
}

0 commit comments

Comments
 (0)