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] simplify transformation and introduce selector #902

Open
HerringtonDarkholme opened this issue Feb 1, 2024 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@HerringtonDarkholme
Copy link
Member

⭐ Suggestion

Currently transformation and relational rules are pretty verbose.

For example:

transformation

transformation:
  NEW:
    substring:
      source: $A
      startChar: 1

and

rule:
  kind: number
  inside:
    kind: arguments
    inside:
      kind: call_expression

We can refer to CSS syntax to simplify them.

💻 Use Cases

For relational rule, we can simplify using CSS selector syntax. https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors

rule:
  selector: call_expression > arguments > number

For transformation, we can refer to CSS function https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Functions

transformation:
  NEW: substring($A, startChar=1)
@HerringtonDarkholme HerringtonDarkholme added the enhancement New feature or request label Feb 1, 2024
@mrloop
Copy link

mrloop commented Feb 9, 2024

This would be great and just what I've been looking for. I use selectors in eslint rules which uses esquery css style selectors. There's also grasp which uses esquery and css style selectors to search ast and replace JS. But grasp isn't maintained and doesn't support modern JS. Also saw this the other day https://github.com/confused-Techie/selector-tree-sitter . Would the plan be to support searching with css style selectors?

@HerringtonDarkholme
Copy link
Member Author

HerringtonDarkholme commented Feb 9, 2024

@mrloop I didn't support selector at first because they tend to produce long, unreadable selector text.
I still have the same concern today but it looks like using selector can address the verbosity of nested YAML.
Also, tree-sitter-selector is similar but differentfrom esquery selector. Users may be confused about the two.

I need more feedback from users. Please leave your insights here (if you can share the post). Or give the issue a thumb-up!

@junyi
Copy link

junyi commented Feb 14, 2024

FYI I recently found this other tool Grit where they also have their own DSL which I think is quite interesting as well

@HerringtonDarkholme
Copy link
Member Author

Thanks for mentioning @junyi
shipping DSL is out of scope since it requires a lot of infras like editor plugins and lsp. Users also need to learn how to write it.

Compared to a full fledged DSL I would prefer something easier to learn.

That said, I still see users don't know how to write YAML. The learning curve is a critical decision for a new project.

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

No branches or pull requests

3 participants