Skip to content

refactor(cli): consolidate duplicated path-strip + output-routing onto shared helpers #545

@dekobon

Description

@dekobon

Summary

Cleanup surfaced while reviewing #544. Now that
big-code-analysis-cli/src/format_util.rs::strip_path_prefix and
lib.rs::{validate_output_path, write_output_or_stdout} exist as shared
helpers, three pre-existing inline duplicates should migrate onto them. This is
a pure DRY refactor — identical logic, no behavior change.

Duplication to consolidate

  1. Path-prefix stripping (→ format_util::strip_path_prefix):

    • big-code-analysis-cli/src/exemptions.rs — private fn strip (~line 335)
      and its 6 call sites (lines ~139, 163, 194, 214, 228, 275).
    • big-code-analysis-cli/src/markdown_report.rs — inline
      file.strip_prefix(strip_prefix).unwrap_or(file) (~line 123).
      All three are byte-identical to strip_path_prefix.
  2. Output-path validate + write (→ validate_output_path /
    write_output_or_stdout):

    • commands.rs::run_command_report (validate block ~1585, write ~1614).
    • commands.rs::run_command_exemptions (validate ~2158, write ~2194).
      The new validate_output_path emits the same error wording
      (--output must be a file path for \`, parent directory of
      --output does not exist: …); confirm the write-path die_io` verb matches
      the existing message before swapping (keep the message identical).

Acceptance

  • exemptions.rs and markdown_report.rs call strip_path_prefix; the private
    strip fn is removed.
  • run_command_report/run_command_exemptions use the shared validate/write
    helpers with byte-identical error messages.
  • No behavior change; existing report/exemptions tests pass unmodified.

Found during #544 review; additive/non-breaking, no milestone.


Resolution

Fixed in e28cd710 (branch fix/issue-545). Pure DRY refactor, no
behavior change.

  • exemptions.rs: the 6 strip(...) call sites now call
    format_util::strip_path_prefix; the private strip fn is removed.
  • markdown_report.rs: the inline
    file.strip_prefix(strip_prefix).unwrap_or(file) in
    extract_summaries now calls strip_path_prefix. The shared helper's
    empty-prefix guard yields an identical result for the default empty
    prefix.
  • commands.rs: run_command_report and run_command_exemptions now
    use validate_output_path and write_output_or_stdout. Error wording
    (--output must be a file path for \`, parent directory of
    --output does not exist: …) and write verbs (write report to, write exemptions report to`) are byte-identical to the prior inline
    blocks.

Validation: cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, and cargo test --workspace --all-features
all pass. Existing report/exemptions tests pass unmodified; no .snap.new
drift.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions