Skip to content

Bug: RuleContext.parserPath should be string | undefined, not string  #9475

Closed
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Relevant Package

utils

Playground Link

No response

Repro Code

import * as espree from 'espree';
import eslint from '@eslint/js';
import tseslintA from 'typescript-eslint';

export default tseslintA.config(
  eslint.configs.recommended,
  ...tseslintA.configs.recommendedTypeChecked,
  {
    files: ['index.ts'],
    languageOptions: {
        parser: espree,
        parserOptions: {
            EXPERIMENTAL_useProjectService: true,
        }
    }
  }
);

ESLint Config

No response

tsconfig

No response

Expected Result

ESLint doesn't always know the parserName provided in rule contexts:

https://github.com/eslint/eslint/blob/7c78ad9d9f896354d557f24e2d37710cf79a27bf/lib/linter/linter.js#L978

 * @param {string | undefined} parserName The name of the parser in the config

https://github.com/eslint/eslint/blob/7c78ad9d9f896354d557f24e2d37710cf79a27bf/lib/linter/linter.js#L1920-L1924

            lintingProblems = runRules(
                sourceCode,
                configuredRules,
                ruleId => getRuleFromConfig(ruleId, config),
                void 0,

Actual Result

...but we define it as:

/**
* The rule ID.
*/
id: string;

And now we have this unfortunate stdout bug - note the Parser: undefined:

Error: Error while loading rule '@typescript-eslint/await-thenable': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Parser: undefined
Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward "parserOptions.project" to @typescript-eslint/parser.
Occurred while linting /Users/josh/repos/repros/index.ts

Additional Info

I'll file an ESLint issue soon asking that ESLint tries to glean that parser name if possible. The espree module exports a name = 'espree' that can be useful.

Edit: eslint/eslint#18645

Versions

package version
@typescript-eslint/eslint-plugin 7.15.0
@typescript-eslint/parser 7.15.0
@typescript-eslint/utils 7.15.0
ESLint 8.6.0

💖

Metadata

Metadata

Labels

accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions