mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
move to complexity
but don't lint by default
This commit is contained in:
parent
378d77584a
commit
725399a178
8 changed files with 12 additions and 54 deletions
|
@ -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:**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1 +1 @@
|
|||
excessive-nesting-threshold = 10
|
||||
excessive-nesting-threshold = 0
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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)]
|
||||
|
|
Loading…
Reference in a new issue