From 725399a178158be33f0754c423b95b5f7f8b53ac Mon Sep 17 00:00:00 2001 From: Centri3 <114838443+Centri3@users.noreply.github.com> Date: Tue, 30 May 2023 12:40:40 -0500 Subject: [PATCH] move to `complexity` but don't lint by default --- book/src/lint_configuration.md | 2 +- clippy_lints/src/excessive_nesting.rs | 13 +++--- clippy_lints/src/utils/conf.rs | 2 +- .../excessive_nesting/default/clippy.toml | 2 +- .../excessive_nesting.default.stderr | 43 ------------------- .../excessive_nesting/excessive_nesting.rs | 4 +- ...ow.stderr => excessive_nesting.set.stderr} | 0 .../{below => set}/clippy.toml | 0 8 files changed, 12 insertions(+), 54 deletions(-) rename tests/ui-toml/excessive_nesting/{excessive_nesting.below.stderr => excessive_nesting.set.stderr} (100%) rename tests/ui-toml/excessive_nesting/{below => set}/clippy.toml (100%) diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index 4fa6b81c0..3c955c9e5 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -161,7 +161,7 @@ The maximum cognitive complexity a function can have ## `excessive-nesting-threshold` The maximum amount of nesting a block can reside in -**Default Value:** `10` (`u64`) +**Default Value:** `0` (`u64`) --- **Affected lints:** diff --git a/clippy_lints/src/excessive_nesting.rs b/clippy_lints/src/excessive_nesting.rs index f1aafa3cb..1d68d7f94 100644 --- a/clippy_lints/src/excessive_nesting.rs +++ b/clippy_lints/src/excessive_nesting.rs @@ -11,13 +11,12 @@ use rustc_span::Span; declare_clippy_lint! { /// ### What it does - /// /// Checks for blocks which are nested beyond a certain threshold. /// - /// ### Why is this bad? + /// Note: Even though this lint is warn-by-default, it will only trigger if a maximum nesting level is defined in the clippy.toml file. /// - /// It can severely hinder readability. The default is very generous; if you - /// exceed this, it's a sign you should refactor. + /// ### Why is this bad? + /// It can severely hinder readability. /// /// ### Example /// An example clippy.toml configuration: @@ -59,7 +58,7 @@ declare_clippy_lint! { /// ``` #[clippy::version = "1.70.0"] pub EXCESSIVE_NESTING, - restriction, + complexity, "checks for blocks nested beyond a certain threshold" } impl_lint_pass!(ExcessiveNesting => [EXCESSIVE_NESTING]); @@ -115,7 +114,9 @@ struct NestingVisitor<'conf, 'cx> { impl NestingVisitor<'_, '_> { fn check_indent(&mut self, span: Span, id: NodeId) -> bool { - if self.nest_level > self.conf.excessive_nesting_threshold && !in_external_macro(self.cx.sess(), span) { + let threshold = self.conf.excessive_nesting_threshold; + + if threshold != 0 && self.nest_level > threshold && !in_external_macro(self.cx.sess(), span) { self.conf.nodes.insert(id); return true; diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index cf0da266d..69143c3c7 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -308,7 +308,7 @@ define_Conf! { /// Lint: EXCESSIVE_NESTING. /// /// The maximum amount of nesting a block can reside in - (excessive_nesting_threshold: u64 = 10), + (excessive_nesting_threshold: u64 = 0), /// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY. /// /// Use the Cognitive Complexity lint instead. diff --git a/tests/ui-toml/excessive_nesting/default/clippy.toml b/tests/ui-toml/excessive_nesting/default/clippy.toml index b01e482e4..e8b115a0f 100644 --- a/tests/ui-toml/excessive_nesting/default/clippy.toml +++ b/tests/ui-toml/excessive_nesting/default/clippy.toml @@ -1 +1 @@ -excessive-nesting-threshold = 10 +excessive-nesting-threshold = 0 diff --git a/tests/ui-toml/excessive_nesting/excessive_nesting.default.stderr b/tests/ui-toml/excessive_nesting/excessive_nesting.default.stderr index 02fa2cdcf..e69de29bb 100644 --- a/tests/ui-toml/excessive_nesting/excessive_nesting.default.stderr +++ b/tests/ui-toml/excessive_nesting/excessive_nesting.default.stderr @@ -1,43 +0,0 @@ -error: this block is too nested - --> $DIR/excessive_nesting.rs:154:18 - | -LL | [0, {{{{{{{{{{0}}}}}}}}}}]; - | ^^^ - | - = help: try refactoring your code to minimize nesting - = note: `-D clippy::excessive-nesting` implied by `-D warnings` - -error: this block is too nested - --> $DIR/excessive_nesting.rs:156:17 - | -LL | xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: try refactoring your code to minimize nesting - -error: this block is too nested - --> $DIR/excessive_nesting.rs:157:19 - | -LL | &mut {{{{{{{{{{y}}}}}}}}}}; - | ^^^ - | - = help: try refactoring your code to minimize nesting - -error: this block is too nested - --> $DIR/excessive_nesting.rs:165:29 - | -LL | let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: try refactoring your code to minimize nesting - -error: this block is too nested - --> $DIR/excessive_nesting.rs:168:27 - | -LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: try refactoring your code to minimize nesting - -error: aborting due to 5 previous errors - diff --git a/tests/ui-toml/excessive_nesting/excessive_nesting.rs b/tests/ui-toml/excessive_nesting/excessive_nesting.rs index 745031db1..5e436b97e 100644 --- a/tests/ui-toml/excessive_nesting/excessive_nesting.rs +++ b/tests/ui-toml/excessive_nesting/excessive_nesting.rs @@ -1,6 +1,6 @@ //@aux-build:macro_rules.rs -//@revisions: below default -//@[below] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/excessive_nesting/below +//@revisions: set default +//@[set] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/excessive_nesting/set //@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/excessive_nesting/default #![rustfmt::skip] #![feature(custom_inner_attributes)] diff --git a/tests/ui-toml/excessive_nesting/excessive_nesting.below.stderr b/tests/ui-toml/excessive_nesting/excessive_nesting.set.stderr similarity index 100% rename from tests/ui-toml/excessive_nesting/excessive_nesting.below.stderr rename to tests/ui-toml/excessive_nesting/excessive_nesting.set.stderr diff --git a/tests/ui-toml/excessive_nesting/below/clippy.toml b/tests/ui-toml/excessive_nesting/set/clippy.toml similarity index 100% rename from tests/ui-toml/excessive_nesting/below/clippy.toml rename to tests/ui-toml/excessive_nesting/set/clippy.toml