Skip to content

Commit

Permalink
refactor(cyclomatic): improved message for cyclomatic rule (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
butuzov authored Jan 31, 2022
1 parent 47ba3e3 commit 6545203
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions rule/cyclomatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ func (w lintCyclomatic) Visit(_ ast.Node) ast.Visitor {
w.onFailure(lint.Failure{
Confidence: 1,
Category: "maintenance",
Failure: fmt.Sprintf("function %s has cyclomatic complexity %d", funcName(fn), c),
Node: fn,
Failure: fmt.Sprintf("function %s has cyclomatic complexity %d (> max enabled %d)",
funcName(fn), c, w.complexity),
Node: fn,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion testdata/cyclomatic-2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package pkg

import "log"

func f(x int) bool { // MATCH /function f has cyclomatic complexity 4/
func f(x int) bool { // MATCH /function f has cyclomatic complexity 4 (> max enabled 3)/
if x > 0 && true || false {
return true
} else {
Expand Down
4 changes: 2 additions & 2 deletions testdata/cyclomatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package pkg

import "log"

func f(x int) bool { // MATCH /function f has cyclomatic complexity 4/
func f(x int) bool { // MATCH /function f has cyclomatic complexity 4 (> max enabled 1)/
if x > 0 && true || false {
return true
} else {
Expand All @@ -14,7 +14,7 @@ func f(x int) bool { // MATCH /function f has cyclomatic complexity 4/
return false
}

func g(f func() bool) string { // MATCH /function g has cyclomatic complexity 2/
func g(f func() bool) string { // MATCH /function g has cyclomatic complexity 2 (> max enabled 1)/
if ok := f(); ok {
return "it's okay"
} else {
Expand Down

0 comments on commit 6545203

Please sign in to comment.