Skip to content

Commit b024399

Browse files
committed
move to complexity but don't lint by default
1 parent 51c28a6 commit b024399

File tree

8 files changed

+13
-55
lines changed

8 files changed

+13
-55
lines changed

book/src/lint_configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Please use that command to update the file and do not edit it by hand.
1212
| [avoid-breaking-exported-api](#avoid-breaking-exported-api) | `true` |
1313
| [msrv](#msrv) | `None` |
1414
| [cognitive-complexity-threshold](#cognitive-complexity-threshold) | `25` |
15-
| [excessive-nesting-threshold](#excessive-nesting-threshold) | `10` |
15+
| [excessive-nesting-threshold](#excessive-nesting-threshold) | `0` |
1616
| [disallowed-names](#disallowed-names) | `["foo", "baz", "quux"]` |
1717
| [doc-valid-idents](#doc-valid-idents) | `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenDNS", "WebGL", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]` |
1818
| [too-many-arguments-threshold](#too-many-arguments-threshold) | `7` |
@@ -197,7 +197,7 @@ The maximum cognitive complexity a function can have
197197
### excessive-nesting-threshold
198198
The maximum amount of nesting a block can reside in
199199

200-
**Default Value:** `10` (`u64`)
200+
**Default Value:** `0` (`u64`)
201201

202202
* [excessive_nesting](https://rust-lang.github.io/rust-clippy/master/index.html#excessive_nesting)
203203

clippy_lints/src/excessive_nesting.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ use rustc_span::Span;
1111

1212
declare_clippy_lint! {
1313
/// ### What it does
14-
///
1514
/// Checks for blocks which are nested beyond a certain threshold.
1615
///
17-
/// ### Why is this bad?
16+
/// 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.
1817
///
19-
/// It can severely hinder readability. The default is very generous; if you
20-
/// exceed this, it's a sign you should refactor.
18+
/// ### Why is this bad?
19+
/// It can severely hinder readability.
2120
///
2221
/// ### Example
2322
/// An example clippy.toml configuration:
@@ -59,7 +58,7 @@ declare_clippy_lint! {
5958
/// ```
6059
#[clippy::version = "1.70.0"]
6160
pub EXCESSIVE_NESTING,
62-
restriction,
61+
complexity,
6362
"checks for blocks nested beyond a certain threshold"
6463
}
6564
impl_lint_pass!(ExcessiveNesting => [EXCESSIVE_NESTING]);
@@ -115,7 +114,9 @@ struct NestingVisitor<'conf, 'cx> {
115114

116115
impl NestingVisitor<'_, '_> {
117116
fn check_indent(&mut self, span: Span, id: NodeId) -> bool {
118-
if self.nest_level > self.conf.excessive_nesting_threshold && !in_external_macro(self.cx.sess(), span) {
117+
let threshold = self.conf.excessive_nesting_threshold;
118+
119+
if threshold != 0 && self.nest_level > threshold && !in_external_macro(self.cx.sess(), span) {
119120
self.conf.nodes.insert(id);
120121

121122
return true;

clippy_lints/src/utils/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ define_Conf! {
269269
/// Lint: EXCESSIVE_NESTING.
270270
///
271271
/// The maximum amount of nesting a block can reside in
272-
(excessive_nesting_threshold: u64 = 10),
272+
(excessive_nesting_threshold: u64 = 0),
273273
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY.
274274
///
275275
/// Use the Cognitive Complexity lint instead.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
excessive-nesting-threshold = 10
1+
excessive-nesting-threshold = 0
Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +0,0 @@
1-
error: this block is too nested
2-
--> $DIR/excessive_nesting.rs:154:18
3-
|
4-
LL | [0, {{{{{{{{{{0}}}}}}}}}}];
5-
| ^^^
6-
|
7-
= help: try refactoring your code to minimize nesting
8-
= note: `-D clippy::excessive-nesting` implied by `-D warnings`
9-
10-
error: this block is too nested
11-
--> $DIR/excessive_nesting.rs:156:17
12-
|
13-
LL | xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}];
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= help: try refactoring your code to minimize nesting
17-
18-
error: this block is too nested
19-
--> $DIR/excessive_nesting.rs:157:19
20-
|
21-
LL | &mut {{{{{{{{{{y}}}}}}}}}};
22-
| ^^^
23-
|
24-
= help: try refactoring your code to minimize nesting
25-
26-
error: this block is too nested
27-
--> $DIR/excessive_nesting.rs:165:29
28-
|
29-
LL | let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} };
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31-
|
32-
= help: try refactoring your code to minimize nesting
33-
34-
error: this block is too nested
35-
--> $DIR/excessive_nesting.rs:168:27
36-
|
37-
LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}};
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39-
|
40-
= help: try refactoring your code to minimize nesting
41-
42-
error: aborting due to 5 previous errors
43-

tests/ui-toml/excessive_nesting/excessive_nesting.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@aux-build:macro_rules.rs
2-
//@revisions: below default
3-
//@[below] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/excessive_nesting/below
2+
//@revisions: set default
3+
//@[set] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/excessive_nesting/set
44
//@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/excessive_nesting/default
55
#![rustfmt::skip]
66
#![feature(custom_inner_attributes)]

0 commit comments

Comments
 (0)