Skip to content

Commit 93ea4a6

Browse files
committed
apply suggestion from #1741
1 parent 3a9d212 commit 93ea4a6

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

pkg/golinters/gocyclo.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package golinters
33

44
import (
55
"fmt"
6-
"sort"
76
"sync"
87

98
"github.com/fzipp/gocyclo"
@@ -31,24 +30,18 @@ func NewGocyclo() *goanalysis.Linter {
3130
nil,
3231
).WithContextSetter(func(lintCtx *linter.Context) {
3332
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
34-
var stats []gocyclo.Stat
33+
var stats gocyclo.Stats
3534
for _, f := range pass.Files {
3635
stats = gocyclo.AnalyzeASTFile(f, pass.Fset, stats)
3736
}
3837
if len(stats) == 0 {
3938
return nil, nil
4039
}
4140

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

4643
res := make([]goanalysis.Issue, 0, len(stats))
4744
for _, s := range stats {
48-
if s.Complexity <= lintCtx.Settings().Gocyclo.MinComplexity {
49-
break // Break as the stats is already sorted from greatest to least
50-
}
51-
5245
res = append(res, goanalysis.NewIssue(&result.Issue{
5346
Pos: s.Pos,
5447
Text: fmt.Sprintf("cyclomatic complexity %d of func %s is high (> %d)",

0 commit comments

Comments
 (0)