Skip to content

Commit

Permalink
Removed support for indirect recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
uudashr committed Jul 14, 2021
1 parent db50331 commit 16f84d2
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 29 deletions.
5 changes: 0 additions & 5 deletions gocognit.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,6 @@ func (v *complexityVisitor) visitCallExpr(n *ast.CallExpr) ast.Visitor {
if obj == v.name.Obj && name == v.name.Name {
// called by same function directly (direct recursion)
v.incComplexity()
} else if obj != nil {
if fnDecl, ok := obj.Decl.(*ast.FuncDecl); ok {
// called by same function indirectly (indirect recursion)
ast.Walk(v, fnDecl)
}
}
}
return v
Expand Down
12 changes: 0 additions & 12 deletions testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,6 @@ func FactRec(n int) int { // want "cognitive complexity 3 of func FactRec is hig
}
} // total complexity = 3

func FactRecIndirect(n int) int { // want "cognitive complexity 3 of func FactRecIndirect is high \\(> 0\\)"
if n <= 1 { // +1
return 1
} else { // +1
return factRecIndirect0(n) // +0 +1, due to indirect call to FactRecIndirect
}
} // total complexity = 3

func factRecIndirect0(n int) int { // want "cognitive complexity 3 of func factRecIndirect0 is high \\(> 0\\)"
return n * FactRecIndirect(n-1) // +0 +3 due to inderect call to factRecIndirect0
} // total complexity = 3

func FactLoop(n int) int { // want "cognitive complexity 1 of func FactLoop is high \\(> 0\\)"
total := 1
for n > 0 { // +1
Expand Down
12 changes: 0 additions & 12 deletions testdata/src/b/b.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,6 @@ func FactRec(n int) int {
}
} // total complexity = 3

func FactRecIndirect(n int) int {
if n <= 1 { // +1
return 1
} else { // +1
return factRecIndirect0(n) // +0 +1, due to indirect call to FactRecIndirect
}
} // total complexity = 3

func factRecIndirect0(n int) int {
return n * FactRecIndirect(n-1) // +0 +3 due to inderect call to factRecIndirect0
} // total complexity = 3

func FactLoop(n int) int {
total := 1
for n > 0 { // +1
Expand Down

0 comments on commit 16f84d2

Please sign in to comment.