Skip to main content

Module fix

Module fix 

Source
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 --fix run over one or more paths.

Enums§

FixerKind
Builtin fixers a rule can name in its fixer field. 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: the autofix_safe ones, plus the autofix_unsafe ones when unsafe_fixes is on.
fix_snippet
Apply a single rule’s autofix rewrite to an in-memory snippet, to a fix point. Used by slopguard test to validate tests.should_fix: no baseline, no test-path filtering, no files / ignores globs, no inline-disable directives are consulted. Nothing is written to disk, so the external-rule trust gate does not apply, and an autofix_unsafe rewrite is applied like a safe one. No manifest is read either: the strum derive macros are assumed reachable through strum, and a fixer that needs another file declines. Returns the snippet unchanged when the rule is not autofixable.