Skip to content

Commit

Permalink
enable type checking for eslint.config.mjs again
Browse files Browse the repository at this point in the history
there is conflict of type definitions between `@types/eslint` and
`typescript-eslint`. These packages provide their own types for
a config object in `eslint.config.mjs` and the types are not assignable.
`eslint-plugin-n` uses `@types/eslint` but `ts.config()` does not accept
the flat config object of the plugin.  It seems that the maintainer of
`typescript-eslint` won't improve this situation.

typescript-eslint/typescript-eslint#8613 (comment)
  • Loading branch information
rhysd committed Aug 5, 2024
1 parent e6115f5 commit 7a1e09d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
20 changes: 20 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ import n from 'eslint-plugin-n';
export default ts.config(
eslint.configs.recommended,
...ts.configs.recommendedTypeChecked,
// @ts-expect-error Types of typescript-eslint is not compatible with @types/eslint.
// These packages provide their own types for eslint.config.mjs and they are not compatible with each other.
// eslint-plugin-n uses @types/eslint but `ts.config()` does not accept the flat config of the plugin.
// The maintainer of typescript-eslint won't improve this situation. So ignoring type error here is the best
// we can do.
// See https://github.com/typescript-eslint/typescript-eslint/issues/8613#issuecomment-1983488262
n.configs['flat/recommended'],
{
languageOptions: {
parserOptions: {
projectService: true,
project: 'tsconfig.json',
},
},
Expand Down Expand Up @@ -99,4 +106,17 @@ export default ts.config(
'mocha/no-top-level-hooks': 'error',
},
},
{
files: ['eslint.config.mjs'],
languageOptions: {
parserOptions: {
projectService: false,
project: 'tsconfig.eslint.json',
},
},
rules: {
'@typescript-eslint/naming-convention': 'off',
'n/no-extraneous-import': 'off',
},
},
);
48 changes: 48 additions & 0 deletions package-lock.json

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

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"watch:tsc": "tsc -p . --watch --preserveWatchOutput --pretty",
"watch:mocha": "mocha --watch-files \"./test/*.js\"",
"watch": "concurrently -c auto npm:watch:tsc npm:watch:mocha",
"lint:eslint": "eslint --max-warnings 0 \"./**/*.ts\"",
"lint:eslint": "eslint --max-warnings 0 \"./**/*.ts\" eslint.config.mjs",
"lint:tsc-eslint": "tsc -p tsconfig.eslint.json --pretty",
"lint:prettier": "prettier --check \"./**/*.ts\" \"./**/*.mjs\"",
"lint": "concurrently -c auto npm:lint:eslint npm:lint:prettier",
"lint": "concurrently -c auto npm:lint:eslint npm:lint:prettier npm:lint:tsc-eslint",
"fix:eslint": "eslint --fix \"./**/*.ts\"",
"fix:prettier": "prettier --write \"./**/*.ts\" \"./**/*.mjs\"",
"fix": "concurrently -m 1 -c auto npm:fix:eslint npm:fix:prettier",
Expand Down Expand Up @@ -51,6 +52,9 @@
"shlex": "^2.1.2"
},
"devDependencies": {
"@types/eslint": "^9.6.0",
"@types/eslint__js": "^8.42.3",
"@types/eslint-plugin-mocha": "^10.4.0",
"@types/mocha": "^10.0.7",
"@types/mock-require": "^2.0.3",
"@types/node": "^22.1.0",
Expand Down
12 changes: 12 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "nodenext",
"moduleResolution": "nodenext",
"noEmit": true,
"allowJs": true
},
"files": [
"eslint.config.mjs"
]
}

0 comments on commit 7a1e09d

Please sign in to comment.