Skip to content

Commit ea6f86b

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

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
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

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 bytes.Equal(source, result) {
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)