all2md.linter.fixes
Auto-fix framework for the linter.
A fix is a closure attached to a Violation. The rule’s check()
captures the offending AST node and emits a Violation whose
fix field carries a LintFix — the framework calls
LintFix.apply to mutate the captured node in place. There is no second
fix() method on LintRule, so check and fix cannot drift.
Most fixes mutate Text.content and never touch FixContext.
Structural fixes (e.g. removing an empty heading) call
fctx.remove(node) to detach a node from its parent — the framework
handles the parent lookup lazily.
- class all2md.linter.fixes.FixSafety
Bases:
IntEnumSafety classification for an auto-fix.
Lower numeric value means safer / less invasive.
apply_fixesuses<= max_safetyto decide which fixes to apply, soSAFEfixes run under both--fixand--fix-unsafewhileSUGGESTEDfixes run only under--fix-unsafe.- SAFE = 1
- SUGGESTED = 2
- MANUAL = 3
- property label: str
Lowercase label suitable for human output (‘safe’, ‘suggested’, ‘manual’).
- __new__(value)
- class all2md.linter.fixes.LintFix
Bases:
objectA fix attached to a
Violation.- Parameters:
target (Node) – The AST node this fix mutates or removes. Used for conflict detection (two fixes targeting the same node — the first one wins).
apply (Callable[[FixContext], None]) – In-place mutation of the AST. For text mutations the callback usually closes over
targetand rewritestarget.content. For structural fixes the callback usesctx.remove(target)orctx.replace(old, new).safety (FixSafety) – How aggressively to apply this fix.
description (str) – Short human-readable description of what the fix does, for reporters and logs.
- apply: Callable[[FixContext], None]
- description: str
- __init__(target: Node, apply: Callable[[FixContext], None], safety: FixSafety, description: str = '') None
- class all2md.linter.fixes.AppliedFix
Bases:
objectRecord of a fix that was (or would have been) applied.
- rule_code: str
- line: int | None
- description: str
- to_dict() dict
Serialise to a plain dict for the JSON reporter.
- class all2md.linter.fixes.FixContext
Bases:
objectMutation primitives passed to
LintFix.apply.The parent map is built lazily on first use, so fixes that only mutate
Text.contentnever pay for it.Initialise a context for
document.The parent map is not built until the first call to
parent_of(),remove(), orreplace().- __init__(document: Document) None
Initialise a context for
document.The parent map is not built until the first call to
parent_of(),remove(), orreplace().
- all2md.linter.fixes.apply_fixes(doc: Document, violations: list['Violation'], max_safety: FixSafety) tuple[list[AppliedFix], list[AppliedFix]]
Apply every fix attached to
violationswhose safety is<= max_safety.Conflict policy: when two fixes target the same node (by
id()), the first one (in deterministic outer-to-inner, top-to-bottom order) is applied; subsequent fixes targeting that node are deferred and returned inskipped_conflicts. Users re-run--fixto converge.- Returns:
Two lists of
AppliedFixrecords — the first describes fixes that ran, the second describes fixes that were deferred because an earlier fix already touched their target.- Return type: