add more test cases & improve docs & replace Vec with FxHashSet for segments
This commit is contained in:
parent
d02df12bd5
commit
314bddee95
9 changed files with 92 additions and 14 deletions
|
|
@ -101,11 +101,11 @@ declare_clippy_lint! {
|
|||
pub struct WildcardImports {
|
||||
warn_on_all: bool,
|
||||
test_modules_deep: u32,
|
||||
ignored_segments: Vec<String>,
|
||||
ignored_segments: FxHashSet<String>,
|
||||
}
|
||||
|
||||
impl WildcardImports {
|
||||
pub fn new(warn_on_all: bool, ignored_wildcard_imports: Vec<String>) -> Self {
|
||||
pub fn new(warn_on_all: bool, ignored_wildcard_imports: FxHashSet<String>) -> Self {
|
||||
Self {
|
||||
warn_on_all,
|
||||
test_modules_deep: 0,
|
||||
|
|
@ -212,10 +212,8 @@ fn is_super_only_import(segments: &[PathSegment<'_>]) -> bool {
|
|||
|
||||
// Allow skipping imports containing user configured segments,
|
||||
// i.e. "...::utils::...::*" if user put `ignored-wildcard-imports = ["utils"]` in `Clippy.toml`
|
||||
fn is_ignored_via_config(segments: &[PathSegment<'_>], ignored_segments: &[String]) -> bool {
|
||||
let segments_set: FxHashSet<&str> = segments.iter().map(|s| s.ident.as_str()).collect();
|
||||
let ignored_set: FxHashSet<&str> = ignored_segments.iter().map(String::as_str).collect();
|
||||
fn is_ignored_via_config(segments: &[PathSegment<'_>], ignored_segments: &FxHashSet<String>) -> bool {
|
||||
// segment matching need to be exact instead of using 'contains', in case user unintentionaly put
|
||||
// a single character in the config thus skipping most of the warnings.
|
||||
segments_set.intersection(&ignored_set).next().is_some()
|
||||
segments.iter().any(|seg| ignored_segments.contains(seg.ident.as_str()))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue