Skip to content

Commit

Permalink
Gci: update the way to call Run()
Browse files Browse the repository at this point in the history
Signed-off-by: Xiang Dai <[email protected]>
  • Loading branch information
daixiang0 committed Aug 28, 2020
1 parent 8e63112 commit 9122678
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Djarvur/go-err113 v0.0.0-20200511133814-5174e21577d5
github.com/OpenPeeDeeP/depguard v1.0.1
github.com/bombsimon/wsl/v3 v3.1.0
github.com/daixiang0/gci v0.2.2
github.com/daixiang0/gci v0.2.3
github.com/denis-tingajkin/go-header v0.3.1
github.com/fatih/color v1.9.0
github.com/go-critic/go-critic v0.5.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/daixiang0/gci v0.2.2 h1:ql+M0OX7Z+tPt0WAMpN11rgEvZGc+dqxuw5dn6d3UJM=
github.com/daixiang0/gci v0.2.2/go.mod h1:+AV8KmHTGxxwp/pY84TLQfFKp2vuKXXJVzF3kD/hfR4=
github.com/daixiang0/gci v0.2.3 h1:wg2R5t3NwFSmsGZDaD1mjiv0aRqktnaijE9f4SeLqu0=
github.com/daixiang0/gci v0.2.3/go.mod h1:+AV8KmHTGxxwp/pY84TLQfFKp2vuKXXJVzF3kD/hfR4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
12 changes: 10 additions & 2 deletions pkg/golinters/gci.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package golinters

import (
"bytes"
"fmt"
"sync"

"github.com/daixiang0/gci/pkg/gci"
"github.com/pkg/errors"
"github.com/shazow/go-diff/difflib"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
Expand All @@ -16,6 +19,7 @@ const gciName = "gci"
func NewGci() *goanalysis.Linter {
var mu sync.Mutex
var resIssues []goanalysis.Issue
differ := difflib.New()

analyzer := &analysis.Analyzer{
Name: gciName,
Expand Down Expand Up @@ -43,13 +47,17 @@ func NewGci() *goanalysis.Linter {
var issues []goanalysis.Issue

for _, f := range fileNames {
diff, err := gci.Run(f, &gci.FlagSet{LocalFlag: localFlag})
source, result, err := gci.Run(f, &gci.FlagSet{LocalFlag: localFlag})
if err != nil {
return nil, err
}
if diff == nil {
if result == nil {
continue
}
err = differ.Diff(&out, bytes.NewReader(source), bytes.NewReader(result))
if err != nil {
return nil, fmt.Errorf("can't get gci diff output: %v", err)
}

is, err := extractIssuesFromPatch(string(diff), lintCtx.Log, lintCtx, gciName)
if err != nil {
Expand Down

0 comments on commit 9122678

Please sign in to comment.