From 857d9f15da507adbc3e59560f3c15568cd0ae0e5 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sun, 2 May 2021 16:56:46 -0500 Subject: [PATCH 1/3] Fix error punctuation --- clippy_lints/src/utils/conf.rs | 2 +- tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 747d92dd742..aeca5b9ccce 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -102,7 +102,7 @@ define_Conf! { /// Lint: COGNITIVE_COMPLEXITY. The maximum cognitive complexity a function can have (cognitive_complexity_threshold: u64 = 25), /// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY. Use the Cognitive Complexity lint instead. - #[conf_deprecated("Please use `cognitive-complexity-threshold` instead.")] + #[conf_deprecated("Please use `cognitive-complexity-threshold` instead")] (cyclomatic_complexity_threshold: Option), /// Lint: DOC_MARKDOWN. The list of words this lint should not consider as identifiers needing ticks (doc_valid_idents: Vec = [ diff --git a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr index 8bf9fe64c6d..90021a034a3 100644 --- a/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr +++ b/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr @@ -1,4 +1,4 @@ -error: error reading Clippy's configuration file `$DIR/clippy.toml`: deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead. +error: error reading Clippy's configuration file `$DIR/clippy.toml`: deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead error: aborting due to previous error From 499813026f1e84456c9a108b249ed1005c624181 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sun, 2 May 2021 17:50:22 -0500 Subject: [PATCH 2/3] Fix config parsing --- clippy_lints/src/utils/conf.rs | 21 ++++++++++----------- util/lintlib.py | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index aeca5b9ccce..dc079663fc9 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -28,7 +28,7 @@ macro_rules! define_Conf { ($( #[$doc:meta] $(#[conf_deprecated($dep:literal)])? - ($name:ident: $ty:ty $(= $default:expr)?), + ($name:ident: $ty:ty = $default:expr), )*) => { /// Clippy lint configuration pub struct Conf { @@ -36,7 +36,7 @@ macro_rules! define_Conf { } mod defaults { - $(pub fn $name() -> $ty { define_Conf!(@default $($default)?) })* + $(pub fn $name() -> $ty { $default })* } impl Default for Conf { @@ -90,20 +90,19 @@ macro_rules! define_Conf { } } }; - (@default) => (Default::default()); - (@default $default:expr) => ($default); } +// N.B., this macro is parsed by util/lintlib.py define_Conf! { /// Lint: CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, 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. The minimum rust version that the project supports - (msrv: Option), + (msrv: Option = None), /// Lint: BLACKLISTED_NAME. The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses (blacklisted_names: Vec = ["foo", "baz", "quux"].iter().map(ToString::to_string).collect()), /// Lint: COGNITIVE_COMPLEXITY. The maximum cognitive complexity a function can have (cognitive_complexity_threshold: u64 = 25), /// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY. Use the Cognitive Complexity lint instead. #[conf_deprecated("Please use `cognitive-complexity-threshold` instead")] - (cyclomatic_complexity_threshold: Option), + (cyclomatic_complexity_threshold: Option = None), /// Lint: DOC_MARKDOWN. The list of words this lint should not consider as identifiers needing ticks (doc_valid_idents: Vec = [ "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", @@ -142,7 +141,7 @@ define_Conf! { /// Lint: DECIMAL_LITERAL_REPRESENTATION. The lower bound for linting decimal literals (literal_representation_threshold: u64 = 16384), /// Lint: TRIVIALLY_COPY_PASS_BY_REF. The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by reference. - (trivial_copy_size_limit: Option), + (trivial_copy_size_limit: Option = None), /// Lint: LARGE_TYPE_PASS_BY_MOVE. The minimum size (in bytes) to consider a type for passing by reference instead of by value. (pass_by_value_size_limit: u64 = 256), /// Lint: TOO_MANY_LINES. The maximum number of lines a function or method can have @@ -158,15 +157,15 @@ define_Conf! { /// Lint: FN_PARAMS_EXCESSIVE_BOOLS. The maximum number of bools function parameters can have (max_fn_params_bools: u64 = 3), /// Lint: WILDCARD_IMPORTS. Whether to allow certain wildcard imports (prelude, super in tests). - (warn_on_all_wildcard_imports: bool), + (warn_on_all_wildcard_imports: bool = false), /// Lint: DISALLOWED_METHOD. The list of disallowed methods, written as fully qualified paths. - (disallowed_methods: Vec), + (disallowed_methods: Vec = Vec::new()), /// Lint: UNREADABLE_LITERAL. Should the fraction of a decimal be linted to include separators. (unreadable_literal_lint_fractions: bool = true), /// Lint: UPPER_CASE_ACRONYMS. Enables verbose mode. Triggers if there is more than one uppercase char next to each other - (upper_case_acronyms_aggressive: bool), + (upper_case_acronyms_aggressive: bool = false), /// Lint: _CARGO_COMMON_METADATA. For internal testing only, ignores the current `publish` settings in the Cargo manifest. - (cargo_ignore_publish: bool), + (cargo_ignore_publish: bool = false), } /// Search for the configuration file. diff --git a/util/lintlib.py b/util/lintlib.py index d0d9beb9b2d..5707cf0ce0f 100644 --- a/util/lintlib.py +++ b/util/lintlib.py @@ -14,7 +14,7 @@ lintname_re = re.compile(r'''pub\s+([A-Z_][A-Z_0-9]*)''') group_re = re.compile(r'''\s*([a-z_][a-z_0-9]+)''') conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE) confvar_re = re.compile( - r'''/// Lint: ([\w,\s]+)\. (.*)\n\s*\([^,]+,\s+"([^"]+)":\s+([^,]+),\s+([^\.\)]+).*\),''', re.MULTILINE) + r'''/// Lint: ([\w,\s]+)\. (.*)\n\s*\(([^:]+):\s*([^\s=]+)\s*=\s*([^\.\)]+).*\),''', re.MULTILINE) comment_re = re.compile(r'''\s*/// ?(.*)''') lint_levels = { From ffb0951a4d80cda686349f8f735ac4ac8a0e0cb4 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sun, 2 May 2021 17:53:01 -0500 Subject: [PATCH 3/3] Update config contributing docs --- doc/adding_lints.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/adding_lints.md b/doc/adding_lints.md index d6cc6d0c2c7..5a06afedbf4 100644 --- a/doc/adding_lints.md +++ b/doc/adding_lints.md @@ -454,7 +454,7 @@ in `clippy_lints/src/utils/conf.rs`: ```rust define_Conf! { /// Lint: LIST, OF, LINTS, . The minimum rust version that the project supports - (msrv, "msrv": Option, None), + (msrv: Option = None), ... } ``` @@ -562,7 +562,7 @@ in the following steps: like this: ```rust /// Lint: LINT_NAME. - (configuration_ident, "configuration_value": Type, DefaultValue), + (configuration_ident: Type = DefaultValue), ``` The configuration value and identifier should usually be the same. The doc comment will be automatically added to the lint documentation.