Module

health.autofix

Auto-fix framework for health check issues.

Provides safe, automated fixes for common validation errors.

Classes

FixSafety
Safety level for auto-fixes.
0

Safety level for auto-fixes.

Inherits from Enum
FixAction dataclass
Represents a single fix action.
1

Represents a single fix action.

Attributes

Name Type Description
description str

Human-readable description of what will be fixed

file_path Path

Path to file that needs fixing

line_number int | None

Line number (if applicable)

fix_type str

Type of fix (e.g., "directive_fence", "link_update")

safety FixSafety

Safety level (SAFE, CONFIRM, UNSAFE)

apply Any

Function to apply the fix (returns True if successful)

check_result CheckResult | None

Original CheckResult that triggered this fix

Methods 1

can_apply
Check if this fix can be applied automatically.
0 bool
def can_apply(self) -> bool

Check if this fix can be applied automatically.

Returns

bool

AutoFixer
Auto-fix framework for health check issues. Analyzes health check reports and suggests fixes for c…
12

Auto-fix framework for health check issues.

Analyzes health check reports and suggests fixes for common errors. Provides safe fixes that can be applied automatically.

Methods 3

suggest_fixes
Analyze report and suggest fixes for all issues.
0 list[FixAction]
def suggest_fixes(self) -> list[FixAction]

Analyze report and suggest fixes for all issues.

Returns

list[FixAction]

List of FixAction objects representing possible fixes

apply_fixes
Apply fixes to files.
1 dict[str, Any]
def apply_fixes(self, fixes: list[FixAction] | None = None) -> dict[str, Any]

Apply fixes to files.

Parameters 1
fixes list[FixAction] | None

List of fixes to apply (if None, uses self.fixes)

Returns

dict[str, Any]

Dictionary with results: {"applied": N, "failed": M, "skipped": K}

apply_safe_fixes
Apply only safe fixes automatically.
0 dict[str, Any]
def apply_safe_fixes(self) -> dict[str, Any]

Apply only safe fixes automatically.

Returns

dict[str, Any]

Dictionary with results

Internal Methods 9
__init__
Initialize auto-fixer.
2 None
def __init__(self, report: HealthReport, site_root: Path)

Initialize auto-fixer.

Parameters 2
report HealthReport

Health report to analyze for fixes

site_root Path

Root path of the site (required, must be absolute)

_suggest_directive_fixes
Suggest fixes for directive validation errors and warnings.
1 list[FixAction]
def _suggest_directive_fixes(self, validator_report: Any) -> list[FixAction]

Suggest fixes for directive validation errors and warnings.

Parameters 1
validator_report Any
Returns

list[FixAction]

_create_file_fix
Create a fix function that fixes all directives in a file. This ensures we fix…
2 Any
def _create_file_fix(self, file_path: Path, line_numbers: list[int]) -> Any

Create a fix function that fixes all directives in a file.

This ensures we fix the entire hierarchy in one pass, including all nested children and grandchildren.

Parameters 2
file_path Path
line_numbers list[int]
Returns

Any

_is_descendant
Check if directive is a descendant of ancestor.
3 bool
def _is_descendant(self, directive: dict[str, Any], ancestor: dict[str, Any], all_directives: list[dict[str, Any]]) -> bool

Check if directive is a descendant of ancestor.

Parameters 3
directive dict[str, Any]
ancestor dict[str, Any]
all_directives list[dict[str, Any]]
Returns

bool

_get_depth
Get nesting depth of directive (0 = root, 1 = child, etc.).
2 int
def _get_depth(self, directive: dict[str, Any], all_directives: list[dict[str, Any]]) -> int

Get nesting depth of directive (0 = root, 1 = child, etc.).

Parameters 2
directive dict[str, Any]
all_directives list[dict[str, Any]]
Returns

int

_create_fence_fix
Create a fix function for fence nesting issues. Implements hierarchical fix: i…
2 Any
def _create_fence_fix(self, file_path: Path, line_number: int) -> Any

Create a fix function for fence nesting issues.

Implements hierarchical fix: increments all parents +1 based on deepest nested directive. Example: tab-set (grandparent) > tab-item (parent) > note (child, baseline 3) Result: grandparent=5, parent=4, child=3

The fix analyzes the entire file to understand directive hierarchy and fixes from bottom-up (deepest first, then parents).

Parameters 2
file_path Path
line_number int
Returns

Any

_parse_directive_hierarchy
Parse directive hierarchy from file lines. Returns list of directives with par…
1 list[dict[str, Any]]
def _parse_directive_hierarchy(self, lines: list[str]) -> list[dict[str, Any]]

Parse directive hierarchy from file lines.

Returns list of directives with parent relationships.

Parameters 1
lines list[str]
Returns

list[dict[str, Any]]

_apply_single_fix
Apply fix to a single directive (increase fence depth).
2 None
def _apply_single_fix(self, lines: list[str], directive: dict[str, Any]) -> None

Apply fix to a single directive (increase fence depth).

Parameters 2
lines list[str]
directive dict[str, Any]
_suggest_link_fixes
Suggest fixes for link validation errors.
1 list[FixAction]
def _suggest_link_fixes(self, validator_report: Any) -> list[FixAction]

Suggest fixes for link validation errors.

Parameters 1
validator_report Any
Returns

list[FixAction]