Issue
I am getting the error: -
Parsing error: "parserOptions.project" has been set for u/typescript-eslint/parser.
The file does not match your project config: .eslintrc.js.
The file must be included in at least one of the projects provided.
IDE - WebStorm 20.1.1
Project structure: -
node_modules
src
--- testfile.js
.eslintrc.js
.prettierrc.js
baseeslint.js
package.json
tsconfig.json
.eslintrc.js: -
module.exports = {
extends: ['./baseeslint'],
parserOptions: {
project: './tsconfig.json'
},
rules: {}
}
baseeslint.js: -
module.exports = {
parser: '@typescript-eslint/parser'
}
tsconfig.json: -
{
"include": [
"/src/**/*.ts",
"/src/**/*.tsx"
],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "./lib",
"types": ["styled-components", "react", "@types/react-router-dom", "reactstrap"]
}
}
I have absolutely no idea why this is happening? I would assume it would ignore files in the root, especially with include specified in my tsconfg.json?
Any help would be greatly appreciated.
EDIT: -
My solution, should it help others...
I added the ignorePatterns configuration to my .eslintrc.js file: -
module.exports = {
extends: ["mycustom/eslint-config"],
parserOptions: {
project: './tsconfig.json'
},
ignorePatterns: ["/*.*"],
rules: {}
}
This can also be done via .eslintignore (see Anton Bessonov's response below).
Another thing relating to this which maybe of use to others here is the VScode config I used (I switched from WebStorm to VSCode after posting the original question). I am a big fan of running eslint fix on save but I do not want it attempting to do this with all files. My project files (and only my project files) are all .ts/.tsx. The options below in settings.json allow fix on save without it including every file in my repo: -
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.probe": [
"typescript",
"typescriptreact"
],
}
If eslint.probe is not specified, it defaults to: -
["javascript", "javascriptreact", "typescript", "typescriptreact", "html", "vue"]
More about the VSCode ESLint extension settings can be found here.
Solution
Why this happens?
I'm not entirely sure, but it seems like @typescript-eslint/parser
tries to compare files covered in the eslint configuration (for example by extension) with files included in tsconfig.json
. Since the .js
files are covered by @typescript-eslint/parser and depending on your eslint configuration, the file is probably included in the eslint run. But because the file isn't included in tsconfig, you get this error.
How to fix that?
Depending on your case, you can select one of them:
- You can ignore it in
.eslintignore
. This is what @U4EA did. - If can add it to the includes in
tsconfig.json
:
"include": [
".eslintrc.js",
// another includes
]
- If you don't have a "right" tsconfig.json, because you use a monorepo, then you can create a new file
tsconfig.eslint.json
:
{
"include": [
".eslintrc.js"
]
}
and use this file inside .eslintrc.js
for eslint only:
parserOptions: {
project: [
'./tsconfig.eslint.json',
'./packages/*/tsconfig.json',
],
},
Answered By - Anton Bessonov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.