diff --git a/fixtures/cyclomatic-2.go b/fixtures/cyclomatic-2.go new file mode 100644 index 0000000..447cbb6 --- /dev/null +++ b/fixtures/cyclomatic-2.go @@ -0,0 +1,23 @@ +// Test of return+else warning. + +// Package pkg ... +package pkg + +import "log" + +func f(x int) bool { // MATCH /function f has cyclomatic complexity 4/ + if x > 0 && true || false { + return true + } else { + log.Printf("non-positive x: %d", x) + } + return false +} + +func g(f func() bool) string { + if ok := f(); ok { + return "it's okay" + } else { + return "it's NOT okay!" + } +} diff --git a/testutil/lint_test.go b/testutil/lint_test.go index b449024..f98606b 100644 --- a/testutil/lint_test.go +++ b/testutil/lint_test.go @@ -60,6 +60,9 @@ func TestVarDeclaration(t *testing.T) { testRule(t, "cyclomatic", &rule.CyclomaticRule{}, &lint.RuleConfig{ Arguments: []string{"1"}, }) + testRule(t, "cyclomatic-2", &rule.CyclomaticRule{}, &lint.RuleConfig{ + Arguments: []string{"3"}, + }) } func testRule(t *testing.T, filename string, rule lint.Rule, config ...*lint.RuleConfig) { @@ -91,7 +94,8 @@ func TestAll(t *testing.T) { baseDir := "../fixtures/" ignoreFiles := map[string]bool{ - "cyclomatic.go": true, + "cyclomatic.go": true, + "cyclomatic-2.go": true, } rx, err := regexp.Compile(*lintMatch)