Skip to content

Commit 4622203

Browse files
committed
Move configuration to new clippy_config crate
1 parent 033c763 commit 4622203

File tree

89 files changed

+448
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+448
-439
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ name = "clippy-driver"
2121
path = "src/driver.rs"
2222

2323
[dependencies]
24+
clippy_config = { path = "clippy_config" }
2425
clippy_lints = { path = "clippy_lints" }
2526
rustc_tools_util = "0.3.0"
2627
tempfile = { version = "3.2", optional = true }
2728
termize = "0.1"
28-
color-print = "0.3.4" # Sync version with Cargo
29+
color-print = "0.3.4"
2930
anstream = "0.5.0"
3031

3132
[dev-dependencies]
@@ -54,7 +55,7 @@ rustc_tools_util = "0.3.0"
5455
[features]
5556
deny-warnings = ["clippy_lints/deny-warnings"]
5657
integration = ["tempfile"]
57-
internal = ["clippy_lints/internal", "tempfile"]
58+
internal = ["clippy_config/internal", "clippy_lints/internal", "tempfile"]
5859

5960
[package.metadata.rust-analyzer]
6061
# This package uses #[feature(rustc_private)]

book/src/lint_configuration.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ arithmetic-side-effects-allowed = ["SomeType", "AnotherType"]
2626
A type, say `SomeType`, listed in this configuration has the same behavior of
2727
`["SomeType" , "*"], ["*", "SomeType"]` in `arithmetic_side_effects_allowed_binary`.
2828

29-
**Default Value:** `{}` (`rustc_data_structures::fx::FxHashSet<String>`)
29+
**Default Value:** `{}` (`FxHashSet<String>`)
3030

