Skip to content

Commit cec1e78

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

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

pkg/golinters/gocognit.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// nolint:dupl
21
package golinters
32

43
import (

pkg/golinters/gocyclo.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// nolint:dupl
21
package golinters
32

43
import (
54
"fmt"
6-
"sort"
75
"sync"
86

97
"github.com/fzipp/gocyclo"
@@ -31,24 +29,18 @@ func NewGocyclo() *goanalysis.Linter {
3129
nil,
3230
).WithContextSetter(func(lintCtx *linter.Context) {
3331
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
34-
var stats []gocyclo.Stat
32+
var stats gocyclo.Stats
3533
for _, f := range pass.Files {
3634
stats = gocyclo.AnalyzeASTFile(f, pass.Fset, stats)
3735
}
3836
if len(stats) == 0 {
3937
return nil, nil
4038
}
4139

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

4642
res := make([]goanalysis.Issue, 0, len(stats))
4743
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-
5244
res = append(res, goanalysis.NewIssue(&result.Issue{
5345
Pos: s.Pos,
5446
Text: fmt.Sprintf("cyclomatic complexity %d of func %s is high (> %d)",

0 commit comments

Comments
 (0)