Skip to content

Commit

Permalink
Use upstream gocyclo. (#1739)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Feb 17, 2021
1 parent 2121370 commit 34e5fc6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ require (
github.com/denis-tingajkin/go-header v0.4.2
github.com/esimonov/ifshort v1.0.1
github.com/fatih/color v1.10.0
github.com/fzipp/gocyclo v0.3.1
github.com/go-critic/go-critic v0.5.4
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b
github.com/gofrs/flock v0.8.0
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a
github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6
github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613
github.com/golangci/gocyclo v0.0.0-20180528144436-0a533e8fa43d
github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a
github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc
github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
16 changes: 4 additions & 12 deletions pkg/golinters/gocyclo.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// nolint:dupl
package golinters

import (
"fmt"
"sort"
"sync"

gocycloAPI "github.com/golangci/gocyclo/pkg/gocyclo"
"github.com/fzipp/gocyclo"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
Expand All @@ -31,24 +29,18 @@ func NewGocyclo() *goanalysis.Linter {
nil,
).WithContextSetter(func(lintCtx *linter.Context) {
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
var stats []gocycloAPI.Stat
var stats gocyclo.Stats
for _, f := range pass.Files {
stats = gocycloAPI.BuildStats(f, pass.Fset, stats)
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

0 comments on commit 34e5fc6

Please sign in to comment.