mirror of
https://github.com/ivuorinen/cheatsheet-tldr.git
synced 2026-03-10 17:58:18 +00:00
Update cheatsheets
This commit is contained in:
25
sg
Normal file
25
sg
Normal file
@@ -0,0 +1,25 @@
|
||||
---
|
||||
syntax: markdown
|
||||
tags: [tldr, common]
|
||||
source: https://github.com/tldr-pages/tldr.git
|
||||
---
|
||||
# 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`
|
||||
Reference in New Issue
Block a user