Skip to content

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

Closed

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

Activity

  1. added 2 commits that reference this issue on May 20, 2026
  2. mvanhorn commented on Jun 26, 2026

    @mvanhorn
    Contributor

    Implemented in #1948 - replaces the regex import scan with a syn AST parse moved into a unit-testable lib.rs, adds NDJSON output, and keeps coverage for root aliases and macro-embedded dependency paths that a naive visitor would miss.

  3. josecelano commented on Jun 26, 2026

    @josecelano
    MemberAuthor

    Implemented in #1948 - replaces the regex import scan with a syn AST parse moved into a unit-testable lib.rs, adds NDJSON output, and keeps coverage for root aliases and macro-embedded dependency paths that a naive visitor would miss.

    Thanks @mvanhorn! I will review the PR soon.

  4. added 3 commits that reference this issue on Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions