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 detectors:
no-out-of-module-call(D1): a call expressionA::…::f(…)inside a#[cfg(test)]module whose leading segmentAreaches out of the module —crate::(first-party, another module),super::super::…(an ancestor), an external crate fromCargo.toml, or effectfulstd. A singlesuper::,self/Self, a bare/unqualified call, and purestd(incl.io::Cursor) stay in-module and are not flagged.no-out-of-module-import(D2): auseinside a#[cfg(test)]module that brings in a foreign surface — a glob of anything butsuper::*, or a named import rooted atcrate::, an external crate, or effectfulstd.use super::*/use super::Thing(the unit under test),self, and purestd(e.g.collections,io::Cursor) are in-module. Catches a collaborator imported then called unqualified, which D1’s call check can’t see.
Re-exports§
pub use crate::violation::Violation;
Enums§
- Language
- A language whose unit-isolation convention can be checked (Python #42 is a
separate detector). Each detector lives in its own module; this enum is the
shared
unit isolationlanguage selector.
Functions§
- find_
integration_ violations - Scan the Rust integration crates under
root(the*.rsfiles in atests/directory) and return everyno-first-party-doubleviolation — a#[double]import of a first-party item. An integration test runs first-party code for real, so doubling it is the error; doubling an external crate is fine.rootis the crate root; itsCargo.tomlnames the first-party crates. - find_
violations - Scan the Rust source files under
rootand return every isolation violation, sorted by(file, line)for deterministic output.