Skip to content

Commit 34e5fc6

Browse files
authored
Use upstream gocyclo. (#1739)
1 parent 2121370 commit 34e5fc6

File tree

4 files changed

+7
-16
lines changed

4 files changed

+7
-16
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ require (
1616
github.com/denis-tingajkin/go-header v0.4.2
1717
github.com/esimonov/ifshort v1.0.1
1818
github.com/fatih/color v1.10.0
19+
github.com/fzipp/gocyclo v0.3.1
1920
github.com/go-critic/go-critic v0.5.4
2021
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b
2122
github.com/gofrs/flock v0.8.0
2223
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
2324
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a
2425
github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6
2526
github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613
26-
github.com/golangci/gocyclo v0.0.0-20180528144436-0a533e8fa43d
2727
github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a
2828
github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc
2929
github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/gocognit.go

-1
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

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
// nolint:dupl
21
package golinters
32

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

9-
gocycloAPI "github.com/golangci/gocyclo/pkg/gocyclo"
7+
"github.com/fzipp/gocyclo"
108
"golang.org/x/tools/go/analysis"
119

1210
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
@@ -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 []gocycloAPI.Stat
32+
var stats gocyclo.Stats
3533
for _, f := range pass.Files {
36-
stats = gocycloAPI.BuildStats(f, pass.Fset, stats)
34+
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)