Skip to content

Commit 46dd826

Browse files
committedFeb 2, 2024
rename conf option to allowed_wildcard_imports
1 parent 314bdde commit 46dd826

File tree

8 files changed

+41
-17
lines changed

8 files changed

+41
-17
lines changed
 

Diff for: ‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5823,4 +5823,5 @@ Released 2018-09-13
58235823
[`check-private-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items
58245824
[`pub-underscore-fields-behavior`]: https://doc.rust-lang.org/clippy/lint_configuration.html#pub-underscore-fields-behavior
58255825
[`allow-comparison-to-zero`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-comparison-to-zero
5826+
[`allowed-wildcard-imports`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-wildcard-imports
58265827
<!-- end autogenerated links to configuration documentation -->

Diff for: ‎book/src/lint_configuration.md

+22
Original file line numberDiff line numberDiff line change
@@ -838,3 +838,25 @@ Don't lint when comparing the result of a modulo operation to zero.
838838
* [`modulo_arithmetic`](https://rust-lang.github.io/rust-clippy/master/index.html#modulo_arithmetic)
839839

840840

841+
## `allowed-wildcard-imports`
842+
List of path segments allowed to have wildcard imports.
843+
844+
#### Example
845+
846+
```toml
847+
allowed-wildcard-imports = [ "utils", "common" ]
848+
```
849+
850+
#### Noteworthy
851+
852+
1. This configuration has no effects if used with `warn_on_all_wildcard_imports = true`.
853+
2. Paths with any segment that containing the word 'prelude'
854+
are already allowed by default.
855+
856+
**Default Value:** `[]`
857+
858+
---
859+
**Affected lints:**
860+
* [`wildcard_imports`](https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports)
861+
862+

Diff for: ‎clippy_config/src/conf.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -573,20 +573,20 @@ define_Conf! {
573573
(allow_comparison_to_zero: bool = true),
574574
/// Lint: WILDCARD_IMPORTS.
575575
///
576-
/// List of path segments to ignore when checking wildcard imports.
576+
/// List of path segments allowed to have wildcard imports.
577577
///
578578
/// #### Example
579579
///
580580
/// ```toml
581-
/// ignored-wildcard-imports = [ "utils", "common" ]
581+
/// allowed-wildcard-imports = [ "utils", "common" ]
582582
/// ```
583583
///
584584
/// #### Noteworthy
585585
///
586586
/// 1. This configuration has no effects if used with `warn_on_all_wildcard_imports = true`.
587587
/// 2. Paths with any segment that containing the word 'prelude'
588-
/// are already ignored by default.
589-
(ignored_wildcard_imports: FxHashSet<String> = FxHashSet::default()),
588+
/// are already allowed by default.
589+
(allowed_wildcard_imports: FxHashSet<String> = FxHashSet::default()),
590590
}
591591

592592
/// Search for the configuration file.

Diff for: ‎clippy_lints/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
524524
ref allowed_dotfiles,
525525
ref allowed_idents_below_min_chars,
526526
ref allowed_scripts,
527+
ref allowed_wildcard_imports,
527528
ref arithmetic_side_effects_allowed_binary,
528529
ref arithmetic_side_effects_allowed_unary,
529530
ref arithmetic_side_effects_allowed,
@@ -545,7 +546,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
545546
excessive_nesting_threshold,
546547
future_size_threshold,
547548
ref ignore_interior_mutability,
548-
ref ignored_wildcard_imports,
549549
large_error_threshold,
550550
literal_representation_threshold,
551551
matches_for_let_else,
@@ -880,7 +880,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
880880
store.register_late_pass(move |_| {
881881
Box::new(wildcard_imports::WildcardImports::new(
882882
warn_on_all_wildcard_imports,
883-
ignored_wildcard_imports.clone(),
883+
allowed_wildcard_imports.clone(),
884884
))
885885
});
886886
store.register_late_pass(|_| Box::<redundant_pub_crate::RedundantPubCrate>::default());

