ast-grep
Verified for current stable LTS
Ast Grep Command: Rewrite Code Matching Pattern
An engineer would use the 'ast-grep' command to automatically refactor a specific code pattern throughout a codebase by substituting it with a new code structure in a targeted file, thereby improving code quality and maintainability. Exact CLI syntax to rewrite_code_matching_pattern using Ast Grep.
When to use this: An engineer would use the 'ast-grep' command to automatically refactor a specific code pattern throughout a codebase by substituting it with a new code structure in a targeted file, thereby improving code quality and maintainability.
Command Syntax
ast-grep run -p '<pattern>' -r '<replacement>' <path/to/file> ast-grep run -p '<pattern>' -r '<replacement>' <path/to/file> Command Breakdown
-p- Command Option
- Tool-specific option used by this command invocation.
-r- Command Option
- Tool-specific option used by this command invocation.
FAQ
Purpose: Exact syntax to rewrite_code_matching_pattern using Ast Grep.
Test path: Replace placeholders and run destructive commands in a disposable workspace first.
Flag behavior: Tool version, platform, and shell can change behavior.
Improve This Command
Suggest a correction, safer default, or version-specific note for this entry.
Related Operations
Ast Grep Command: Search For Pattern In Files
ast-grep run {-p|--pattern} '<pattern>' {path/to/file} Ast Grep Command: Run Rules From Configuration File ast-grep scan {-r|--rule} {path/to/rule.yml} {path/to/directory} Ast Grep Command: Display Help For Subcommand ast-grep {run} {-h|--help} Ast Grep Command: Search For Pattern In Specific Language ast-grep run {-p|--pattern} '<pattern>' {-l|--lang} {python} {path/to/directory} Ast Grep Command: Rewrite Code Matching Pattern ast-grep run {-p|--pattern} '<pattern>' {-r|--rewrite} '<replacement>' {path/to/file}