Skip to content

Commit 7e716ff

Browse files
[mod_module_files] Don't emit lint for modules in tests
fixes: rust-lang#11775 current state: indiscriminately emits the lint for mod files in tests. The following tests/ common/ mod.rs test.rs is a common pattern for code shared across the tests and is suggested in the rust book. The change adds an additional check to verify that the mod file is not in tests. changelog: Fix [`mod_module_files`]: false positive for mod files in tests folder
1 parent ba43632 commit 7e716ff

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

clippy_lints/src/module_style.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,11 @@ fn process_paths_for_mod_files<'a>(
153153
}
154154

155155
/// Checks every path for the presence of `mod.rs` files and emits the lint if found.
156+
/// We should not emit a lint for test modules in the presence of `mod.rs`.
157+
/// Using `mod.rs` in integration tests is a [common pattern](https://doc.rust-lang.org/book/ch11-03-test-organization.html#submodules-in-integration-test)
158+
/// for code-sharing between tests.
156159
fn check_self_named_mod_exists(cx: &EarlyContext<'_>, path: &Path, file: &SourceFile) {
157-
if path.ends_with("mod.rs") {
160+
if path.ends_with("mod.rs") && !path.starts_with("tests") {
158161
let mut mod_file = path.to_path_buf();
159162
mod_file.pop();
160163
mod_file.set_extension("rs");

0 commit comments

Comments
 (0)