gci: remove the use of stdin (#2984)
Co-authored-by: Tom Moulard <tom.moulard@traefik.io>
This commit is contained in:
parent
a913b3e955
commit
fd87bd1efb
2
go.mod
2
go.mod
@ -44,6 +44,7 @@ require (
|
|||||||
github.com/gostaticanalysis/nilerr v0.1.1
|
github.com/gostaticanalysis/nilerr v0.1.1
|
||||||
github.com/hashicorp/go-multierror v1.1.1
|
github.com/hashicorp/go-multierror v1.1.1
|
||||||
github.com/hashicorp/go-version v1.6.0
|
github.com/hashicorp/go-version v1.6.0
|
||||||
|
github.com/hexops/gotextdiff v1.0.3
|
||||||
github.com/jgautheron/goconst v1.5.1
|
github.com/jgautheron/goconst v1.5.1
|
||||||
github.com/jingyugao/rowserrcheck v1.1.1
|
github.com/jingyugao/rowserrcheck v1.1.1
|
||||||
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af
|
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af
|
||||||
@ -132,7 +133,6 @@ require (
|
|||||||
github.com/gostaticanalysis/comment v1.4.2 // indirect
|
github.com/gostaticanalysis/comment v1.4.2 // indirect
|
||||||
github.com/hashicorp/errwrap v1.0.0 // indirect
|
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/hexops/gotextdiff v1.0.3 // indirect
|
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
github.com/kisielk/gotool v1.0.0 // indirect
|
github.com/kisielk/gotool v1.0.0 // indirect
|
||||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||||
|
@ -7,6 +7,11 @@ import (
|
|||||||
|
|
||||||
gcicfg "github.com/daixiang0/gci/pkg/config"
|
gcicfg "github.com/daixiang0/gci/pkg/config"
|
||||||
"github.com/daixiang0/gci/pkg/gci"
|
"github.com/daixiang0/gci/pkg/gci"
|
||||||
|
"github.com/daixiang0/gci/pkg/io"
|
||||||
|
"github.com/daixiang0/gci/pkg/log"
|
||||||
|
"github.com/hexops/gotextdiff"
|
||||||
|
"github.com/hexops/gotextdiff/myers"
|
||||||
|
"github.com/hexops/gotextdiff/span"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/tools/go/analysis"
|
"golang.org/x/tools/go/analysis"
|
||||||
|
|
||||||
@ -81,7 +86,7 @@ func runGci(pass *analysis.Pass, lintCtx *linter.Context, cfg *gcicfg.Config, lo
|
|||||||
}
|
}
|
||||||
|
|
||||||
var diffs []string
|
var diffs []string
|
||||||
err := gci.DiffFormattedFilesToArray(fileNames, *cfg, &diffs, lock)
|
err := diffFormattedFilesToArray(fileNames, *cfg, &diffs, lock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -106,6 +111,25 @@ func runGci(pass *analysis.Pass, lintCtx *linter.Context, cfg *gcicfg.Config, lo
|
|||||||
return issues, nil
|
return issues, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// diffFormattedFilesToArray is a copy of gci.DiffFormattedFilesToArray without io.StdInGenerator.
|
||||||
|
// gci.DiffFormattedFilesToArray uses gci.processStdInAndGoFilesInPaths that uses io.StdInGenerator but stdin is not active on CI.
|
||||||
|
// https://github.com/daixiang0/gci/blob/6f5cb16718ba07f0342a58de9b830ec5a6d58790/pkg/gci/gci.go#L63-L75
|
||||||
|
// https://github.com/daixiang0/gci/blob/6f5cb16718ba07f0342a58de9b830ec5a6d58790/pkg/gci/gci.go#L80
|
||||||
|
func diffFormattedFilesToArray(paths []string, cfg gcicfg.Config, diffs *[]string, lock *sync.Mutex) error {
|
||||||
|
log.InitLogger()
|
||||||
|
defer func() { _ = log.L().Sync() }()
|
||||||
|
|
||||||
|
return gci.ProcessFiles(io.GoFilesInPathsGenerator(paths), cfg, func(filePath string, unmodifiedFile, formattedFile []byte) error {
|
||||||
|
fileURI := span.URIFromPath(filePath)
|
||||||
|
edits := myers.ComputeEdits(fileURI, string(unmodifiedFile), string(formattedFile))
|
||||||
|
unifiedEdits := gotextdiff.ToUnified(filePath, filePath, string(unmodifiedFile), edits)
|
||||||
|
lock.Lock()
|
||||||
|
*diffs = append(*diffs, fmt.Sprint(unifiedEdits))
|
||||||
|
lock.Unlock()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func getErrorTextForGci(settings config.GciSettings) string {
|
func getErrorTextForGci(settings config.GciSettings) string {
|
||||||
text := "File is not `gci`-ed"
|
text := "File is not `gci`-ed"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user