Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lsp): noExcessiveCognitiveComplexity diagnostic shows levels #4028

Merged
merged 5 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ impl Rule for NoExcessiveCognitiveComplexity {
RuleDiagnostic::new(
rule_category!(),
range,
markup!("Excessive complexity detected."),
markup!({
format!(
"Excessive complexity of {calculated_score} detected \
(max: {max_allowed_complexity})."
)
}),
)
.note(if calculated_score == &MAX_SCORE {
"Please refactor this function to reduce its complexity. \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function booleanOperators() {
```
booleanOperators.js:1:10 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 4 detected (max: 3).

> 1 │ function booleanOperators() {
│ ^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function booleanOperators2() {
```
booleanOperators2.js:1:10 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 3 detected (max: 2).

> 1 │ function booleanOperators2() {
│ ^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function handleArrowDown(event: React.KeyboardEvent) {
```
complexEventHandler.ts:1:10 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 26 detected (max: 15).

> 1 │ function handleArrowDown(event: React.KeyboardEvent) {
│ ^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function excessiveNesting() {
```
excessiveNesting.js:10:46 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 255 detected (max: 15).

8 │ function nested7() {
9 │ function nested8() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function functionalChain(array) {
```
functionalChain.js:4:24 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 3 detected (max: 2).

2 │ return array
3 │ .filter(Boolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function lambdas(array) {
```
lambdas.js:4:26 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 4 detected (max: 3).

2 │ for (item of array) { // +1, nesting = 1
3 │ if (item) { // +2, nesting = 2
Expand All @@ -57,7 +57,7 @@ lambdas.js:4:26 lint/complexity/noExcessiveCognitiveComplexity ━━━━━
```
lambdas.js:10:22 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 4 detected (max: 3).

8 │ };
9 │
Expand All @@ -74,7 +74,7 @@ lambdas.js:10:22 lint/complexity/noExcessiveCognitiveComplexity ━━━━━
```
lambdas.js:16:23 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 4 detected (max: 3).

14 │ }
15 │
Expand All @@ -91,7 +91,7 @@ lambdas.js:16:23 lint/complexity/noExcessiveCognitiveComplexity ━━━━━
```
lambdas.js:22:32 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 4 detected (max: 3).

20 │ };
21 │
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function nestedControlFlowStructures(num) {
```
nestedControlFlowStructures.js:1:10 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 9 detected (max: 8).

> 1 │ function nestedControlFlowStructures(num) {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function simpleBranches() {
```
simpleBranches.js:1:10 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 3 detected (max: 2).

> 1 │ function simpleBranches() {
│ ^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function simpleBranches2() {
```
simpleBranches2.js:1:10 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 2 detected (max: 1).

> 1 │ function simpleBranches2() {
│ ^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function sumOfPrimes(max) {
```
sumOfPrimes.js:1:10 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Excessive complexity detected.
! Excessive complexity of 7 detected (max: 6).

> 1 │ function sumOfPrimes(max) {
│ ^^^^^^^^^^^
Expand Down
Loading