parserOptions.project eslint path is resolved wrong

I am using a project generated by @nrwl/nx and they are working with eslint config file extension a lot. Sub projects have new .eslintrc files which extend base .eslintrc files. Also I use the automatic eslint config of webstorm.

One .eslintrc file in a subfolder is extending a base .eslintrc file which is in the root of the project. That root .eslintrc itself has a parserOptions object and requires a tsconfig.base.json file with a relative path. The bundled automatic eslint resolver from webstorm cannot resolve the tsconfig, as the path is resolved from the subfolder instead of the root folder which it should be. Running eslint from the cli does work fine, so I don't think it's a config error, rather than an error in the file resolution.

The screenshot shows, how ESLint tries to resolve the .../foobar/apps/fooapp/tsconfig.base.json instead of the .../foobar/tsconfig.base.json

The root .eslintrc file requires the base file with ./tsconfig.base.json. My guess is, that the nearest .eslintrc file is picked up by webstorm, which is in .../foobar/apps/fooapp/.eslintrc and sets that as new working directory, which is wrong in that case.

Thanks in advance.

4
9 comments

Normally the IDE looks for the directory closest to the linted file which contains .eslintignore or .eslintrc.* file, or package.json file with either "eslintIgnore" or "eslintConfig" property when setting up the working directory... This is expected for monorepos

0

I've stumbled upon a similar issue. Previously I've been using WebStorm 2020.1 and eslint was working flawlessly, once I updated WebStorm to 2020.2 got the same message as OP. Mind you, if I change parserOptions.project to ../tsconfig.json instead of ./tsconfig.json, it satisfies WebStorm but fails when running linter from command line

1

webstorm shows eslint parsing error on windows but not linux

source/.eslintrc.js
exports.parserOptions = {
project: './tsconfig.json',
}

there is the following workaround

const path = require('path')

exports.parserOptions = {
project: path.join(__dirname, '../tsconfig.json'),
}
1

i confirm that the problem appeared in version 2020.2

0

I am on linux (ubuntu 20.04 amd64), and get the parsing error on our (internal) project.

0

We had the same problem and could solve it with this:

parserOptions: {
ecmaVersion: 6,
project: 'tsconfig.json',
tsconfigRootDir: __dirname
}

tsconfigRootDir: __dirname does the trick

 

0

Same here. What is the procedure to create issue regarding this problem?

0

You can create a new ticket in youtrack, https://youtrack.jetbrains.com/issues/WEB

BTW, we have a feature request for a possibility to configure ESLint working folders manually, WEB-47135, please follow it for updates

0

You could try with glob pattern.

exports.parserOptions = {
project: '**/tsconfig.json',
}

 

0

Please sign in to leave a comment.