ast-grep adds a min-severity CLI option
When running repository checks with `ast-grep scan`, use `--min-severity <LEVEL>` to run only rules whose final severity is at least the threshold.
ast-grep scan --min-severity warningWe scan this tool’s changelog a few times a day and keep the changes that would alter your agent’s next action: 10 since January 2026, each linked to its source.
ast-grepWhen running repository checks with `ast-grep scan`, use `--min-severity <LEVEL>` to run only rules whose final severity is at least the threshold.
ast-grep scan --min-severity warningWhen traversing a parsed source tree, call `namedChildren()` in the WebAssembly or napi binding, or `named_children()` in PyO3, to get named AST nodes only.
const nodes = root.namedChildren()When inspecting code in a builtin language with outline rules, run `ast-grep outline <path>` to view its structure. The 0.44.1 release added outline rules for C, C++, C#, Ruby, and PHP.
ast-grep outline <path>To inspect a file or directory’s structure, run `ast-grep outline` on the target path; bundled outline rules are used automatically. Choose `--items` and `--view` to narrow the output, and use `--outline-rules` only to add extractor definitions.
ast-grep outline <file>When testing ast-grep rules and you need to follow target paths or files, pass `--follow` to `sg test`.
When checking for diagnostics hidden by suppress-all comments, run ast-grep’s built-in `no-suppress-all` rule on the repository. It reports `ast-grep-ignore` comments that omit a rule ID.
ast-grep scan --warning=no-suppress-allWhen a rule needs a reusable global utility customized for different contexts, define parameters on the utility and pass a rule object for every parameter through the caller’s `matches` rule.
# utils/audit-log-call.yml
id: audit-log-call
arguments: [logger-rule]
language: TypeScript
rule:
pattern: $OBJ.$METHOD($$ARGS)
all:
- has:
kind: member_expression
has:
field: object
matches: logger-rule
- has:
field: arguments
has:
kind: string
# rules/audit-logging.yml
id: no-console-string
language: TypeScript
rule:
matches:
audit-log-call:
logger-rule: { regex: ^console$ }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>When a rule should include or exclude paths regardless of case, configure its `files` or `ignores` list with a glob object and set `caseInsensitive: true`.
files:
- glob: '<glob>'
caseInsensitive: trueWhen you need matching file names for a structural search, run ast-grep with `--files-with-matches` and provide a pattern, language, and repository path.
ast-grep run --pattern '<AST pattern>' --lang <language> --files-with-matches <repository-path>