File tree 1 file changed +32
-3
lines changed
1 file changed +32
-3
lines changed Original file line number Diff line number Diff line change 2
2
//config: linters-settings.gocognit.min-complexity=2
3
3
package testdata
4
4
5
- func GocognitGetWords (number int ) string { // ERROR "cognitive complexity 4 of func .* is high .*"
5
+ func GoCognit_CC4_GetWords (number int ) string { // ERROR "cognitive complexity 4 of func .* is high .*"
6
6
if number == 1 { // +1
7
7
return "one"
8
8
} else if number == 2 { // +1
@@ -14,10 +14,39 @@ func GocognitGetWords(number int) string { // ERROR "cognitive complexity 4 of f
14
14
}
15
15
} // total complexity = 4
16
16
17
- func GoCognitFact (n int ) int { // ERROR "cognitive complexity 3 of func .* is high .*"
17
+ func GoCognit_CC1_GetWords (number int ) string {
18
+ switch number { // +1
19
+ case 1 :
20
+ return "one"
21
+ case 2 :
22
+ return "a couple"
23
+ case 3 :
24
+ return "a few"
25
+ default :
26
+ return "lots"
27
+ }
28
+ } // Cognitive complexity = 1
29
+
30
+ func GoCognit_CC3_Fact (n int ) int { // ERROR "cognitive complexity 3 of func .* is high .*"
18
31
if n <= 1 { // +1
19
32
return 1
20
33
} else { // +1
21
- return n + GoCognitFact (n - 1 ) // +1
34
+ return n + GoCognit_CC3_Fact (n - 1 ) // +1
22
35
}
23
36
} // total complexity = 3
37
+
38
+ func GoCognit_CC7_SumOfPrimes (max int ) int { // ERROR "cognitive complexity 7 of func .* is high .*"
39
+ var total int
40
+
41
+ OUT:
42
+ for i := 1 ; i < max ; i ++ { // +1
43
+ for j := 2 ; j < i ; j ++ { // +2 (nesting = 1)
44
+ if i % j == 0 { // +3 (nesting = 2)
45
+ continue OUT // +1
46
+ }
47
+ }
48
+ total += i
49
+ }
50
+
51
+ return total
52
+ } // Cognitive complexity = 7
You can’t perform that action at this time.
0 commit comments