Diff for: ‎clippy_lints/src/wildcard_imports.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ declare_clippy_lint! {
101101
pub struct WildcardImports {
102102
warn_on_all: bool,
103103
test_modules_deep: u32,
104-
ignored_segments: FxHashSet<String>,
104+
allowed_segments: FxHashSet<String>,
105105
}
106106

107107
impl WildcardImports {
108-
pub fn new(warn_on_all: bool, ignored_wildcard_imports: FxHashSet<String>) -> Self {
108+
pub fn new(warn_on_all: bool, allowed_wildcard_imports: FxHashSet<String>) -> Self {
109109
Self {
110110
warn_on_all,
111111
test_modules_deep: 0,
112-
ignored_segments: ignored_wildcard_imports,
112+
allowed_segments: allowed_wildcard_imports,
113113
}
114114
}
115115
}
@@ -193,7 +193,7 @@ impl WildcardImports {
193193
item.span.from_expansion()
194194
|| is_prelude_import(segments)
195195
|| (is_super_only_import(segments) && self.test_modules_deep > 0)
196-
|| is_ignored_via_config(segments, &self.ignored_segments)
196+
|| is_allowed_via_config(segments, &self.allowed_segments)
197197
}
198198
}
199199

@@ -211,9 +211,9 @@ fn is_super_only_import(segments: &[PathSegment<'_>]) -> bool {
211211
}
212212

213213
// Allow skipping imports containing user configured segments,
214-
// i.e. "...::utils::...::*" if user put `ignored-wildcard-imports = ["utils"]` in `Clippy.toml`
215-
fn is_ignored_via_config(segments: &[PathSegment<'_>], ignored_segments: &FxHashSet<String>) -> bool {
214+
// i.e. "...::utils::...::*" if user put `allowed-wildcard-imports = ["utils"]` in `Clippy.toml`
215+
fn is_allowed_via_config(segments: &[PathSegment<'_>], allowed_segments: &FxHashSet<String>) -> bool {
216216
// segment matching need to be exact instead of using 'contains', in case user unintentionaly put
217217
// a single character in the config thus skipping most of the warnings.
218-
segments.iter().any(|seg| ignored_segments.contains(seg.ident.as_str()))
218+
segments.iter().any(|seg| allowed_segments.contains(seg.ident.as_str()))
219219
}

Diff for: ‎tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
1515
allowed-duplicate-crates
1616
allowed-idents-below-min-chars
1717
allowed-scripts
18+
allowed-wildcard-imports
1819
arithmetic-side-effects-allowed
1920
arithmetic-side-effects-allowed-binary
2021
arithmetic-side-effects-allowed-unary
@@ -39,7 +40,6 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
3940
excessive-nesting-threshold
4041
future-size-threshold
4142
ignore-interior-mutability
42-
ignored-wildcard-imports
4343
large-error-threshold
4444
literal-representation-threshold
4545
matches-for-let-else
@@ -94,6 +94,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
9494
allowed-duplicate-crates
9595
allowed-idents-below-min-chars
9696
allowed-scripts
97+
allowed-wildcard-imports
9798
arithmetic-side-effects-allowed
9899
arithmetic-side-effects-allowed-binary
99100
arithmetic-side-effects-allowed-unary
@@ -118,7 +119,6 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
118119
excessive-nesting-threshold
119120
future-size-threshold
120121
ignore-interior-mutability
121-
ignored-wildcard-imports
122122
large-error-threshold
123123
literal-representation-threshold
124124
matches-for-let-else
@@ -173,6 +173,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
173173
allowed-duplicate-crates
174174
allowed-idents-below-min-chars
175175
allowed-scripts
176+
allowed-wildcard-imports
176177
arithmetic-side-effects-allowed
177178
arithmetic-side-effects-allowed-binary
178179
arithmetic-side-effects-allowed-unary

Diff for: ‎tests/ui-toml/wildcard_imports/clippy.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
warn-on-all-wildcard-imports = true
22

33
# This should be ignored since `warn-on-all-wildcard-imports` has higher precedence
4-
ignored-wildcard-imports = ["utils"]
4+
allowed-wildcard-imports = ["utils"]

Diff for: ‎tests/ui-toml/wildcard_imports_whitelist/clippy.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ignored-wildcard-imports = ["utils"]
1+
allowed-wildcard-imports = ["utils"]

0 commit comments

Comments
 (0)