Skip to content

Commit

Permalink
style: add @typescript-eslint/eslint-plugin plugin to eslint
Browse files Browse the repository at this point in the history
Co-authored-by: 丶远方 <[email protected]>
  • Loading branch information
sxzz and Alfred-Skyblue committed Dec 19, 2023
1 parent d5df439 commit 1312b63
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 6 deletions.
28 changes: 25 additions & 3 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const banConstEnum = {
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module'
sourceType: 'module',
project: './tsconfig.eslint.json'
},
plugins: ['jest', 'import'],
plugins: ['jest', 'import', '@typescript-eslint'],
rules: {
'no-debugger': 'error',
// most of the codebase are expected to be env agnostic
Expand All @@ -38,7 +39,23 @@ module.exports = {
'import/no-nodejs-modules': [
'error',
{ allow: builtinModules.map(mod => `node:${mod}`) }
]
],
// This rule enforces the preference for using '@ts-expect-error' comments in TypeScript
// code to indicate intentional type errors, improving code clarity and maintainability.
'@typescript-eslint/prefer-ts-expect-error': 'error',
// Avoid unnecessary type assertions
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
// Enforce the use of 'import type' for importing types
'@typescript-eslint/consistent-type-imports': [
'error',
{
fixStyle: 'inline-type-imports'
}
],
// Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers
'@typescript-eslint/no-import-type-side-effects': 'error',
// Ensure consistent usage of indexed object access style in TypeScript code.
'@typescript-eslint/consistent-indexed-object-style': 'error'
},
overrides: [
// tests, no restrictions (runs in Node / jest with jsdom)
Expand Down Expand Up @@ -103,6 +120,11 @@ module.exports = {
rules: {
'import/no-nodejs-modules': ['error', { allow: builtinModules }]
}
},
{
// disable type checking for JS files
files: ['*.js'],
extends: ['plugin:@typescript-eslint/disable-type-checked']
}
]
}
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"semi": false,
"singleQuote": true,
"arrowParens": "avoid"
"arrowParens": "avoid",
"trailingComma": "none"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"@types/minimist": "^1.2.5",
"@types/node": "^20.10.4",
"@types/semver": "^7.5.5",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.13.2",
"@vitest/coverage-istanbul": "^1.0.4",
"@vue/consolidate": "0.17.3",
Expand Down
118 changes: 116 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["packages", "scripts", "./*.ts"]
}

0 comments on commit 1312b63

Please sign in to comment.