Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
JoshuaKGoldberg opened this issue Jul 2, 2024 · 1 comment · Fixed by #9486
Closed
4 tasks done

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

JoshuaKGoldberg opened this issue Jul 2, 2024 · 1 comment · Fixed by #9486
Assignees
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.

Comments

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Jul 2, 2024

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

💖

@JoshuaKGoldberg JoshuaKGoldberg added bug Something isn't working triage Waiting for team members to take a look labels Jul 2, 2024
@JoshuaKGoldberg
Copy link
Member Author

Oh, and: #8891 is a byproduct of this.

@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Jul 3, 2024
@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Jul 3, 2024
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Jul 14, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant