Skip to content

Config property parserOptions.project relative path resolving #540

Closed
@woldner

Description

@woldner

When using a relative parserOptions.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:

typescript

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 the parserOptions.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 at
C:\Users\m41n\Source\Repos\TT-ESLint-VisualStudioSample:

  1. I have a terminal with the user folder as working directory (e.g. C:\Users\m41n)
  2. 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 file C:\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 property parserOptions.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: parserIssues related to @typescript-eslint/parserquestionQuestions! (i.e. not a bug / enhancment / documentation)working as intendedIssues that are closed as they are working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions