Skip to content

Commit 2d0ee7d

Browse files
committed
Gci: update the way to call Run()
Signed-off-by: Xiang Dai <[email protected]>
1 parent 8e63112 commit 2d0ee7d

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/Djarvur/go-err113 v0.0.0-20200511133814-5174e21577d5
77
github.com/OpenPeeDeeP/depguard v1.0.1
88
github.com/bombsimon/wsl/v3 v3.1.0
9-
github.com/daixiang0/gci v0.2.2
9+
github.com/daixiang0/gci v0.2.3
1010
github.com/denis-tingajkin/go-header v0.3.1
1111
github.com/fatih/color v1.9.0
1212
github.com/go-critic/go-critic v0.5.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
4747
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
4848
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
4949
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
50-
github.com/daixiang0/gci v0.2.2 h1:ql+M0OX7Z+tPt0WAMpN11rgEvZGc+dqxuw5dn6d3UJM=
51-
github.com/daixiang0/gci v0.2.2/go.mod h1:+AV8KmHTGxxwp/pY84TLQfFKp2vuKXXJVzF3kD/hfR4=
50+
github.com/daixiang0/gci v0.2.3 h1:wg2R5t3NwFSmsGZDaD1mjiv0aRqktnaijE9f4SeLqu0=
51+
github.com/daixiang0/gci v0.2.3/go.mod h1:+AV8KmHTGxxwp/pY84TLQfFKp2vuKXXJVzF3kD/hfR4=
5252
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5353
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5454
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

pkg/golinters/gci.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package golinters
22

33
import (
4+
"bytes"
5+
"fmt"
46
"sync"
57

68
"github.com/daixiang0/gci/pkg/gci"
79
"github.com/pkg/errors"
10+
"github.com/shazow/go-diff/difflib"
811
"golang.org/x/tools/go/analysis"
912

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

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

4549
for _, f := range fileNames {
46-
diff, err := gci.Run(f, &gci.FlagSet{LocalFlag: localFlag})
50+
source, result, err := gci.Run(f, &gci.FlagSet{LocalFlag: localFlag})
4751
if err != nil {
4852
return nil, err
4953
}
50-
if diff == nil {
54+
if result == nil {
5155
continue
5256
}
57+
err = differ.Diff(&out, bytes.NewReader(source), bytes.NewReader(result))
58+
if err != nil {
59+
return nil, fmt.Errorf("can't get gci diff output: %v", err)
60+
}
5361

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

0 commit comments

Comments
 (0)