Expand description
scan --fix: apply the rewrites of autofixable rules in place.
The detection pass never touches rewrite or fixer. This module compiles
each autofixable rule with its rewrite as the ast-grep fix (or with its
detection matcher alone when a builtin fixer computes the edits), matches
the source directly (so it can re-match a mutated buffer and reach a fix
point), and applies the resulting edits. The edits of one match form a group
applied together or not at all. Rules marked autofix_unsafe only run when
the caller asks for unsafe fixes.
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.
Enums§
- Fixer
Kind - Builtin fixers a rule can name in its
fixerfield. Builtin only: a custom YAML may reuse one, never define a new one, so an unknown name is a parse error.
Functions§
- fix_
paths - Apply the autofix rewrites over
paths: theautofix_safeones, plus theautofix_unsafeones whenunsafe_fixesis on. - 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, and anautofix_unsaferewrite is applied like a safe one. No manifest is read either: the strum derive macros are assumed reachable throughstrum, and a fixer that needs another file declines. Returns the snippet unchanged when the rule is not autofixable.