From d02df12bd5e9ad2016328786d6a117afe0f1604a Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Mon, 18 Dec 2023 17:57:22 +0800 Subject: [PATCH 1/3] add configuration for [`wildcard_imports`] to ignore certain imports --- clippy_config/src/conf.rs | 5 +++++ clippy_lints/src/lib.rs | 8 +++++++- clippy_lints/src/wildcard_imports.rs | 18 ++++++++++++++++-- .../toml_unknown_key/conf_unknown_key.stderr | 2 ++ .../wildcard_imports_whitelist/clippy.toml | 1 + .../wildcard_imports.fixed | 18 ++++++++++++++++++ .../wildcard_imports.rs | 18 ++++++++++++++++++ .../wildcard_imports.stderr | 11 +++++++++++ 8 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 tests/ui-toml/wildcard_imports_whitelist/clippy.toml create mode 100644 tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.fixed create mode 100644 tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.rs create mode 100644 tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.stderr diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 8b45f250b10..e4e512482ac 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -571,6 +571,11 @@ pub fn get_configuration_metadata() -> Vec { /// /// Don't lint when comparing the result of a modulo operation to zero. (allow_comparison_to_zero: bool = true), + /// Lint: WILDCARD_IMPORTS. + /// + /// List of path segments to ignore when checking wildcard imports, + /// could get overrided by `warn_on_all_wildcard_imports`. + (ignored_wildcard_imports: Vec = Vec::new()), } /// Search for the configuration file. diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 7da916ade2a..678058a5411 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -545,6 +545,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { excessive_nesting_threshold, future_size_threshold, ref ignore_interior_mutability, + ref ignored_wildcard_imports, large_error_threshold, literal_representation_threshold, matches_for_let_else, @@ -876,7 +877,12 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { )) }); store.register_early_pass(|| Box::new(option_env_unwrap::OptionEnvUnwrap)); - store.register_late_pass(move |_| Box::new(wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports))); + store.register_late_pass(move |_| { + Box::new(wildcard_imports::WildcardImports::new( + warn_on_all_wildcard_imports, + ignored_wildcard_imports.clone(), + )) + }); store.register_late_pass(|_| Box::::default()); store.register_late_pass(|_| Box::new(unnamed_address::UnnamedAddress)); store.register_late_pass(|_| Box::>::default()); diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index b82bd1d7e7c..4eb45e6f8da 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -1,6 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::is_test_module_or_function; use clippy_utils::source::{snippet, snippet_with_applicability}; +use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Item, ItemKind, PathSegment, UseKind}; @@ -100,13 +101,15 @@ pub struct WildcardImports { warn_on_all: bool, test_modules_deep: u32, + ignored_segments: Vec, } impl WildcardImports { - pub fn new(warn_on_all: bool) -> Self { + pub fn new(warn_on_all: bool, ignored_wildcard_imports: Vec) -> Self { Self { warn_on_all, test_modules_deep: 0, + ignored_segments: ignored_wildcard_imports, } } } @@ -190,6 +193,7 @@ fn check_exceptions(&self, item: &Item<'_>, segments: &[PathSegment<'_>]) -> boo item.span.from_expansion() || is_prelude_import(segments) || (is_super_only_import(segments) && self.test_modules_deep > 0) + || is_ignored_via_config(segments, &self.ignored_segments) } } @@ -198,10 +202,20 @@ fn check_exceptions(&self, item: &Item<'_>, segments: &[PathSegment<'_>]) -> boo fn is_prelude_import(segments: &[PathSegment<'_>]) -> bool { segments .iter() - .any(|ps| ps.ident.name.as_str().contains(sym::prelude.as_str())) + .any(|ps| ps.ident.as_str().contains(sym::prelude.as_str())) } // Allow "super::*" imports in tests. fn is_super_only_import(segments: &[PathSegment<'_>]) -> bool { segments.len() == 1 && segments[0].ident.name == kw::Super } + +// 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(); + // 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() +} diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index 24fdfd945bd..b1e000abec8 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -39,6 +39,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect excessive-nesting-threshold future-size-threshold ignore-interior-mutability + ignored-wildcard-imports large-error-threshold literal-representation-threshold matches-for-let-else @@ -117,6 +118,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect excessive-nesting-threshold future-size-threshold ignore-interior-mutability + ignored-wildcard-imports large-error-threshold literal-representation-threshold matches-for-let-else diff --git a/tests/ui-toml/wildcard_imports_whitelist/clippy.toml b/tests/ui-toml/wildcard_imports_whitelist/clippy.toml new file mode 100644 index 00000000000..1d28cac588b --- /dev/null +++ b/tests/ui-toml/wildcard_imports_whitelist/clippy.toml @@ -0,0 +1 @@ +ignored-wildcard-imports = ["utils"] diff --git a/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.fixed b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.fixed new file mode 100644 index 00000000000..5ef30b054b3 --- /dev/null +++ b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.fixed @@ -0,0 +1,18 @@ +#![warn(clippy::wildcard_imports)] + +mod utils { + pub fn print() {} +} + +mod utils_plus { + pub fn do_something() {} +} + +use utils::*; +use utils_plus::do_something; +//~^ ERROR: usage of wildcard import + +fn main() { + print(); + do_something(); +} diff --git a/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.rs b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.rs new file mode 100644 index 00000000000..5ea91a8d70a --- /dev/null +++ b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.rs @@ -0,0 +1,18 @@ +#![warn(clippy::wildcard_imports)] + +mod utils { + pub fn print() {} +} + +mod utils_plus { + pub fn do_something() {} +} + +use utils::*; +use utils_plus::*; +//~^ ERROR: usage of wildcard import + +fn main() { + print(); + do_something(); +} diff --git a/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.stderr b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.stderr new file mode 100644 index 00000000000..15f522cb5af --- /dev/null +++ b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.stderr @@ -0,0 +1,11 @@ +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:12:5 + | +LL | use utils_plus::*; + | ^^^^^^^^^^^^^ help: try: `utils_plus::do_something` + | + = note: `-D clippy::wildcard-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` + +error: aborting due to 1 previous error + From 314bddee95f88a405ec4b44db5576e3745ee1699 Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Mon, 29 Jan 2024 11:29:15 +0800 Subject: [PATCH 2/3] add more test cases & improve docs & replace `Vec` with `FxHashSet` for segments --- clippy_config/src/conf.rs | 17 +++++++++++++--- clippy_lints/src/wildcard_imports.rs | 10 ++++------ tests/ui-toml/wildcard_imports/clippy.toml | 3 +++ .../wildcard_imports/wildcard_imports.fixed | 19 ++++++++++++++++++ .../wildcard_imports/wildcard_imports.rs | 19 ++++++++++++++++++ .../wildcard_imports/wildcard_imports.stderr | 20 +++++++++++++++---- .../wildcard_imports.fixed | 8 ++++++++ .../wildcard_imports.rs | 8 ++++++++ .../wildcard_imports.stderr | 2 +- 9 files changed, 92 insertions(+), 14 deletions(-) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index e4e512482ac..d03f805e2fc 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -573,9 +573,20 @@ pub fn get_configuration_metadata() -> Vec { (allow_comparison_to_zero: bool = true), /// Lint: WILDCARD_IMPORTS. /// - /// List of path segments to ignore when checking wildcard imports, - /// could get overrided by `warn_on_all_wildcard_imports`. - (ignored_wildcard_imports: Vec = Vec::new()), + /// List of path segments to ignore when checking wildcard imports. + /// + /// #### Example + /// + /// ```toml + /// ignored-wildcard-imports = [ "utils", "common" ] + /// ``` + /// + /// #### Noteworthy + /// + /// 1. This configuration has no effects if used with `warn_on_all_wildcard_imports = true`. + /// 2. Paths with any segment that containing the word 'prelude' + /// are already ignored by default. + (ignored_wildcard_imports: FxHashSet = FxHashSet::default()), } /// Search for the configuration file. diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 4eb45e6f8da..7318ffc9587 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -101,11 +101,11 @@ pub struct WildcardImports { warn_on_all: bool, test_modules_deep: u32, - ignored_segments: Vec, + ignored_segments: FxHashSet, } impl WildcardImports { - pub fn new(warn_on_all: bool, ignored_wildcard_imports: Vec) -> Self { + pub fn new(warn_on_all: bool, ignored_wildcard_imports: FxHashSet) -> 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) -> 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())) } diff --git a/tests/ui-toml/wildcard_imports/clippy.toml b/tests/ui-toml/wildcard_imports/clippy.toml index 875aaeef6c9..56a945e48bb 100644 --- a/tests/ui-toml/wildcard_imports/clippy.toml +++ b/tests/ui-toml/wildcard_imports/clippy.toml @@ -1 +1,4 @@ warn-on-all-wildcard-imports = true + +# This should be ignored since `warn-on-all-wildcard-imports` has higher precedence +ignored-wildcard-imports = ["utils"] diff --git a/tests/ui-toml/wildcard_imports/wildcard_imports.fixed b/tests/ui-toml/wildcard_imports/wildcard_imports.fixed index 1752f48856c..af72d6be0e0 100644 --- a/tests/ui-toml/wildcard_imports/wildcard_imports.fixed +++ b/tests/ui-toml/wildcard_imports/wildcard_imports.fixed @@ -3,9 +3,28 @@ mod prelude { pub const FOO: u8 = 1; } + +mod utils { + pub const BAR: u8 = 1; + pub fn print() {} +} + +mod my_crate { + pub mod utils { + pub fn my_util_fn() {} + } +} + +use utils::{BAR, print}; +//~^ ERROR: usage of wildcard import +use my_crate::utils::my_util_fn; +//~^ ERROR: usage of wildcard import use prelude::FOO; //~^ ERROR: usage of wildcard import fn main() { let _ = FOO; + let _ = BAR; + print(); + my_util_fn(); } diff --git a/tests/ui-toml/wildcard_imports/wildcard_imports.rs b/tests/ui-toml/wildcard_imports/wildcard_imports.rs index 331c2c59c22..91009dd8835 100644 --- a/tests/ui-toml/wildcard_imports/wildcard_imports.rs +++ b/tests/ui-toml/wildcard_imports/wildcard_imports.rs @@ -3,9 +3,28 @@ mod prelude { pub const FOO: u8 = 1; } + +mod utils { + pub const BAR: u8 = 1; + pub fn print() {} +} + +mod my_crate { + pub mod utils { + pub fn my_util_fn() {} + } +} + +use utils::*; +//~^ ERROR: usage of wildcard import +use my_crate::utils::*; +//~^ ERROR: usage of wildcard import use prelude::*; //~^ ERROR: usage of wildcard import fn main() { let _ = FOO; + let _ = BAR; + print(); + my_util_fn(); } diff --git a/tests/ui-toml/wildcard_imports/wildcard_imports.stderr b/tests/ui-toml/wildcard_imports/wildcard_imports.stderr index f11fda6a0c6..a733d786d0e 100644 --- a/tests/ui-toml/wildcard_imports/wildcard_imports.stderr +++ b/tests/ui-toml/wildcard_imports/wildcard_imports.stderr @@ -1,11 +1,23 @@ error: usage of wildcard import - --> $DIR/wildcard_imports.rs:6:5 + --> $DIR/wildcard_imports.rs:18:5 | -LL | use prelude::*; - | ^^^^^^^^^^ help: try: `prelude::FOO` +LL | use utils::*; + | ^^^^^^^^ help: try: `utils::{BAR, print}` | = note: `-D clippy::wildcard-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` -error: aborting due to 1 previous error +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:20:5 + | +LL | use my_crate::utils::*; + | ^^^^^^^^^^^^^^^^^^ help: try: `my_crate::utils::my_util_fn` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:22:5 + | +LL | use prelude::*; + | ^^^^^^^^^^ help: try: `prelude::FOO` + +error: aborting due to 3 previous errors diff --git a/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.fixed b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.fixed index 5ef30b054b3..d539525c45e 100644 --- a/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.fixed +++ b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.fixed @@ -8,11 +8,19 @@ mod utils_plus { pub fn do_something() {} } +mod my_crate { + pub mod utils { + pub fn my_util_fn() {} + } +} + +use my_crate::utils::*; use utils::*; use utils_plus::do_something; //~^ ERROR: usage of wildcard import fn main() { print(); + my_util_fn(); do_something(); } diff --git a/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.rs b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.rs index 5ea91a8d70a..9169d16a08b 100644 --- a/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.rs +++ b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.rs @@ -8,11 +8,19 @@ mod utils_plus { pub fn do_something() {} } +mod my_crate { + pub mod utils { + pub fn my_util_fn() {} + } +} + +use my_crate::utils::*; use utils::*; use utils_plus::*; //~^ ERROR: usage of wildcard import fn main() { print(); + my_util_fn(); do_something(); } diff --git a/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.stderr b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.stderr index 15f522cb5af..12c2f9cbada 100644 --- a/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.stderr +++ b/tests/ui-toml/wildcard_imports_whitelist/wildcard_imports.stderr @@ -1,5 +1,5 @@ error: usage of wildcard import - --> $DIR/wildcard_imports.rs:12:5 + --> $DIR/wildcard_imports.rs:19:5 | LL | use utils_plus::*; | ^^^^^^^^^^^^^ help: try: `utils_plus::do_something` From 46dd8263a08a09e522d6990d11a3aa5e58702a50 Mon Sep 17 00:00:00 2001 From: J-ZhengLi Date: Fri, 2 Feb 2024 09:22:42 +0800 Subject: [PATCH 3/3] rename conf option to `allowed_wildcard_imports` --- CHANGELOG.md | 1 + book/src/lint_configuration.md | 22 +++++++++++++++++++ clippy_config/src/conf.rs | 8 +++---- clippy_lints/src/lib.rs | 4 ++-- clippy_lints/src/wildcard_imports.rs | 14 ++++++------ .../toml_unknown_key/conf_unknown_key.stderr | 5 +++-- tests/ui-toml/wildcard_imports/clippy.toml | 2 +- .../wildcard_imports_whitelist/clippy.toml | 2 +- 8 files changed, 41 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 471163499e5..c4cddd0b4b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5823,4 +5823,5 @@ Released 2018-09-13 [`check-private-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items [`pub-underscore-fields-behavior`]: https://doc.rust-lang.org/clippy/lint_configuration.html#pub-underscore-fields-behavior [`allow-comparison-to-zero`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-comparison-to-zero +[`allowed-wildcard-imports`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-wildcard-imports diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index 1b321b8bcb8..669cdb0735d 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -838,3 +838,25 @@ Don't lint when comparing the result of a modulo operation to zero. * [`modulo_arithmetic`](https://rust-lang.github.io/rust-clippy/master/index.html#modulo_arithmetic) +## `allowed-wildcard-imports` +List of path segments allowed to have wildcard imports. + +#### Example + +```toml +allowed-wildcard-imports = [ "utils", "common" ] +``` + +#### Noteworthy + +1. This configuration has no effects if used with `warn_on_all_wildcard_imports = true`. +2. Paths with any segment that containing the word 'prelude' +are already allowed by default. + +**Default Value:** `[]` + +--- +**Affected lints:** +* [`wildcard_imports`](https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports) + + diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index d03f805e2fc..a7a81b6f421 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -573,20 +573,20 @@ pub fn get_configuration_metadata() -> Vec { (allow_comparison_to_zero: bool = true), /// Lint: WILDCARD_IMPORTS. /// - /// List of path segments to ignore when checking wildcard imports. + /// List of path segments allowed to have wildcard imports. /// /// #### Example /// /// ```toml - /// ignored-wildcard-imports = [ "utils", "common" ] + /// allowed-wildcard-imports = [ "utils", "common" ] /// ``` /// /// #### Noteworthy /// /// 1. This configuration has no effects if used with `warn_on_all_wildcard_imports = true`. /// 2. Paths with any segment that containing the word 'prelude' - /// are already ignored by default. - (ignored_wildcard_imports: FxHashSet = FxHashSet::default()), + /// are already allowed by default. + (allowed_wildcard_imports: FxHashSet = FxHashSet::default()), } /// Search for the configuration file. diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 678058a5411..5636f46b22f 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -524,6 +524,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { ref allowed_dotfiles, ref allowed_idents_below_min_chars, ref allowed_scripts, + ref allowed_wildcard_imports, ref arithmetic_side_effects_allowed_binary, ref arithmetic_side_effects_allowed_unary, ref arithmetic_side_effects_allowed, @@ -545,7 +546,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { excessive_nesting_threshold, future_size_threshold, ref ignore_interior_mutability, - ref ignored_wildcard_imports, large_error_threshold, literal_representation_threshold, matches_for_let_else, @@ -880,7 +880,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(move |_| { Box::new(wildcard_imports::WildcardImports::new( warn_on_all_wildcard_imports, - ignored_wildcard_imports.clone(), + allowed_wildcard_imports.clone(), )) }); store.register_late_pass(|_| Box::::default()); diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 7318ffc9587..5410e8ac117 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -101,15 +101,15 @@ pub struct WildcardImports { warn_on_all: bool, test_modules_deep: u32, - ignored_segments: FxHashSet, + allowed_segments: FxHashSet, } impl WildcardImports { - pub fn new(warn_on_all: bool, ignored_wildcard_imports: FxHashSet) -> Self { + pub fn new(warn_on_all: bool, allowed_wildcard_imports: FxHashSet) -> Self { Self { warn_on_all, test_modules_deep: 0, - ignored_segments: ignored_wildcard_imports, + allowed_segments: allowed_wildcard_imports, } } } @@ -193,7 +193,7 @@ fn check_exceptions(&self, item: &Item<'_>, segments: &[PathSegment<'_>]) -> boo item.span.from_expansion() || is_prelude_import(segments) || (is_super_only_import(segments) && self.test_modules_deep > 0) - || is_ignored_via_config(segments, &self.ignored_segments) + || is_allowed_via_config(segments, &self.allowed_segments) } } @@ -211,9 +211,9 @@ 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: &FxHashSet) -> bool { +// i.e. "...::utils::...::*" if user put `allowed-wildcard-imports = ["utils"]` in `Clippy.toml` +fn is_allowed_via_config(segments: &[PathSegment<'_>], allowed_segments: &FxHashSet) -> 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.iter().any(|seg| ignored_segments.contains(seg.ident.as_str())) + segments.iter().any(|seg| allowed_segments.contains(seg.ident.as_str())) } diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index b1e000abec8..f097d2503e1 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -15,6 +15,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect allowed-duplicate-crates allowed-idents-below-min-chars allowed-scripts + allowed-wildcard-imports arithmetic-side-effects-allowed arithmetic-side-effects-allowed-binary arithmetic-side-effects-allowed-unary @@ -39,7 +40,6 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect excessive-nesting-threshold future-size-threshold ignore-interior-mutability - ignored-wildcard-imports large-error-threshold literal-representation-threshold matches-for-let-else @@ -94,6 +94,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect allowed-duplicate-crates allowed-idents-below-min-chars allowed-scripts + allowed-wildcard-imports arithmetic-side-effects-allowed arithmetic-side-effects-allowed-binary arithmetic-side-effects-allowed-unary @@ -118,7 +119,6 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect excessive-nesting-threshold future-size-threshold ignore-interior-mutability - ignored-wildcard-imports large-error-threshold literal-representation-threshold matches-for-let-else @@ -173,6 +173,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni allowed-duplicate-crates allowed-idents-below-min-chars allowed-scripts + allowed-wildcard-imports arithmetic-side-effects-allowed arithmetic-side-effects-allowed-binary arithmetic-side-effects-allowed-unary diff --git a/tests/ui-toml/wildcard_imports/clippy.toml b/tests/ui-toml/wildcard_imports/clippy.toml index 56a945e48bb..68815c1756a 100644 --- a/tests/ui-toml/wildcard_imports/clippy.toml +++ b/tests/ui-toml/wildcard_imports/clippy.toml @@ -1,4 +1,4 @@ warn-on-all-wildcard-imports = true # This should be ignored since `warn-on-all-wildcard-imports` has higher precedence -ignored-wildcard-imports = ["utils"] +allowed-wildcard-imports = ["utils"] diff --git a/tests/ui-toml/wildcard_imports_whitelist/clippy.toml b/tests/ui-toml/wildcard_imports_whitelist/clippy.toml index 1d28cac588b..6b7882e64a8 100644 --- a/tests/ui-toml/wildcard_imports_whitelist/clippy.toml +++ b/tests/ui-toml/wildcard_imports_whitelist/clippy.toml @@ -1 +1 @@ -ignored-wildcard-imports = ["utils"] +allowed-wildcard-imports = ["utils"]