Skip to content

refactor(core): normalize WalkBuilder paths at the source to eliminate ./ prefix inconsistency #8

@StudentWeis

Description

@StudentWeis

Current State

collect_markdown_files in src/core/util.rs returns paths verbatim from ignore::WalkBuilder. When root is ".", every path carries a ./ prefix (e.g. ./examples/main.md). Downstream consumers — find_references, find_links, and the ReplacementPlan in mv.rs — inherit this inconsistency.

PR #7 worked around the mismatch for mv by introducing canonical_plan_key / find_matching_plan_key (O(n) linear scans with canonicalize() fallback). The workaround is correct but violates KISS: it exists only because the upstream data is ambiguous.

Additionally, find command output mixes ./examples/main.md (References section) with examples/main.md (Links section), which is confusing.

Target State

  1. collect_markdown_files strips the ./ prefix at the source, so every path it returns is in the same "clean relative" form as user-supplied arguments.
  2. canonical_plan_key / find_matching_plan_key and the resolve_path import are removed from mv.rs. All ReplacementPlan key operations revert to plain HashMap lookups.
  3. find output shows consistent path forms (no leading ./).
  4. The two regression tests from fix(mv): mv fails when source has a self-reference and path shape differs from WalkBuilder output #6 (test_mv_relative_source_with_self_reference_succeeds, test_mv_relative_source_rewrites_external_reference) continue to pass, proving the source-level fix is sufficient.

Rationale

  • DRY / KISS: the linear-scan workaround duplicates the "same file?" check that would be unnecessary if the data was clean from the start.
  • User-facing polish: find output becomes consistent.
  • Maintainability: future code that iterates ReplacementPlan keys won't need to remember the ./ quirk.

Scope

core

Safety Net

  • Existing tests cover the affected behavior
  • New tests will be added as part of this refactor
  • This refactor is purely mechanical (no behavior change)

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorInternal cleanup / technical-debt repayment with no user-visible change

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions