Allow use super::*;
in test modules
#5554
Labels
C-enhancement
Category: Enhancement of lints, like adding more cases or adding help messages
good-first-issue
These issues are a good way to get started with Clippy
Current behavior:
Using
use super::*;
in a test module throws a warning in pedantic mode:Expected behavior:
No warning when
use super::*;
is used in a test module.Reasoning:
Using a wildcard import in test modules to bring in everything from the (parent) module being tested seems to be a very common idiom in Rust. It's recommended in The Book, it's more common in the standard library than explicitly-listed imports, with the same bring true in a sample of commonly-used crates.
Warning on this seems counter-productive - forcing explicit imports introduces a lot of additional friction to writing tests. For the first attempt at writing tests you could use a wildcard import and then quickfix it to explicitly import, but any future tests written in that module will still require hopping up to the
use
statement and manually plugging in everything needed from the parent module. That's not the end of the world of course, but I'm always wary of anything that introduces unnecessary friction to the act of writing tests.I think it makes a lot of sense to allow
use super::*;
in tests, in the same way prelude::* imports are allowed. Something along the lines ofif current_module is [cfg(test)] and current_module_name matches "test[s]" and import is "super::*", do not warn
.I'm happy to put up a pull request to implement this, if it sounds like a reasonable idea. I can reason from the above code how to match on "super", but I'd need some guidance on how to find the name of the current module and/or how to check for
#[cfg(test)]
.The text was updated successfully, but these errors were encountered: