Skip to content

Overhaul workspace-coupling report tool: replace regex scanner with syn and adopt CLI output contract #1805

@josecelano

Description

@josecelano

Goal

Replace the regex-based import scanner in the workspace-coupling analysis tool with a
syn-based Rust AST parser to correctly extract imported items from all use statement
forms, and bring the tool's CLI output into compliance with the global CLI output contract
(ADR 20260519000000_define_global_cli_output_contract) by replacing plain-text eprintln!
calls with structured JSON NDJSON records on stderr.

Background

The workspace-coupling tool uses a regex to extract imports:

{module_name}::[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)?

This regex misses at minimum two legitimate patterns:

  1. Brace-import groups: use torrust_tracker_contrib_bencode::{BMutAccess, ben_int, ben_map}
  2. Re-export statements: pub use bittorrent_peer_id::{PeerClient, PeerId}

This causes six confirmed false-negative "Items not extracted" entries in the coupling report.
Patching the regex would leave the tool fragile; replacing it with syn AST parsing handles all
valid use forms by construction.

Additionally, the tool's eprintln! calls violate ADR 20260519000000_define_global_cli_output_contract
(section 1: all stderr records must be JSON NDJSON). The migration policy (section 10) requires
migration when the file is substantially touched — this rewrite qualifies.

The tool also has no tests. As part of this overhaul, unit tests (for a pure
parse_imports_from_source function) and integration tests (via std::process::Command against
a fixture workspace) will be added, following TDD order.

Spec

Full specification: docs/issues/open/ (see spec file for this issue number).

Related

  • Part of Overhaul: packages #1669 (EPIC — Overhaul Packages)
  • See also: companion issue for cargo machete --with-metadata and unused dev dep removal

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions