Lint diff
lint_diff
Compute tagged_plus_minus diffs between post-agent and post-lint snapshots.
ImportRemoval
dataclass
A dangerous ruff removal surfaced from a lint diff.
F401 marks an unused import ruff deleted; F811 marks a symbol whose
redefinition ruff dropped. name is the import/symbol identifier, file
the (optionally resolved) path and code the ruff rule that fired.
Source code in packages/axm-edit/src/axm_edit/services/lint_diff.py
compute_lint_diffs(post_agent, post_lint, rules_by_file, *, max_ratio=0.5, max_chars=4000)
Compute per-file diffs between post-agent and post-lint snapshots.
Returns one entry per file that was mutated by ruff/harness_fix. Files whose content is unchanged are omitted (no empty list entries).
When the diff exceeds max_ratio * len(post_lint_content) OR
max_chars, the entry falls back to {"file", "rules",
"diff_skipped": "file_reread_recommended"} without a diff key.
Source code in packages/axm-edit/src/axm_edit/services/lint_diff.py
extract_import_removals(diagnostics, *, path_resolver=None)
Filter dangerous F401/F811 removals out of concise ruff diagnostics.
Reuses :func:extract_rules_by_file as the authority on which
(file, code) pairs ruff reported, then enriches each F401/F811 entry
with the back-quoted symbol name from the diagnostic message. Pure: no I/O,
no ruff re-run — it only classifies the already-collected diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostics
|
list[str]
|
Concise ruff diagnostic lines (same input as
:func: |
required |
path_resolver
|
Callable[[str], str] | None
|
Optional callable mapping raw file path to the key used
by |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, list[ImportRemoval]]
|
|
dict[str, list[ImportRemoval]]
|
Empty when no such removal is present. |
Source code in packages/axm-edit/src/axm_edit/services/lint_diff.py
extract_rules_by_file(diagnostics, *, path_resolver=None)
Parse file:line:col: CODE msg diagnostic lines into {file: [codes]}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostics
|
list[str]
|
Concise ruff diagnostic lines. |
required |
path_resolver
|
Callable[[str], str] | None
|
Optional callable mapping raw file path to the key
used by |
None
|