sg

Ast-grep is a tool for code structural search, lint, and rewriting. More information: <https://ast-grep.github.io/guide/introduction.html>.

Install

All systems
curl cmd.cat/sg.sh
Debian Debian
apt-get install login
Ubuntu
apt-get install login
Alpine
apk add shadow
Arch Arch Linux
pacman -S shadow
image/svg+xml Kali Linux
apt-get install login
Fedora
dnf install shadow-utils-2
Windows (WSL2)
sudo apt-get update sudo apt-get install login
Raspbian
apt-get install login
Docker
docker run cmd.cat/sg sg powered by Commando

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

© tl;dr; authors and contributors