ast-grep supports the :not selector
Introduced 2026-03-16 · score 0.92
HOW TO USE IT
When a query needs to exclude nodes matching a selector, use ast-grep’s `:not` selector in `--kind` to search the repository. The selector negates its inner selector.
ast-grep run --kind 'expression_statement:not(:has(> call_expression))' <path>ast-grep run --kind 'identifier:not(number)' <path>WHY THIS HELPS
Query repository code while excluding nodes that match a selector condition.
REQUIREMENTS AND LIMITATIONS
- Version: 0.42.0
- --kind <KIND> (required): AST kind or ESQuery-style selector to match. Use `:not(selector)` to negate the inner selector.
- [PATHS]...: Paths to search; defaults to `.`. Multiple paths may be separated by spaces.
FIRST-PARTY EVIDENCE
- https://github.com/ast-grep/ast-grep/releases/tag/0.42.0
- https://ast-grep.github.io/blog/new-ver-42
- https://ast-grep.github.io/reference/rule/esquery
- https://github.com/ast-grep/ast-grep.github.io/blob/main/website/reference/cli.md
Check the installed version and the source before using it. Entry JSON