diff --git a/rule/cognitive-complexity.go b/rule/cognitive-complexity.go index 711aa22..9b98237 100644 --- a/rule/cognitive-complexity.go +++ b/rule/cognitive-complexity.go @@ -52,7 +52,7 @@ type cognitiveComplexityLinter struct { func (w cognitiveComplexityLinter) lint() { f := w.file for _, decl := range f.AST.Decls { - if fn, ok := decl.(*ast.FuncDecl); ok { + if fn, ok := decl.(*ast.FuncDecl); ok && fn.Body != nil { v := cognitiveComplexityVisitor{} c := v.subTreeComplexity(fn.Body) if c > w.maxComplexity { diff --git a/testdata/cognitive-complexity.go b/testdata/cognitive-complexity.go index 0a0348a..c20794b 100644 --- a/testdata/cognitive-complexity.go +++ b/testdata/cognitive-complexity.go @@ -278,3 +278,6 @@ func (m *Migrator) MigrateIfNeeded(target *EtcdVersionPair) error { // MATCH /fu } } } + +// no regression test for issue #451 +func myFunc()