Let's say you want to scan for C++ forward declarations in a codebase. Specifically the Chromium codebase.
This Gist captures some details about how to do that with ast-grep. You may also want jq for a few of the commands.
- Make sure you have
ast-grepandjqinstalled - Copy
sgconfig.ymlto the root of the Chromium repo - Create a folder at the root of the Chromium repo called
ast-grep-rules - Copy
forward-declaration.yamlinto that folder
- Basic usage:
ast-grep scan - Collect files with forward declarations, sorted by forward declaration count:
ast-grep scan --json=stream | jq -r '.file' | sort | uniq -c | sort -nr - Collect forward declaration names, sorted by count:
ast-grep scan --json=stream | jq -r '.metaVariables.single.IMPT.text' | sort | uniq -c | sort -nr