-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #4935 - krishna-veerareddy:issue-4241-cognitive-complex…
…ity-lint-span, r=phansch Reduce cognitive complexity lint span Currently the cognitive complexity lint spans the entire function body making it really difficult to read and refactor the code in editors. To fix this we reduce the lint span to the function name. changelog: Reduce cognitive complexity lint span Fixes #4241
- Loading branch information
Showing
4 changed files
with
125 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,211 +1,139 @@ | ||
error: the function has a cognitive complexity of (28/25) | ||
--> $DIR/cognitive_complexity.rs:6:1 | ||
--> $DIR/cognitive_complexity.rs:6:4 | ||
| | ||
LL | / fn main() { | ||
LL | | if true { | ||
LL | | println!("a"); | ||
LL | | } | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn main() { | ||
| ^^^^ | ||
| | ||
= note: `-D clippy::cognitive-complexity` implied by `-D warnings` | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (7/1) | ||
--> $DIR/cognitive_complexity.rs:91:1 | ||
--> $DIR/cognitive_complexity.rs:91:4 | ||
| | ||
LL | / fn kaboom() { | ||
LL | | let n = 0; | ||
LL | | 'a: for i in 0..20 { | ||
LL | | 'b: for j in i..20 { | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn kaboom() { | ||
| ^^^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (2/1) | ||
--> $DIR/cognitive_complexity.rs:149:1 | ||
--> $DIR/cognitive_complexity.rs:149:4 | ||
| | ||
LL | / fn baa() { | ||
LL | | let x = || match 99 { | ||
LL | | 0 => 0, | ||
LL | | 1 => 1, | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn baa() { | ||
| ^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (2/1) | ||
--> $DIR/cognitive_complexity.rs:150:13 | ||
| | ||
LL | let x = || match 99 { | ||
| _____________^ | ||
LL | | 0 => 0, | ||
LL | | 1 => 1, | ||
LL | | 2 => 2, | ||
... | | ||
LL | | _ => 42, | ||
LL | | }; | ||
| |_____^ | ||
LL | let x = || match 99 { | ||
| ^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (2/1) | ||
--> $DIR/cognitive_complexity.rs:167:1 | ||
--> $DIR/cognitive_complexity.rs:167:4 | ||
| | ||
LL | / fn bar() { | ||
LL | | match 99 { | ||
LL | | 0 => println!("hi"), | ||
LL | | _ => println!("bye"), | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn bar() { | ||
| ^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (2/1) | ||
--> $DIR/cognitive_complexity.rs:186:1 | ||
--> $DIR/cognitive_complexity.rs:186:4 | ||
| | ||
LL | / fn barr() { | ||
LL | | match 99 { | ||
LL | | 0 => println!("hi"), | ||
LL | | 1 => println!("bla"), | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn barr() { | ||
| ^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (3/1) | ||
--> $DIR/cognitive_complexity.rs:196:1 | ||
--> $DIR/cognitive_complexity.rs:196:4 | ||
| | ||
LL | / fn barr2() { | ||
LL | | match 99 { | ||
LL | | 0 => println!("hi"), | ||
LL | | 1 => println!("bla"), | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn barr2() { | ||
| ^^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (2/1) | ||
--> $DIR/cognitive_complexity.rs:212:1 | ||
--> $DIR/cognitive_complexity.rs:212:4 | ||
| | ||
LL | / fn barrr() { | ||
LL | | match 99 { | ||
LL | | 0 => println!("hi"), | ||
LL | | 1 => panic!("bla"), | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn barrr() { | ||
| ^^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (3/1) | ||
--> $DIR/cognitive_complexity.rs:222:1 | ||
--> $DIR/cognitive_complexity.rs:222:4 | ||
| | ||
LL | / fn barrr2() { | ||
LL | | match 99 { | ||
LL | | 0 => println!("hi"), | ||
LL | | 1 => panic!("bla"), | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn barrr2() { | ||
| ^^^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (2/1) | ||
--> $DIR/cognitive_complexity.rs:238:1 | ||
--> $DIR/cognitive_complexity.rs:238:4 | ||
| | ||
LL | / fn barrrr() { | ||
LL | | match 99 { | ||
LL | | 0 => println!("hi"), | ||
LL | | 1 => println!("bla"), | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn barrrr() { | ||
| ^^^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (3/1) | ||
--> $DIR/cognitive_complexity.rs:248:1 | ||
--> $DIR/cognitive_complexity.rs:248:4 | ||
| | ||
LL | / fn barrrr2() { | ||
LL | | match 99 { | ||
LL | | 0 => println!("hi"), | ||
LL | | 1 => println!("bla"), | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn barrrr2() { | ||
| ^^^^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (2/1) | ||
--> $DIR/cognitive_complexity.rs:264:1 | ||
--> $DIR/cognitive_complexity.rs:264:4 | ||
| | ||
LL | / fn cake() { | ||
LL | | if 4 == 5 { | ||
LL | | println!("yea"); | ||
LL | | } else { | ||
... | | ||
LL | | println!("whee"); | ||
LL | | } | ||
| |_^ | ||
LL | fn cake() { | ||
| ^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (4/1) | ||
--> $DIR/cognitive_complexity.rs:274:1 | ||
--> $DIR/cognitive_complexity.rs:274:8 | ||
| | ||
LL | / pub fn read_file(input_path: &str) -> String { | ||
LL | | use std::fs::File; | ||
LL | | use std::io::{Read, Write}; | ||
LL | | use std::path::Path; | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | pub fn read_file(input_path: &str) -> String { | ||
| ^^^^^^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (2/1) | ||
--> $DIR/cognitive_complexity.rs:305:1 | ||
--> $DIR/cognitive_complexity.rs:305:4 | ||
| | ||
LL | / fn void(void: Void) { | ||
LL | | if true { | ||
LL | | match void {} | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn void(void: Void) { | ||
| ^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (8/1) | ||
--> $DIR/cognitive_complexity.rs:356:1 | ||
--> $DIR/cognitive_complexity.rs:356:4 | ||
| | ||
LL | / fn early_ret() -> i32 { | ||
LL | | let a = if true { 42 } else { return 0; }; | ||
LL | | let a = if a < 99 { 42 } else { return 0; }; | ||
LL | | let a = if a < 99 { 42 } else { return 0; }; | ||
... | | ||
LL | | } | ||
LL | | } | ||
| |_^ | ||
LL | fn early_ret() -> i32 { | ||
| ^^^^^^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: aborting due to 15 previous errors | ||
error: the function has a cognitive complexity of (2/1) | ||
--> $DIR/cognitive_complexity.rs:377:13 | ||
| | ||
LL | let x = |a: i32, b: i32| -> i32 { | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: the function has a cognitive complexity of (2/1) | ||
--> $DIR/cognitive_complexity.rs:390:8 | ||
| | ||
LL | fn moo(&self) { | ||
| ^^^ | ||
| | ||
= help: you could split it up into multiple smaller functions | ||
|
||
error: aborting due to 17 previous errors | ||
|
Oops, something went wrong.