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

[feature] supports multiple languages in a rule #525

Closed
pd4d10 opened this issue Jul 21, 2023 · 2 comments
Closed

[feature] supports multiple languages in a rule #525

pd4d10 opened this issue Jul 21, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@pd4d10
Copy link
Contributor

pd4d10 commented Jul 21, 2023

⭐ Suggestion

supports multiple languages in a rule, for example:

- id: xxx
- languages: [ts, tsx]

💻 Use Cases

There are many common lint cases in ts and tsx. It would be great to config them in one rule, to avoid copy and paste.

@pd4d10 pd4d10 added the enhancement New feature or request label Jul 21, 2023
@HerringtonDarkholme HerringtonDarkholme added the good first issue Good for newcomers label Dec 7, 2023
@HerringtonDarkholme HerringtonDarkholme self-assigned this May 3, 2024
@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented May 3, 2024

I'm suspecting if using multiple languages in a rule is the real issue here.

JavaScript and TypeScript looks like the same, but they just happened to be similar. Their underlying parsers will produce different ASTs for the same code input.

For example:

(a) => f(a)

Will produce different syntax trees. #1087

Having two similar but different languages in the same rule will confuse users for parsing discrepancies.

Instead, the issue here should be rephrased to

"both JS/TS should be parsed with one language and handled together"

Using language globs is probably the better approach here.
https://ast-grep.github.io/reference/sgconfig.html#languageglobs

Example sgconfig.yml

ruleDirs:
  - rules
languageGlobs:
  TypeScript: ["*.js"]

@HerringtonDarkholme
Copy link
Member

Closing as stated above, the more appropriate mental model will be using a superset language to parse subset language via languageGlobs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Archived in project
Development

No branches or pull requests

2 participants