使用 pre-commit.com,如何修复 go vet 错误 "no Go files in"
Using pre-commit.com, How can I fix go vet error "no Go files in"
我们的项目使用go standards project layout. Also, I'm using the pre-commit-hooks from 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...
编辑:
抱歉,我没有意识到 go vet
钩子不是来自 pre-commit.com 本身...
那是我的.pre-commit-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$)
我深入研究了 dnephin 的钩子,对 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 list 将搜索模块而不是包。 为什么 解决了我的问题,我不太确定....
我们的项目使用go standards project layout. Also, I'm using the pre-commit-hooks from 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...
编辑:
抱歉,我没有意识到 go vet
钩子不是来自 pre-commit.com 本身...
那是我的.pre-commit-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$)
我深入研究了 dnephin 的钩子,对 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 list 将搜索模块而不是包。 为什么 解决了我的问题,我不太确定....