git - 为 golang 存储库运行预提交 Hook 时出现错误 [命名文件必须是 .go 文件 : ./...]

标签 git go githooks pre-commit.com

这是我的 .pre-commit-config.yaml 文件的内容,

repos:
- repo: local
  hooks:
    - id: static-checks-pramod
      name: Static Analysis
      description: This hook does static analysis
      entry: staticcheck -tests=false ./...
      language: golang
      types: [text]

在本地为所有本地文件运行 Hook 时,我遇到以下错误,

pramodchoudhari@Pramods-MacBook-Pro-2 my-repo % pre-commit run --all-files
Static Analysis..........................................................Failed
- hook id: static-checks-pramod
- exit code: 1

-: named files must be .go files: ./...
-: named files must be .go files: ./...
-: named files must be .go files: ./...
-: named files must be .go files: ./...
-: named files must be .go files: ./...
-: named files must be .go files: ./...
-: named files must be .go files: ./...
-: named files must be .go files: ./...

但是如果我在本地运行 staticcheck 命令,它可以正常工作,如下所示,

pramodchoudhari@Pramods-MacBook-Pro-2 my-repo % staticcheck -tests=false ./...         
pramodchoudhari@Pramods-MacBook-Pro-2 my-repo % 

我不确定我在预提交配置中做错了什么。

PS:我正在使用this linter 用于对我的存储库进行静态分析

最佳答案

在您的 .pre-commit-config.yaml 中,您的 types 设置为 text,这会将所有文本(如文件)传递给 staticcheck ,但它只需要 go-files

您可能需要使用types: [go]

关于git - 为 golang 存储库运行预提交 Hook 时出现错误 [命名文件必须是 .go 文件 : ./...],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72611583/

相关文章:

go - 是什么导致 'go build' 以 'unexpected NUL in input' 失败?

go - 在 goroutine 中扭曲 sarama-cluster 消费 Action ,然后它无法消费任何东西

git - 为什么 merge 后的 git hook 没有运行?

git - 如何允许 git merge 提交掌握但防止非 merge 提交?

GitHub Actions 无法将更改部署到 Heroku

git - 无法使用 github 2FA 从命令行提交

go - SOO Go 分包命名

github - 设置可从 GitHub 下载的 ZIP 名称或在 GitHub 上注册 Google Transit 项目的其他方式

git - 从 gitlab 推送到远程 git 服务器时为 "Connection refused - connect(2) (Errno::ECONNREFUSED)"

java - 应用程序运行后是否需要 java .class 文件?