Skip to content

feat: add autofix for legacy_comment and near_duplicate findings#940

Merged
chubes4 merged 2 commits intomainfrom
feat/comment-and-near-dup-fixers
Mar 23, 2026
Merged

feat: add autofix for legacy_comment and near_duplicate findings#940
chubes4 merged 2 commits intomainfrom
feat/comment-and-near-dup-fixers

Conversation

@chubes4
Copy link
Member

@chubes4 chubes4 commented Mar 23, 2026

Summary

  • comment_fixes: Auto-removes LegacyComment and TodoMarker findings via DocLineRemoval. Parses line number from the audit description. Safe tier.
  • near_duplicate_fixes: Consolidates structurally identical functions across files. Picks canonical copy (alphabetically first), removes the duplicate, adds a use import, upgrades visibility to pub(crate) on canonical if needed. Safe tier — sandbox validation gates correctness.

Both registered in generate_fixes_impl(). Fixability auto-derives.

Finding coverage after this PR

Category Before After
legacy_comment ❌ No fixer ✅ Safe auto-fix
todo_marker ❌ No fixer ✅ Safe auto-fix
near_duplicate ❌ No fixer ✅ Safe auto-fix

Closes #929 (legacy_comment)
Addresses #542 (near_duplicate — 16 findings now fixable)

Add two new fixers to the refactor pipeline:

- comment_fixes: removes stale LegacyComment and TodoMarker lines via
  DocLineRemoval. Parses line number from the finding description.

- near_duplicate_fixes: consolidates structurally identical functions
  across files. Picks the canonical copy (first alphabetically), removes
  the duplicate via FunctionRemoval, adds a use import, and upgrades
  visibility to pub(crate) on the canonical if needed. All Safe tier —
  sandbox validation + cargo check catches breakage before merge.

Both fixers are registered in generate_fixes_impl() and fixability
auto-derives from compute_fixability().
@homeboy-ci
Copy link
Contributor

homeboy-ci bot commented Mar 23, 2026

Homeboy Results — homeboy

Audit

Failure Digest

Audit Failure Digest

  • Alignment score: 0.921
  • Severity counts: info: 9, unknown: 3, warning: 24
  • Outliers in current run: 3
  • Parsed outlier entries: 3
  • Drift increased: yes
  • New findings since baseline: 6
    1. intra-method-duplication — Duplicated block in generate_comment_fixes — 5 identical lines at line 109 and line 202 (intra-method-duplication::src/core/refactor/plan/generate/comment_fixes.rs::IntraMethodDuplicate)
    2. intra-method-duplication — Duplicated block in generate_near_duplicate_fixes — 5 identical lines at line 131 and line 147 (intra-method-duplication::src/core/refactor/plan/generate/near_duplicate_fixes.rs::IntraMethodDuplicate)
    3. intra-method-duplication — Duplicated block in run_fix_iteration — 11 identical lines at line 446 and line 476 (intra-method-duplication::src/core/refactor/plan/verify.rs::IntraMethodDuplicate)
    4. comment_hygiene — Comment marker 'TODO' found on line 107: TODO markers describe work to be done — always needs human review. (comment_hygiene::src/core/refactor/plan/generate/comment_fixes.rs::TodoMarker)
    5. test_coverage — Method 'generate_comment_fixes' has no corresponding test (expected 'test_generate_comment_fixes') (test_coverage::src/core/refactor/plan/generate/comment_fixes.rs::MissingTestMethod)
  • Top actionable findings:
    1. src/core/refactor/plan/planner.rs — god_file — File has 1183 lines (threshold: 1000)
    2. src/core/refactor/plan/planner.rs — high_item_count — File has 28 top-level items (threshold: 15)
    3. src/core/code_audit/report.rs — intra_method_duplicate — Duplicated block in compute_fixability — 10 identical lines at line 209 and line 231
    4. src/core/refactor/plan/generate/comment_fixes.rs — intra_method_duplicate — Duplicated block in generate_comment_fixes — 5 identical lines at line 109 and line 202
    5. src/core/refactor/plan/generate/near_duplicate_fixes.rs — intra_method_duplicate — Duplicated block in generate_near_duplicate_fixes — 5 identical lines at line 131 and line 147
