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

Add more test #21

Merged
merged 2 commits into from
Jul 17, 2023
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
4 changes: 2 additions & 2 deletions testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ func ComplexLogicalSeq5(a, b, c, d, e, f bool) bool { // want "cognitive complex
return a && b && (c && d || e || f) // +1 for `&&` sequence, +2 for `&&` `||` sequence in parentheses
} // total complexity = 3

func ExprFunc(a, b, c any) bool { // want "cognitive complexity 2 of func ExprFunc is high \\(> 0\\)"
func ExprFunc(a, b, c interface{}) bool { // want "cognitive complexity 2 of func ExprFunc is high \\(> 0\\)"
if a != nil || b != nil || c != nil { // +1 for `if`, +1 for `||` chain
return false
}

return true
} // total complexity = 2

func VarFunc(a, b, c any) bool { // want "cognitive complexity 2 of func VarFunc is high \\(> 0\\)"
func VarFunc(a, b, c interface{}) bool { // want "cognitive complexity 2 of func VarFunc is high \\(> 0\\)"
na := a != nil
nb := b != nil
nc := c != nil
Expand Down
35 changes: 35 additions & 0 deletions testdata/src/b/b.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,41 @@ func ComplexLogicalSeq2(a, b, c, d, e, f bool) string {
return "not ok"
} // total complexity = 3

func ComplexLogicalSeq3(a, b, c, d, e, f bool) string {
if a && (b && c) { // +1 for `if`, +1 for each `&&` chain
return "ok"
}

return "not ok"
} // total complexity = 3

func ComplexLogicalSeq4(a, b, c, d, e, f bool) bool {
return a && b && c || d || e && f // +3 for changing sequence of `&&` `||` `&&`
} // total complexity = 3

func ComplexLogicalSeq5(a, b, c, d, e, f bool) bool {
return a && b && (c && d || e || f) // +1 for `&&` sequence, +2 for `&&` `||` sequence in parentheses
} // total complexity = 3

func ExprFunc(a, b, c interface{}) bool {
if a != nil || b != nil || c != nil { // +1 for `if`, +1 for `||` chain
return false
}

return true
} // total complexity = 2

func VarFunc(a, b, c interface{}) bool {
na := a != nil
nb := b != nil
nc := c != nil
if na || nb || nc { // +1 for `if`, +1 for `||` chain
return false
}

return true
} // total complexity = 2

func GetWords(number int) string {
switch number { // +1
case 1:
Expand Down