Semantic code replacement using ast-grep patterns with safe preview mode
Use sl ast replace for structural code transformations.
# Preview changes (default — does NOT apply)
sl ast replace "<pattern>" "<replacement>" --lang <lang>
# Apply changes to all matches
sl ast replace "<pattern>" "<replacement>" --lang <lang> --update-all
Captured variables ($NAME, $$$ARGS) are reused in the replacement.
Rename a function call:
sl ast replace "console.log($$$ARGS)" "logger.info($$$ARGS)" --lang typescript
Add error handling:
sl ast replace "foo.unwrap()" "foo.expect(\"foo should be set\")" --lang rust
Modernize syntax:
sl ast replace "var $NAME = $VAL" "const $NAME = $VAL" --lang javascript --update-all
--update-all) to verify before applyingsl edit for surgical edits.gitignore by defaultsg binary (auto-downloaded on first use)--path src/ to scope replacements to a directory