All parsed audit findings (36)
1. **src/core/refactor/plan/planner.rs** — god_file — File has 1183 lines (threshold: 1000)
2. **src/core/refactor/plan/planner.rs** — high_item_count — File has 28 top-level items (threshold: 15)
3. **src/core/code_audit/report.rs** — intra_method_duplicate — Duplicated block in `compute_fixability` — 10 identical lines at line 209 and line 231
4. **src/core/refactor/plan/generate/comment_fixes.rs** — intra_method_duplicate — Duplicated block in `generate_comment_fixes` — 5 identical lines at line 109 and line 202
5. **src/core/refactor/plan/generate/near_duplicate_fixes.rs** — intra_method_duplicate — Duplicated block in `generate_near_duplicate_fixes` — 5 identical lines at line 131 and line 147
6. **src/core/refactor/plan/verify.rs** — intra_method_duplicate — Duplicated block in `run_fix_iteration` — 11 identical lines at line 446 and line 476
7. **src/core/refactor/add.rs** — near_duplicate — Near-duplicate `resolve_root` — structurally identical to src/core/refactor/move_items/whole_file_move.rs
8. **src/core/refactor/plan/planner.rs** — unreferenced_export — Public function 'analyze_stage_overlaps' is not referenced by any other file
9. **src/core/refactor/plan/planner.rs** — unreferenced_export — Public function 'normalize_sources' is not referenced by any other file
10. **src/core/refactor/plan/planner.rs** — unreferenced_export — Public function 'run_lint_refactor' is not referenced by any other file
11. **src/core/refactor/plan/planner.rs** — unreferenced_export — Public function 'run_test_refactor' is not referenced by any other file
12. **src/core/refactor/plan/planner.rs** — unreferenced_export — Public function 'summarize_plan_totals' is not referenced by any other file
13. **src/core/refactor/plan/planner.rs** — unreferenced_export — Public function 'test_refactor_request' is not referenced by any other file
14. **src/core/refactor/plan/generate/comment_fixes.rs** — todo_marker — Comment marker 'TODO' found on line 107: TODO markers describe work to be done — always needs human review.
15. **src/core/code_audit/report.rs** — missing_test_method — Method 'build_audit_summary' has no corresponding test (expected 'test_build_audit_summary')
16. **src/core/code_audit/report.rs** — missing_test_method — Method 'compute_fixability' has no corresponding test (expected 'test_compute_fixability')
17. **src/core/code_audit/report.rs** — missing_test_method — Method 'finding_kind_key' has no corresponding test (expected 'test_finding_kind_key')
18. **src/core/code_audit/report.rs** — missing_test_method — Method 'from_main_workflow' has no corresponding test (expected 'test_from_main_workflow')
19. **src/core/refactor/add.rs** — missing_test_method — Method 'add_import' has no corresponding test (expected 'test_add_import')
20. **src/core/refactor/add.rs** — missing_test_method — Method 'fixes_from_audit' has no corresponding test (expected 'test_fixes_from_audit')
21. **src/core/refactor/plan/generate/comment_fixes.rs** — missing_test_method — Method 'generate_comment_fixes' has no corresponding test (expected 'test_generate_comment_fixes')
22. **src/core/refactor/plan/generate/near_duplicate_fixes.rs** — missing_test_method — Method 'generate_near_duplicate_fixes' has no corresponding test (expected 'test_generate_near_duplicate_fixes')
23. **src/core/refactor/plan/planner.rs** — missing_test_method — Method 'analyze_stage_overlaps' has no corresponding test (expected 'test_analyze_stage_overlaps')
24. **src/core/refactor/plan/planner.rs** — missing_test_method — Method 'build_refactor_plan' has no corresponding test (expected 'test_build_refactor_plan')
25. **src/core/refactor/plan/planner.rs** — missing_test_method — Method 'lint_refactor_request' has no corresponding test (expected 'test_lint_refactor_request')
26. **src/core/refactor/plan/planner.rs** — missing_test_method — Method 'normalize_sources' has no corresponding test (expected 'test_normalize_sources')
27. **src/core/refactor/plan/planner.rs** — missing_test_method — Method 'run_lint_refactor' has no corresponding test (expected 'test_run_lint_refactor')
28. **src/core/refactor/plan/planner.rs** — missing_test_method — Method 'run_test_refactor' has no corresponding test (expected 'test_run_test_refactor')
29. **src/core/refactor/plan/planner.rs** — missing_test_method — Method 'summarize_plan_totals' has no corresponding test (expected 'test_summarize_plan_totals')
30. **src/core/refactor/plan/planner.rs** — orphaned_test — Test method 'test_component' references 'component' which no longer exists in the source
31. **src/core/refactor/plan/planner.rs** — orphaned_test — Test method 'test_refactor_request' references 'refactor_request' which no longer exists in the source
32. **src/core/refactor/plan/planner.rs** — orphaned_test — Test method 'test_tmp_dir' references 'tmp_dir' which no longer exists in the source
33. **src/core/refactor/plan/verify.rs** — missing_test_file — No test file found (expected 'tests/core/refactor/plan/verify_test.rs') and no inline tests
34. **src/commands/docs.rs** — outlier — (outlier)
35. **tests/commands/deploy_test.rs** — outlier — (outlier)
36. **src/core/engine/undo/rollback.rs** — outlier — (outlier)
- Full audit log: https://github.com/Extra-Chill/homeboy/actions/runs/23419554490

