@@ -7,6 +7,11 @@ import (
7
7
8
8
gcicfg "github.com/daixiang0/gci/pkg/config"
9
9
"github.com/daixiang0/gci/pkg/gci"
10
+ "github.com/daixiang0/gci/pkg/io"
11
+ "github.com/daixiang0/gci/pkg/log"
12
+ "github.com/hexops/gotextdiff"
13
+ "github.com/hexops/gotextdiff/myers"
14
+ "github.com/hexops/gotextdiff/span"
10
15
"github.com/pkg/errors"
11
16
"golang.org/x/tools/go/analysis"
12
17
@@ -81,7 +86,7 @@ func runGci(pass *analysis.Pass, lintCtx *linter.Context, cfg *gcicfg.Config, lo
81
86
}
82
87
83
88
var diffs []string
84
- err := gci . DiffFormattedFilesToArray (fileNames , * cfg , & diffs , lock )
89
+ err := diffFormattedFilesToArray (fileNames , * cfg , & diffs , lock )
85
90
if err != nil {
86
91
return nil , err
87
92
}
@@ -106,6 +111,25 @@ func runGci(pass *analysis.Pass, lintCtx *linter.Context, cfg *gcicfg.Config, lo
106
111
return issues , nil
107
112
}
108
113
114
+ // diffFormattedFilesToArray is a copy of gci.DiffFormattedFilesToArray without io.StdInGenerator.
115
+ // gci.DiffFormattedFilesToArray uses gci.processStdInAndGoFilesInPaths that uses io.StdInGenerator but stdin is not active on CI.
116
+ // https://github.com/daixiang0/gci/blob/6f5cb16718ba07f0342a58de9b830ec5a6d58790/pkg/gci/gci.go#L63-L75
117
+ // https://github.com/daixiang0/gci/blob/6f5cb16718ba07f0342a58de9b830ec5a6d58790/pkg/gci/gci.go#L80
118
+ func diffFormattedFilesToArray (paths []string , cfg gcicfg.Config , diffs * []string , lock * sync.Mutex ) error {
119
+ log .InitLogger ()
120
+ defer func () { _ = log .L ().Sync () }()
121
+
122
+ return gci .ProcessFiles (io .GoFilesInPathsGenerator (paths ), cfg , func (filePath string , unmodifiedFile , formattedFile []byte ) error {
123
+ fileURI := span .URIFromPath (filePath )
124
+ edits := myers .ComputeEdits (fileURI , string (unmodifiedFile ), string (formattedFile ))
125
+ unifiedEdits := gotextdiff .ToUnified (filePath , filePath , string (unmodifiedFile ), edits )
126
+ lock .Lock ()
127
+ * diffs = append (* diffs , fmt .Sprint (unifiedEdits ))
128
+ lock .Unlock ()
129
+ return nil
130
+ })
131
+ }
132
+
109
133
func getErrorTextForGci (settings config.GciSettings ) string {
110
134
text := "File is not `gci`-ed"
111
135
0 commit comments