@@ -59,6 +59,14 @@ func SimpleLogicalSeq2(a, b, c, d bool) string { // want "cognitive complexity 2
59
59
return "not ok"
60
60
} // total complexity = 2
61
61
62
+ func SimpleLogicalSeq3 (a , b , c interface {}) string { // want "cognitive complexity 2 of func SimpleLogicalSeq3 is high \\(> 0\\)"
63
+ if a == nil || b != nil || c != nil { // +1 for `if`, +1 for `||` sequence
64
+ return "ok"
65
+ }
66
+
67
+ return "not ok"
68
+ } // total complexity = 2
69
+
62
70
func ComplexLogicalSeq1 (a , b , c , d , e , f bool ) string { // want "cognitive complexity 4 of func ComplexLogicalSeq1 is high \\(> 0\\)"
63
71
if a && b && c || d || e && f { // +1 for `if`, +3 for changing sequence of `&&` `||` `&&`
64
72
return "ok"
@@ -68,13 +76,48 @@ func ComplexLogicalSeq1(a, b, c, d, e, f bool) string { // want "cognitive compl
68
76
} // total complexity = 4
69
77
70
78
func ComplexLogicalSeq2 (a , b , c , d , e , f bool ) string { // want "cognitive complexity 3 of func ComplexLogicalSeq2 is high \\(> 0\\)"
71
- if a && ! (b && c ) { // +1 for `if`, +2 for having sequence of `&&` `&&` chain
79
+ if a && ! (b && c ) { // +1 for `if`, +1 for each `&&` chain
80
+ return "ok"
81
+ }
82
+
83
+ return "not ok"
84
+ } // total complexity = 3
85
+
86
+ func ComplexLogicalSeq3 (a , b , c , d , e , f bool ) string { // want "cognitive complexity 3 of func ComplexLogicalSeq3 is high \\(> 0\\)"
87
+ if a && (b && c ) { // +1 for `if`, +1 for each `&&` chain
72
88
return "ok"
73
89
}
74
90
75
91
return "not ok"
76
92
} // total complexity = 3
77
93
94
+ func ComplexLogicalSeq4 (a , b , c , d , e , f bool ) bool { // want "cognitive complexity 3 of func ComplexLogicalSeq4 is high \\(> 0\\)"
95
+ return a && b && c || d || e && f // +3 for changing sequence of `&&` `||` `&&`
96
+ } // total complexity = 3
97
+
98
+ func ComplexLogicalSeq5 (a , b , c , d , e , f bool ) bool { // want "cognitive complexity 3 of func ComplexLogicalSeq5 is high \\(> 0\\)"
99
+ return a && b && (c && d || e || f ) // +1 for `&&` sequence, +2 for `&&` `||` sequence in parentheses
100
+ } // total complexity = 3
101
+
102
+ func ExprFunc (a , b , c any ) bool { // want "cognitive complexity 2 of func ExprFunc is high \\(> 0\\)"
103
+ if a != nil || b != nil || c != nil { // +1 for `if`, +1 for `||` chain
104
+ return false
105
+ }
106
+
107
+ return true
108
+ } // total complexity = 2
109
+
110
+ func VarFunc (a , b , c any ) bool { // want "cognitive complexity 2 of func VarFunc is high \\(> 0\\)"
111
+ na := a != nil
112
+ nb := b != nil
113
+ nc := c != nil
114
+ if na || nb || nc { // +1 for `if`, +1 for `||` chain
115
+ return false
116
+ }
117
+
118
+ return true
119
+ } // total complexity = 2
120
+
78
121
func GetWords (number int ) string { // want "cognitive complexity 1 of func GetWords is high \\(> 0\\)"
79
122
switch number { // +1
80
123
case 1 :
0 commit comments