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] Support filter sg run results by metavar regular expression #379

Open
HerringtonDarkholme opened this issue May 15, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@HerringtonDarkholme
Copy link
Member

Related: #378

We can only use one single pattern to search code for command line sg run. This is convenient but less powerful to sg scan.
For example, if users want to find userCol.update or itemCol.update, a single pattern $COL.update cannot be done on command line. The work around is to write a temporary rule in YAML and use sg scan -r temp.yml to scan code base.

We can build a better CLI option to accept regular expression for meta-variables on command line.

@HerringtonDarkholme HerringtonDarkholme self-assigned this May 15, 2023
@HerringtonDarkholme HerringtonDarkholme added the enhancement New feature or request label May 15, 2023
@HerringtonDarkholme
Copy link
Member Author

HerringtonDarkholme commented May 15, 2023

I have an idea like this:
sg run will have a new option -f --filter to filter match results based on the metavariable.

The filter will have three forms:

  • -f META_VAR=pattern will match the meta-variable against ast-grep pattern pattern.
  • -f META_VAR/regexp/ will match the meta-variable against regular expression regexp.
  • -f META_VAR:kind_id will match the meta-varaible with nodes of the syntax kind kind.

This is a mini-syntax to keep in sync with constraints in the YAML format. Maybe it is too hard to learn and even harder to search on web.

Please leave comments here if you have any feedback! It can be a simple "love it"/"hate it". Or a lengthy paragraph explaining your preference. Of course I welcome your proposal!

@HerringtonDarkholme
Copy link
Member Author

Alternative design:

  • --filter-pattern META_VAR=pattern
  • --filter-regex META_VAR=regex
  • --filter-kind META_VAR=kind

which one is better?

@adamazing
Copy link

I would definitely prefer the second design.
As a sometime / irregular user of ast-grep, I'm far less likely to recall the former syntax (e.g. -f META_VAR:kind_id etc.).

The second/alternative design would probably lend itself more to ergonomic/easily-grokked shell completions?

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
Development

No branches or pull requests

2 participants