Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 1.98 KB

File metadata and controls

64 lines (46 loc) · 1.98 KB

ast-grep

Travis Prettier npm semantic-release License

Like grep, but more powerful than you can possibly imagine.

Search your JavaScript files for patterns based on AST shape, rather than substrings or regular expressions.

Install

With yarn:

yarn global add ast-grep

With npm:

npm install --global ast-grep

Usage

$ ast-grep --help
Options:
  --anonymous, -a  Ignore all names in the AST                         [boolean]
  --file, -f       Load pattern from a file                             [string]
  --help           Show help                                           [boolean]
  --version        Show version number                                 [boolean]

Examples:
  ast-grep -a 'fn()' file.js           Find all no-arg function calls in
                                       'file.js'.
  ast-grep -f pattern.js '**/*.js'     Match the pattern in 'pattern.js' across
                                       all JS files.
  echo 'foo' | ast-grep 'pattern'      Match 'pattern' on standard input.

On standard in:

$ echo 'code();' | ast-grep 'code'
code();
$ ast-grep 'foo()' < file.js
foo();

On a set of files:

$ ast-grep 'yield* foo();' '**/*.js'

FAQ

Q. But @azz, grep stands for Global Regular Expression Print, this tool doesn't use Regular Expressions!

A. I know, but gastp doesn't sound great.