Skip to content
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

Enhancement: Add serialization info to parser #6541

Closed
4 tasks done
nzakas opened this issue Feb 27, 2023 · 4 comments · Fixed by #6586
Closed
4 tasks done

Enhancement: Add serialization info to parser #6541

nzakas opened this issue Feb 27, 2023 · 4 comments · Fixed by #6586
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request package: parser Issues related to @typescript-eslint/parser

Comments

@nzakas
Copy link
Contributor

nzakas commented Feb 27, 2023

Before You File a Proposal Please Confirm You Have Done The Following...

Relevant Package

parser

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

Up until now, the flat config in ESLint was unable to serialize custom parsers, meaning that caching and --print-config would not work with typescript-eslint/parser. I just added a feature that allows parsers to export a meta key that would provide serialization information, such as:

exports.meta = {
    name: "typescript-eslint/parser",
    version: "0.0.0"
};

This should be exported on the same object as parse() and parseForESLint().

Fail

// not applicable

Pass

// not applicable

Additional Info

It seems like there may be some fields meant for rules in this template. :)

@nzakas nzakas added enhancement New feature or request triage Waiting for maintainers to take a look labels Feb 27, 2023
@armano2 armano2 added package: parser Issues related to @typescript-eslint/parser accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Feb 27, 2023
@brettz9
Copy link

brettz9 commented Mar 2, 2023

FWIW, this would be useful for us in eslint-plugin-jsdoc to auto-detect from the parser metadata that the user wants TypeScript mode as far as JSDoc's.

@bradzacher
Copy link
Member

@brettz9 - you can actually get this (in a way) in lint rules today via context.parserPath.
The metadata would help to concretely identify it (eg you could do require(context.parserPath).meta.name), but should still be able to make an educated guess by just inspecting the path.

@brettz9
Copy link

brettz9 commented Mar 3, 2023

@bradzacher : Yes, thank you, that's what we have been using, but for a user trying the new flat config, it seems it is not working per eslint/eslint#16878 (comment) .

@nzakas
Copy link
Contributor Author

nzakas commented Mar 3, 2023

You should be able to do context.parser.meta.name with either type of config.

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 enhancement New feature or request package: parser Issues related to @typescript-eslint/parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants