1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-22 10:02:10 +02:00
tldr/pages/common/sg.md
marcel 0c28ba9a9b
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>
2023-11-27 15:56:28 +01:00

701 B

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