8000 Bug: Confusing error when unknown parser used with getParserServices(context, true) in flat config · Issue #8891 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

Bug: Confusing error when unknown parser used with getParserServices(context, true) in flat config #8891

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

Open
4 tasks done
JoshuaKGoldberg opened this issue Apr 10, 2024 · 1 comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: utils Issues related to the @typescript-eslint/utils package

Comments

@JoshuaKGoldberg
Copy link
Member
JoshuaKGoldberg commented Apr 10, 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

{}

ESLint Config

import * as parserJsonc from "jsonc-eslint-parser";
import tseslint from "typescript-eslint";

export default tseslint.config(
    tseslint.configs.base,
    {
        files: ["**/package.json"],
        languageOptions: {
            parser: parserJsonc
        }
    },
    {
        languageOptions: {
            parserOptions: {
                project: true,
            },
        },
        rules: {
            "@typescript-eslint/consistent-type-assertions": "error"
        }
    },
);

tsconfig

n/a

Expected Result

getParserServices should give a complaint saying that the parser is some other one, not @typescript-eslint/parser.

Actual Result

> eslint package.json


Oops! Something went wrong! :(

ESLint: 8.57.0

Error: Error while loading rule '@typescript-eslint/consistent-type-assertions': 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/package.json
    at throwError (/Users/josh/repos/repros/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:40:11)
    at getParserServices (/Users/josh/repos/repros/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:20:9)
    at create (/Users/josh/repos/repros/node_modules/@typescript-eslint/eslint-plugin/dist/rules/consistent-type-assertions.js:88:61)
    at Object.create (/Users/josh/repos/repros/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:38:20)
    at createRuleListeners (/Users/josh/repos/repros/node_modules/eslint/lib/linter/linter.js:895:21)
    at /Users/josh/repos/repros/node_modules/eslint/lib/linter/linter.js:1066:110
    at Array.forEach (<anonymous>)
    at runRules (/Users/josh/repos/repros/node_modules/eslint/lib/linter/linter.js:1003:34)
    at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (/Users/josh/repos/repros/node_modules/eslint/lib/linter/linter.js:1730:31)
    at Linter._verifyWithFlatConfigArray (/Users/josh/repos/repros/node_modules/eslint/lib/linter/linter.js:1861:21)

Additional Info

See isolated repro: https://github.com/JoshuaKGoldberg/repros/tree/ts-eslint-unknown-parser-flat-config

Versions

package version
typescript-eslint 7.6.0
ESLint 8.57.0

😩

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

if (
context.sourceCode.parserServices?.esTreeNodeToTSNodeMap == null ||
context.sourceCode.parserServices.tsNodeToESTreeNodeMap == null
) {
throwError(context.parserPath);
}
// if a rule requires full type information, then hard fail if it doesn't exist
// this forces the user to supply parserOptions.project
if (
context.sourceCode.parserServices.program == null &&
!allowWithoutFullTypeInformation
) {
throwError(context.parserPath);
}

Probably cos we use parserPath which probably should be deprecated for flat configs / v9. Was missed during the cleanup?

@bradzacher bradzacher added package: utils Issues related to the @typescript-eslint/utils package accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: utils Issues related to the @typescript-eslint/utils package
Projects
None yet
Development

No branches or pull requests

2 participants
0