我们的项目使用go标准项目布局。另外,我使用的是pre-commit.com的预提交钩子。
在此设置中,go-vet抱怨:
go vet...................................................................Failed
- hook id: go-vet
- exit code: 1
no Go files in <main directory of the package>这是因为由于项目布局,main.go文件位于cmd/tool/main.go中。
我怎么才能解决这个问题?我不想让兽医瘫痪.
编辑:不好意思,我没有意识到go vet钩子不是来自于预付费网站本身.
那是我的.预提交-config.yaml:
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: git://github.com/dnephin/pre-commit-golang
rev: master
hooks:
- id: go-build
- id: go-critic
- id: go-cyclo
args: [-over=30]
- id: go-fmt
- id: go-imports
# - id: go-lint
- id: go-mod-tidy
# - id: go-unit-tests
- id: go-vet
# - id: golangci-lint
# - id: gometalinter
# - id: validate-toml
exclude: (^vendor/|_test.go$)发布于 2020-11-12 09:51:37
我在dug的钩子里做了更深入的研究,而对run-go-vet.sh的改变解决了我的问题
diff --git a/run-go-vet.sh b/run-go-vet.sh
index 0d21ea4..3de9948 100755
--- a/run-go-vet.sh
+++ b/run-go-vet.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
-pkg=$(go list)
+pkg=$(go list -m)
for dir in $(echo $@|xargs -n1 dirname|sort -u); do
go vet $pkg/$dir
done基本上,go列表将搜索模块而不是包。为什么这能解决我的问题,我不太确定.
https://stackoverflow.com/questions/64784493
复制相似问题