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>
pull/23/head
marcel 2023-11-27 15:56:28 +01:00 committed by GitHub
parent 93d05bf6b7
commit 0c28ba9a9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

20
pages/common/sg.md Normal file
View 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`