ast-grep

0.1.0 • Public • Published

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.js -a 'fn()' file.js        Find all no-arg function calls in
                                       'file.js'.
  ast-grep.js -f pattern.js '**/*.js'  Match the pattern in 'pattern.js' across
                                       all JS files.
  echo 'foo' | ast-grep.js '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.

/ast-grep/

    Package Sidebar

    Install

    npm i ast-grep

    Weekly Downloads

    10

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • azz