2018-01-27 05:52:29 +02:00
|
|
|
// Test of cyclomatic complexity.
|
2018-01-27 05:48:44 +02:00
|
|
|
|
|
|
|
// Package pkg ...
|
|
|
|
package pkg
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
|
2022-01-31 18:33:43 +02:00
|
|
|
func f(x int) bool { // MATCH /function f has cyclomatic complexity 4 (> max enabled 1)/
|
2018-01-27 05:48:44 +02:00
|
|
|
if x > 0 && true || false {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
log.Printf("non-positive x: %d", x)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-01-31 18:33:43 +02:00
|
|
|
func g(f func() bool) string { // MATCH /function g has cyclomatic complexity 2 (> max enabled 1)/
|
2018-01-27 05:48:44 +02:00
|
|
|
if ok := f(); ok {
|
|
|
|
return "it's okay"
|
|
|
|
} else {
|
|
|
|
return "it's NOT okay!"
|
|
|
|
}
|
|
|
|
}
|