3131
---
3232
**Affected lints:**
@@ -65,7 +65,7 @@ Suppress checking of the passed type names in unary operations like "negation" (
6565
arithmetic-side-effects-allowed-unary = ["SomeType", "AnotherType"]
6666
```
6767

68-
**Default Value:** `{}` (`rustc_data_structures::fx::FxHashSet<String>`)
68+
**Default Value:** `{}` (`FxHashSet<String>`)
6969

7070
---
7171
**Affected lints:**
@@ -100,7 +100,7 @@ Suppress lints whenever the suggested change would cause breakage for other crat
100100
## `msrv`
101101
The minimum rust version that the project supports
102102

103-
**Default Value:** `Msrv { stack: [] }` (`crate::Msrv`)
103+
**Default Value:** `Msrv { stack: [] }` (`Msrv`)
104104

105105
---
106106
**Affected lints:**
@@ -417,7 +417,7 @@ Whether to allow certain wildcard imports (prelude, super in tests).
417417
## `disallowed-macros`
418418
The list of disallowed macros, written as fully qualified paths.
419419

420-
**Default Value:** `[]` (`Vec<crate::utils::conf::DisallowedPath>`)
420+
**Default Value:** `[]` (`Vec<DisallowedPath>`)
421421

422422
---
423423
**Affected lints:**
@@ -427,7 +427,7 @@ The list of disallowed macros, written as fully qualified paths.
427427
## `disallowed-methods`
428428
The list of disallowed methods, written as fully qualified paths.
429429

430-
**Default Value:** `[]` (`Vec<crate::utils::conf::DisallowedPath>`)
430+
**Default Value:** `[]` (`Vec<DisallowedPath>`)
431431

432432
---
433433
**Affected lints:**
@@ -437,7 +437,7 @@ The list of disallowed methods, written as fully qualified paths.
437437
## `disallowed-types`
438438
The list of disallowed types, written as fully qualified paths.
439439

440-
**Default Value:** `[]` (`Vec<crate::utils::conf::DisallowedPath>`)
440+
**Default Value:** `[]` (`Vec<DisallowedPath>`)
441441

442442
---
443443
**Affected lints:**
@@ -468,7 +468,7 @@ Enables verbose mode. Triggers if there is more than one uppercase char next to
468468
Whether the matches should be considered by the lint, and whether there should
469469
be filtering for common types.
470470

471-
**Default Value:** `WellKnownTypes` (`crate::manual_let_else::MatchLintBehaviour`)
471+
**Default Value:** `WellKnownTypes` (`MatchLintBehaviour`)
472472

473473
---
474474
**Affected lints:**
@@ -492,7 +492,7 @@ A `MacroMatcher` can be added like so `{ name = "macro_name", brace = "(" }`. If
492492
could be used with a full path two `MacroMatcher`s have to be added one with the full path
493493
`crate_name::macro_name` and one with just the macro name.
494494

495-
**Default Value:** `[]` (`Vec<crate::nonstandard_macro_braces::MacroMatcher>`)
495+
**Default Value:** `[]` (`Vec<MacroMatcher>`)
496496

497497
---
498498
**Affected lints:**
@@ -502,7 +502,7 @@ could be used with a full path two `MacroMatcher`s have to be added one with the
502502
## `enforced-import-renames`
503503
The list of imports to always rename, a fully qualified path followed by the rename.
504504

505-
**Default Value:** `[]` (`Vec<crate::utils::conf::Rename>`)
505+
**Default Value:** `[]` (`Vec<Rename>`)
506506

507507
---
508508
**Affected lints:**
@@ -544,7 +544,7 @@ For example, `[_, _, _, e, ..]` is a slice pattern with 4 elements.
544544
## `await-holding-invalid-types`
545545

546546

547-
**Default Value:** `[]` (`Vec<crate::utils::conf::DisallowedPath>`)
547+
**Default Value:** `[]` (`Vec<DisallowedPath>`)
548548

549549
---
550550
**Affected lints:**
@@ -694,7 +694,7 @@ Allowed names below the minimum allowed characters. The value `".."` can be used
694694
the list to indicate, that the configured values should be appended to the default
695695
configuration of Clippy. By default, any configuration will replace the default value.
696696

697-
**Default Value:** `{"j", "z", "i", "y", "n", "x", "w"}` (`rustc_data_structures::fx::FxHashSet<String>`)
697+
**Default Value:** `{"j", "z", "i", "y", "n", "x", "w"}` (`FxHashSet<String>`)
698698

699699
---
700700
**Affected lints:**
@@ -755,7 +755,7 @@ be linted.
755755
## `absolute-paths-allowed-crates`
756756
Which crates to allow absolute paths from
757757

758-
**Default Value:** `{}` (`rustc_data_structures::fx::FxHashSet<String>`)
758+
**Default Value:** `{}` (`FxHashSet<String>`)
759759

760760
---
761761
**Affected lints:**
@@ -765,7 +765,7 @@ Which crates to allow absolute paths from
765765
## `allowed-dotfiles`
766766
Additional dotfiles (files or directories starting with a dot) to allow
767767

768-
**Default Value:** `{}` (`rustc_data_structures::fx::FxHashSet<String>`)
768+
**Default Value:** `{}` (`FxHashSet<String>`)
769769

770770
---
771771
**Affected lints:**

clippy_config/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "clippy_config"
3+
version = "0.1.75"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
rustc-semver = "1.1"
10+
serde = { version = "1.0", features = ["derive"] }
11+
toml = "0.7.3"
12+
13+
[features]
14+
deny-warnings = []
15+
internal = []
16+
17+
[package.metadata.rust-analyzer]
18+
# This crate uses #[feature(rustc_private)]
19+
rustc_private = true

clippy_lints/src/utils/conf.rs renamed to clippy_config/src/conf.rs

Lines changed: 41 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//! Read configurations files.
2-
3-
#![allow(clippy::module_name_repetitions)]
4-
1+
use crate::msrvs::Msrv;
2+
use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, Rename};
3+
use crate::ClippyConfiguration;
4+
use rustc_data_structures::fx::FxHashSet;
55
use rustc_session::Session;
66
use rustc_span::{BytePos, Pos, SourceFile, Span, SyntaxContext};
77
use serde::de::{Deserializer, IgnoredAny, IntoDeserializer, MapAccess, Visitor};
@@ -38,37 +38,6 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
3838
const DEFAULT_DISALLOWED_NAMES: &[&str] = &["foo", "baz", "quux"];
3939
const DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS: &[&str] = &["i", "j", "x", "y", "z", "w", "n"];
4040

41-
/// Holds information used by `MISSING_ENFORCED_IMPORT_RENAMES` lint.
42-
#[derive(Clone, Debug, Deserialize)]
43-
pub struct Rename {
44-
pub path: String,
45-
pub rename: String,
46-
}
47-
48-
#[derive(Clone, Debug, Deserialize)]
49-
#[serde(untagged)]
50-
pub enum DisallowedPath {
51-
Simple(String),
52-
WithReason { path: String, reason: Option<String> },
53-
}
54-
55-
impl DisallowedPath {
56-
pub fn path(&self) -> &str {
57-
let (Self::Simple(path) | Self::WithReason { path, .. }) = self;
58-
59-
path
60-
}
61-
62-
pub fn reason(&self) -> Option<String> {
63-
match self {
64-
Self::WithReason {
65-
reason: Some(reason), ..
66-
} => Some(format!("{reason} (from clippy.toml)")),
67-
_ => None,
68-
}
69-
}
70-
}
71-
7241
/// Conf with parse errors
7342
#[derive(Default)]
7443
pub struct TryConf {
@@ -124,6 +93,7 @@ macro_rules! define_Conf {
12493
}
12594

12695
mod defaults {
96+
use super::*;
12797
$(pub fn $name() -> $ty { $default })*
12898
}
12999

@@ -190,31 +160,27 @@ macro_rules! define_Conf {
190160
}
191161
}
192162

193-
pub mod metadata {
194-
use crate::utils::ClippyConfiguration;
195-
196-
macro_rules! wrap_option {
197-
() => (None);
198-
($x:literal) => (Some($x));
199-
}
163+
macro_rules! wrap_option {
164+
() => (None);
165+
($x:literal) => (Some($x));
166+
}
200167

201-
pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
202-
vec![
203-
$(
204-
{
205-
let deprecation_reason = wrap_option!($($dep)?);
206-
207-
ClippyConfiguration::new(
208-
stringify!($name),
209-
stringify!($ty),
210-
format!("{:?}", super::defaults::$name()),
211-
concat!($($doc, '\n',)*),
212-
deprecation_reason,
213-
)
214-
},
215-
)+
216-
]
217-
}
168+
pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
169+
vec![
170+
$(
171+
{
172+
let deprecation_reason = wrap_option!($($dep)?);
173+
174+
ClippyConfiguration::new(
175+
stringify!($name),
176+
stringify!($ty),
177+
format!("{:?}", defaults::$name()),
178+
concat!($($doc, '\n',)*),
179+
deprecation_reason,
180+
)
181+
},
182+
)+
183+
]
218184
}
219185
};
220186
}
@@ -236,7 +202,7 @@ define_Conf! {
236202
///
237203
/// A type, say `SomeType`, listed in this configuration has the same behavior of
238204
/// `["SomeType" , "*"], ["*", "SomeType"]` in `arithmetic_side_effects_allowed_binary`.
239-
(arithmetic_side_effects_allowed: rustc_data_structures::fx::FxHashSet<String> = <_>::default()),
205+
(arithmetic_side_effects_allowed: FxHashSet<String> = <_>::default()),
240206
/// Lint: ARITHMETIC_SIDE_EFFECTS.
241207
///
242208
/// Suppress checking of the passed type pair names in binary operations like addition or
@@ -263,15 +229,15 @@ define_Conf! {
263229
/// ```toml
264230
/// arithmetic-side-effects-allowed-unary = ["SomeType", "AnotherType"]
265231
/// ```
266-
(arithmetic_side_effects_allowed_unary: rustc_data_structures::fx::FxHashSet<String> = <_>::default()),
232+
(arithmetic_side_effects_allowed_unary: FxHashSet<String> = <_>::default()),
267233
/// Lint: ENUM_VARIANT_NAMES, LARGE_TYPES_PASSED_BY_VALUE, TRIVIALLY_COPY_PASS_BY_REF, UNNECESSARY_WRAPS, UNUSED_SELF, UPPER_CASE_ACRONYMS, WRONG_SELF_CONVENTION, BOX_COLLECTION, REDUNDANT_ALLOCATION, RC_BUFFER, VEC_BOX, OPTION_OPTION, LINKEDLIST, RC_MUTEX, UNNECESSARY_BOX_RETURNS, SINGLE_CALL_FN.
268234
///
269235
/// Suppress lints whenever the suggested change would cause breakage for other crates.
270236
(avoid_breaking_exported_api: bool = true),
271237
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE.
272238
///
273239
/// The minimum rust version that the project supports
274-
(msrv: crate::Msrv = crate::Msrv::empty()),
240+
(msrv: Msrv = Msrv::empty()),
275241
/// DEPRECATED LINT: BLACKLISTED_NAME.
276242
///
277243
/// Use the Disallowed Names lint instead
@@ -295,7 +261,7 @@ define_Conf! {
295261
/// The list of disallowed names to lint about. NB: `bar` is not here since it has legitimate uses. The value
296262
/// `".."` can be used as part of the list to indicate that the configured values should be appended to the
297263
/// default configuration of Clippy. By default, any configuration will replace the default value.
298-
(disallowed_names: Vec<String> = super::DEFAULT_DISALLOWED_NAMES.iter().map(ToString::to_string).collect()),
264+
(disallowed_names: Vec<String> = DEFAULT_DISALLOWED_NAMES.iter().map(ToString::to_string).collect()),
299265
/// Lint: SEMICOLON_INSIDE_BLOCK.
300266
///
301267
/// Whether to lint only if it's multiline.
@@ -313,7 +279,7 @@ define_Conf! {
313279
/// * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
314280
///
315281
/// Default list:
316-
(doc_valid_idents: Vec<String> = super::DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string).collect()),
282+
(doc_valid_idents: Vec<String> = DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string).collect()),
317283
/// Lint: TOO_MANY_ARGUMENTS.
318284
///
319285
/// The maximum number of argument a function or method can have
@@ -393,15 +359,15 @@ define_Conf! {
393359
/// Lint: DISALLOWED_MACROS.
394360
///
395361
/// The list of disallowed macros, written as fully qualified paths.
396-
(disallowed_macros: Vec<crate::utils::conf::DisallowedPath> = Vec::new()),
362+
(disallowed_macros: Vec<DisallowedPath> = Vec::new()),
397363
/// Lint: DISALLOWED_METHODS.
398364
///
399365
/// The list of disallowed methods, written as fully qualified paths.
400-
(disallowed_methods: Vec<crate::utils::conf::DisallowedPath> = Vec::new()),
366+
(disallowed_methods: Vec<DisallowedPath> = Vec::new()),
401367
/// Lint: DISALLOWED_TYPES.
402368
///
403369
/// The list of disallowed types, written as fully qualified paths.
404-
(disallowed_types: Vec<crate::utils::conf::DisallowedPath> = Vec::new()),
370+
(disallowed_types: Vec<DisallowedPath> = Vec::new()),
405371
/// Lint: UNREADABLE_LITERAL.
406372
///
407373
/// Should the fraction of a decimal be linted to include separators.
@@ -414,8 +380,7 @@ define_Conf! {
414380
///
415381
/// Whether the matches should be considered by the lint, and whether there should
416382
/// be filtering for common types.
417-
(matches_for_let_else: crate::manual_let_else::MatchLintBehaviour =
418-
crate::manual_let_else::MatchLintBehaviour::WellKnownTypes),
383+
(matches_for_let_else: MatchLintBehaviour = MatchLintBehaviour::WellKnownTypes),
419384
/// Lint: _CARGO_COMMON_METADATA.
420385
///
421386
/// For internal testing only, ignores the current `publish` settings in the Cargo manifest.
@@ -427,11 +392,11 @@ define_Conf! {
427392
/// A `MacroMatcher` can be added like so `{ name = "macro_name", brace = "(" }`. If the macro
428393
/// could be used with a full path two `MacroMatcher`s have to be added one with the full path
429394
/// `crate_name::macro_name` and one with just the macro name.
430-
(standard_macro_braces: Vec<crate::nonstandard_macro_braces::MacroMatcher> = Vec::new()),
395+
(standard_macro_braces: Vec<MacroMatcher> = Vec::new()),
431396
/// Lint: MISSING_ENFORCED_IMPORT_RENAMES.
432397
///
433398
/// The list of imports to always rename, a fully qualified path followed by the rename.
434-
(enforced_import_renames: Vec<crate::utils::conf::Rename> = Vec::new()),
399+
(enforced_import_renames: Vec<Rename> = Vec::new()),
435400
/// Lint: DISALLOWED_SCRIPT_IDENTS.
436401
///
437402
/// The list of unicode scripts allowed to be used in the scope.
@@ -447,7 +412,7 @@ define_Conf! {
447412
/// For example, `[_, _, _, e, ..]` is a slice pattern with 4 elements.
448413
(max_suggested_slice_pattern_length: u64 = 3),
449414
/// Lint: AWAIT_HOLDING_INVALID_TYPE.
450-
(await_holding_invalid_types: Vec<crate::utils::conf::DisallowedPath> = Vec::new()),
415+
(await_holding_invalid_types: Vec<DisallowedPath> = Vec::new()),
451416
/// Lint: LARGE_INCLUDE_FILE.
452417
///
453418
/// The maximum size of a file included via `include_bytes!()` or `include_str!()`, in bytes
@@ -511,8 +476,8 @@ define_Conf! {
511476
/// Allowed names below the minimum allowed characters. The value `".."` can be used as part of
512477
/// the list to indicate, that the configured values should be appended to the default
513478
/// configuration of Clippy. By default, any configuration will replace the default value.
514-
(allowed_idents_below_min_chars: rustc_data_structures::fx::FxHashSet<String> =
515-
super::DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string).collect()),
479+
(allowed_idents_below_min_chars: FxHashSet<String> =
480+
DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string).collect()),
516481
/// Lint: MIN_IDENT_CHARS.
517482
///
518483
/// Minimum chars an ident can have, anything below or equal to this will be linted.
@@ -537,13 +502,11 @@ define_Conf! {
537502
/// Lint: ABSOLUTE_PATHS.
538503
///
539504
/// Which crates to allow absolute paths from
540-
(absolute_paths_allowed_crates: rustc_data_structures::fx::FxHashSet<String> =
541-
rustc_data_structures::fx::FxHashSet::default()),
505+
(absolute_paths_allowed_crates: FxHashSet<String> = FxHashSet::default()),
542506
/// Lint: PATH_ENDS_WITH_EXT.
543507
///
544508
/// Additional dotfiles (files or directories starting with a dot) to allow
545-
(allowed_dotfiles: rustc_data_structures::fx::FxHashSet<String> =
546-
rustc_data_structures::fx::FxHashSet::default()),
509+
(allowed_dotfiles: FxHashSet<String> = FxHashSet::default()),
547510
/// Lint: EXPLICIT_ITER_LOOP
548511
///
549512
/// Whether to recommend using implicit into iter for reborrowed values.

0 commit comments

Comments
 (0)