Autofixability classification

  • Overall: auto_fixable
  • Autofix enabled: yes
  • Autofix attempted this run: no
  • Auto-fixable failed commands:
    • audit
  • Failed commands with available automated fixes:
    • audit

Machine-readable artifacts

  • homeboy-lint-summary.json
  • homeboy-test-failures.json
  • homeboy-audit-summary.json
  • homeboy-autofixability.json

⚡ Scope: changed files only

audit (changed files only)

Auto-refactor

ℹ️ Autofix enabled, but no fixable file changes were produced

Failure Digest

Autofixability classification

  • Overall: human_needed
  • Autofix enabled: yes
  • Autofix attempted this run: no
  • Human-needed failed commands:
    • refactor --from all

Machine-readable artifacts

  • homeboy-lint-summary.json
  • homeboy-test-failures.json
  • homeboy-audit-summary.json
  • homeboy-autofixability.json

⚡ Scope: changed files only

refactor --from all

Tooling versions
  • Homeboy CLI: homeboy 0.85.3+bfa5a8f
  • Extension: rust from https://github.com/Extra-Chill/homeboy-extensions
  • Extension revision: unknown
  • Action: Extra-Chill/homeboy-action@v2

Homeboy Action v1

…ments

The legacy comment fixer was wrong — it deleted the comment line and left
the actual legacy code behind. The comment is a SIGNAL that legacy
fallback code exists. The fix is removing the entire code block.

New behavior:
- Reads the source file and classifies what the comment annotates
- Function definition → Safe FunctionRemoval of comment + entire fn
- Guard clause (if without else) → Safe removal of comment + if block
- Match arm → Safe removal of comment + arm
- Else branch → PlanOnly (control flow change needs review)
- Code section → PlanOnly (heuristic boundaries need review)
- Unknown → PlanOnly (manual review required)
- TodoMarker → always PlanOnly (describes work, not code to remove)

Block detection uses brace-depth tracking, indent analysis, and
backward scanning for else branches.
@chubes4 chubes4 merged commit cb9a496 into main Mar 23, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

audit: legacy comment in homeboy (1)

1 participant