From a9bc0d790d7d69e39e7a096f9332bb7aead9a437 Mon Sep 17 00:00:00 2001 From: 23f3001101 <23f3001101@ds.study.iitm.ac.in> Date: Sat, 4 Apr 2026 19:33:57 +0530 Subject: [PATCH] ast-grep: add page (#21517) Co-authored-by: Dylan <145150333+dmmqz@users.noreply.github.com> --- pages/common/ast-grep.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pages/common/ast-grep.md diff --git a/pages/common/ast-grep.md b/pages/common/ast-grep.md new file mode 100644 index 0000000000..797189702e --- /dev/null +++ b/pages/common/ast-grep.md @@ -0,0 +1,28 @@ +# ast-grep + +> Search, lint, and rewrite code using AST patterns. +> More information: . + +- Search for a pattern in files: + +`ast-grep run {{[-p|--pattern]}} '{{pattern}}' {{path/to/file}}` + +- Search for a pattern in a specific language: + +`ast-grep run {{[-p|--pattern]}} '{{pattern}}' {{[-l|--lang]}} {{python}} {{path/to/directory}}` + +- Rewrite code matching a pattern: + +`ast-grep run {{[-p|--pattern]}} '{{pattern}}' {{[-r|--rewrite]}} '{{replacement}}' {{path/to/file}}` + +- Run rules from a configuration file: + +`ast-grep scan {{[-r|--rule]}} {{path/to/rule.yml}} {{path/to/directory}}` + +- Interactively search and rewrite code: + +`ast-grep run {{[-p|--pattern]}} '{{pattern}}' {{[-i|--interactive]}} {{path/to/directory}}` + +- Display help for a subcommand: + +`ast-grep {{run}} {{[-h|--help]}}`