我在Golang项目中做了一些改动,后来跑了make test
它负责 linting、格式化和单元测试。但是当它运行 linter.sh 时,它会抛出以下错误
pkg/skaffold/kubernetes/wait.go:23: File is not `goimports`-ed with -local github.com/GoogleContainerTools/skaffold (goimports)
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl"
这是Code的链接.
最佳答案
正常做Sort imports
可能不会工作。我想你有 goimports
用 local-prefixes
掉毛已启用,这就是错误 File is not 'goimports'-ed with -local ...
的原因
通常 goimports
以某种方式对导入的库进行排序,以便标准 pkg 和其他库位于一个单独的组中。但是,当您启用本地前缀时,linting 需要标准 pkg、第 3 方 pkg 和具有指定本地前缀的 pkg(在您的情况下 github.com/GoogleContainerTools/skaffold
,又名您自己的项目 pkg),这 3 种类型在不同的组中。 (引用: https://github.com/golangci/golangci-lint/issues/209 )
import (
// stdlib
// third-party
// other packages of that project
)
These doesn't have to be in 3 groups, you can have more that 3 groups. Just make sure that above 3 types (or 2) are not in the same one.
修复
当您运行时
goimports
确保使用 -local
运行它旗帜。我认为您也可以配置您的 IDE 来做到这一点。在你的情况下,它应该是这样的:goimports -local "github.com/GoogleContainerTools/skaffold" -w .
-w flag so that it writes the changes back
. (dot) for all the files or you can specify just one file
关于go - 文件不是 `goimports` -ed with -local somePath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59960394/