mirror of
https://github.com/tldr-pages/tldr.git
synced 2025-04-22 05:22:09 +02:00
sg: add page (#11445)
Co-authored-by: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> Co-authored-by: Lena <126529524+acuteenvy@users.noreply.github.com>
This commit is contained in:
parent
93d05bf6b7
commit
0c28ba9a9b
1 changed files with 20 additions and 0 deletions
20
pages/common/sg.md
Normal file
20
pages/common/sg.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# sg
|
||||
|
||||
> Ast-grep is a tool for code structural search, lint, and rewriting.
|
||||
> More information: <https://ast-grep.github.io/guide/introduction.html>.
|
||||
|
||||
- Scan for possible queries using interactive mode:
|
||||
|
||||
`sg scan --interactive`
|
||||
|
||||
- Rewrite code in the current directory using patterns:
|
||||
|
||||
`sg run --pattern '{{foo}}' --rewrite '{{bar}}' --lang {{python}}`
|
||||
|
||||
- Visualize possible changes without applying them:
|
||||
|
||||
`sg run --pattern '{{useState<number>($A)}}' --rewrite '{{useState($A)}}' --lang {{typescript}}`
|
||||
|
||||
- Output results as JSON, extract information using `jq` and interactively view it using `jless`:
|
||||
|
||||
`sg run --pattern '{{Some($A)}}' --rewrite '{{None}}' --json | jq '{{.[].replacement}}' | jless`
|
Loading…
Add table
Reference in a new issue