Expand description
scan --fix: apply the rewrite template of autofix-safe rules in place.
The detection pass never touches rewrite. This module compiles each
autofixable rule with its rewrite as the ast-grep fix, matches the source
directly (so it can re-match a mutated buffer and reach a fix point), and
applies the resulting edits.
A rewrite stays within the scope of detection: only builtin rules, or
external rules the user listed in fix.allow_external, are applied; a rule’s
files / ignores globs are honored; a dedicated autofix_rule only
rewrites inside a match of the detection rule (with its constraints).
Findings that detection would suppress – inside test code, disabled inline,
or recorded in the baseline – are never rewritten. Inline disables and
baseline membership are resolved once on the original content and tracked
through every edit, so a rewrite that shifts lines cannot unprotect them.
Structs§
- FileFix
- The rewrite of one file: kept only when the content actually changed.
- FixReport
- Outcome of a
--fixrun over one or more paths.
Functions§
- fix_
paths - Apply the autofix-safe rewrites over
paths. - fix_
snippet - Apply a single rule’s autofix rewrite to an in-memory snippet, to a fix
point. Used by
slopguard testto validatetests.should_fix: no baseline, no test-path filtering, nofiles/ignoresglobs, no inline-disable directives are consulted. Nothing is written to disk, so the external-rule trust gate does not apply. Returns the snippet unchanged when the rule is not autofixable.