From 0c28ba9a9bff8fda66f041a5afcbb18ff01e8506 Mon Sep 17 00:00:00 2001 From: marcel Date: Mon, 27 Nov 2023 15:56:28 +0100 Subject: [PATCH] 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> --- pages/common/sg.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pages/common/sg.md diff --git a/pages/common/sg.md b/pages/common/sg.md new file mode 100644 index 000000000..24f28da89 --- /dev/null +++ b/pages/common/sg.md @@ -0,0 +1,20 @@ +# sg + +> Ast-grep is a tool for code structural search, lint, and rewriting. +> More information: . + +- 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($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`