Skip to main content

Module isolation

Module isolation 

Source
Expand description

Rust unit-isolation lint (#44): an inline #[cfg(test)] mod may call only into the unit under test — its parent module, reached via super::. A call out of the test’s own module — into another first-party module (crate::…), an external crate, or effectful std — is a violation. Inject a trait double (hand-rolled or mockall) instead; the compiler checks the double.

Detection is AST-based: each *.rs file under the crate root is parsed with syn and its #[cfg(test)] modules are walked with a Visitor. This is the deterministic syn heuristic; full name-resolution precision is a future dylint pass. The design and its precision limits live in internals/rust/isolation.md.

Implemented detector:

  • no-out-of-module-call (D1): a call expression A::…::f(…) inside a #[cfg(test)] module whose leading segment A reaches out of the module — crate:: (first-party, another module), super::super::… (an ancestor), an external crate from Cargo.toml, or effectful std. A single super::, self/Self, a bare/unqualified call, and pure std (incl. io::Cursor) stay in-module and are not flagged.

Re-exports§

pub use crate::violation::Violation;

Enums§

Language
A language whose unit-isolation convention can be checked. Rust only for now (Python #42 / TypeScript #43 are separate detectors).

Functions§

find_violations
Scan the Rust source files under root and return every isolation violation, sorted by (file, line) for deterministic output.