salesforce / eslint-config-lwc

Opinionated ESLint configurations for LWC projects
MIT License
112 stars 35 forks source link

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

Open stephen-carter-at-sf opened 2 weeks ago

stephen-carter-at-sf commented 2 weeks ago

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 commented 2 weeks ago

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 (https://github.com/salesforce/eslint-plugin-lwc/issues/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 (https://github.com/salesforce/eslint-plugin-lwc/issues/154), but we have not yet decided which parser to support, going forward.

stephen-carter-at-sf commented 1 week ago

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.