Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
When using a relativeparserOptions.project
path, I've found that the path is not relative to the config file (e.g..eslintrc.js
) referencing this path, but instead relative to the working directory of the process running the CLI.
From the@typescript-eslint/eslint-plugin
docs:
Here's the problem:
When using the eslint CLI in a different working directory compared to where the eslint config file (e.g..eslintrc.js
) is located, then theparserOptions.project
path will resolve relative to the working directory of the process rather than the config file referencing the relative path.
Here's an example using a project located atC:\Users\m41n\Source\Repos\TT-ESLint-VisualStudioSample
:
- I have a terminal with the user folder as working directory (e.g.
C:\Users\m41n
) - I run the eslint CLI through the terminal on a file located in different directory:
$ C:\Users\m41n\Source\Repos\TT-ESLint-VisualStudioSample\src\TypeScriptSample\node_modules\.bin\eslint.cmd "C:\Users\m41n\Source\Repos\TT-ESLint-VisualStudioSample\src\TypeScriptSample\Scripts\app\HomePageService.ts" --format="json"
By omitting the--config
parameter to the CLI, the config will be resolved correctly by eslint. In this case:C:\Users\m41n\Source\Repos\TT-ESLint-VisualStudioSample\src\TypeScriptSample\.eslintrc.js
Here's the content of the.eslintrc.js
file (irrelevant parts omitted for brevity):
module.exports = { ... "parser": "@typescript-eslint/parser", "parserOptions": { "project": "./tsconfig.json" }, ...
I'll get an parsing error, saying that the fileC:\Users\m41n\tsconfig.json
could not be found (parserOptions.project
path is relative to the working directory of the process, rather than the.eslintrc.js
file):
[ { "filePath": "C:\\Users\\m41n\\Source\\Repos\\TT-ESLint-VisualStudioSample\\src\\TypeScriptSample\\Scripts\\app\\HomePageService.ts", "messages": [ { "ruleId": null, "fatal": true, "severity": 2, "message": "Parsing error: File 'C:\\Users\\m41n\\tsconfig.json' not found." } ], "errorCount": 1, "warningCount": 0, "fixableErrorCount": 0, "fixableWarningCount": 0, "source": "..." }]
What did you expect to happen?
I expect the config propertyparserOptions.project
path to resolve relative to the config file rather than the process running the CLI.
Versions
package | version |
---|---|
"@typescript-eslint/eslint-plugin | 1.9.0 |
@typescript-eslint/parser | 1.9.0 |
TypeScript | 3.4.5 |
ESLint | 5.16.0 |
node | 11.12.0 |