Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
apply suggestion from #1741
  • Loading branch information
ldez committed Feb 17, 2021
commit cec1e780c4085d223dcc7c18b52f4f7cb4939ceb
1 change: 0 additions & 1 deletion pkg/golinters/gocognit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// nolint:dupl
package golinters

import (
Expand Down
12 changes: 2 additions & 10 deletions pkg/golinters/gocyclo.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// nolint:dupl
package golinters

import (
"fmt"
"sort"
"sync"

"github.com/fzipp/gocyclo"
Expand Down Expand Up @@ -31,24 +29,18 @@ func NewGocyclo() *goanalysis.Linter {
nil,
).WithContextSetter(func(lintCtx *linter.Context) {
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
var stats []gocyclo.Stat
var stats gocyclo.Stats
for _, f := range pass.Files {
stats = gocyclo.AnalyzeASTFile(f, pass.Fset, stats)
}
if len(stats) == 0 {
return nil, nil
}

sort.SliceStable(stats, func(i, j int) bool {
return stats[i].Complexity > stats[j].Complexity
})
stats = stats.SortAndFilter(-1, lintCtx.Settings().Gocyclo.MinComplexity)

res := make([]goanalysis.Issue, 0, len(stats))
for _, s := range stats {
if s.Complexity <= lintCtx.Settings().Gocyclo.MinComplexity {
break // Break as the stats is already sorted from greatest to least
}

res = append(res, goanalysis.NewIssue(&result.Issue{
Pos: s.Pos,
Text: fmt.Sprintf("cyclomatic complexity %d of func %s is high (> %d)",
Expand Down