about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--book/src/lint_configuration.md22
-rw-r--r--clippy_config/src/conf.rs8
-rw-r--r--clippy_lints/src/lib.rs4
-rw-r--r--clippy_lints/src/wildcard_imports.rs14
-rw-r--r--tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr5
-rw-r--r--tests/ui-toml/wildcard_imports/clippy.toml2
-rw-r--r--tests/ui-toml/wildcard_imports_whitelist/clippy.toml2
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
 <!-- end autogenerated links to configuration documentation -->
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 @@ define_Conf! {
     (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<String> = FxHashSet::default()),
+    /// are already allowed by default.
+    (allowed_wildcard_imports: FxHashSet<String> = 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::<redundant_pub_crate::RedundantPubCrate>::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 @@ declare_clippy_lint! {
 pub struct WildcardImports {
     warn_on_all: bool,
     test_modules_deep: u32,
-    ignored_segments: FxHashSet<String>,
+    allowed_segments: FxHashSet<String>,
 }
 
 impl WildcardImports {
-    pub fn new(warn_on_all: bool, ignored_wildcard_imports: FxHashSet<String>) -> Self {
+    pub fn new(warn_on_all: bool, allowed_wildcard_imports: FxHashSet<String>) -> Self {
         Self {
             warn_on_all,
             test_modules_deep: 0,
-            ignored_segments: ignored_wildcard_imports,
+            allowed_segments: allowed_wildcard_imports,
         }
     }
 }
@@ -193,7 +193,7 @@ impl WildcardImports {
         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<String>) -> bool {
+// i.e. "...::utils::...::*" if user put `allowed-wildcard-imports = ["utils"]` in `Clippy.toml`
+fn is_allowed_via_config(segments: &[PathSegment<'_>], allowed_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.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"]