Skip to content
/ ast-grep Public

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

License

Notifications You must be signed in to change notification settings

azz/ast-grep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published