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

Question: What parser is required when running typescript rules? #134

Open
stephen-carter-at-sf opened this issue Jun 18, 2024 · 2 comments

Comments

@stephen-carter-at-sf
Copy link

I see the readme says:

Usage with TypeScript
To enable working with TypeScript projects, install @babel/preset-typescript as a dependency, then add "typescript" to parserOptions.babelOptions.parserOpts.plugins in your .eslintrc.

but it shows an example that uses babelOptions which makes me think that the @babel/eslint-parser parser is required instead of the @typescript-eslint/parser. In order to also run the plugin:@typescript-eslint/recommended rules... I believe I need the @typescript-eslint/parser parser. But if I use @typescript-eslint/parser then how can I update the babelOptions with the "typescript" plugin?

@wjhsf
Copy link
Contributor

wjhsf commented Jun 19, 2024

You can only specify one parser. These rules were written with @babel/eslint-parser, so that's the parser we officially support. I think they should be reasonably similar when parsing JavaScript code, but I haven't fully investigated their interoperability. It's on our radar, though (salesforce/eslint-plugin-lwc#153).

An additional thing to be aware of when using this plugin with TypeScript is that certain language features (like type assertions) will break the rules' ability to detect violations, because the AST is different from what we expect to find in JavaScript code. Adding better TypeScript support is also something we're looking into (salesforce/eslint-plugin-lwc#154), but we have not yet decided which parser to support, going forward.

@stephen-carter-at-sf
Copy link
Author

For our usecase, we already want to apply the rules from https://typescript-eslint.io/ which has
parser: '@typescript-eslint/parser' https://typescript-eslint.io/packages/parser

So unless your rules are compatible with their parser or their rules are compatible with your chosen parser... we will be unable to run both sets of rules at the same time. And by we, I mean the next generation of Salesforce Code Analyzer.

At best we would have to make 2 passes of ESLint with 2 different sets of configuration in order to make things work if the parser are incompatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants