在运行Golang Repo的预加入挂钩时会出现错误[命名文件必须为.go文件:。/...]
这是我的 .pre-commit-config.yam l文件的限制,
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]
在本地运行挂钩的所有文件时,本地im会遇到的错误,
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用于对我的存储库进行静态分析
This is the contenct of my .pre-commit-config.yaml file,
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]
on running the hooks locally for all the files locally im getting below error,
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: ./...
but if i run staticcheck command locally, it work fine as below,
pramodchoudhari@Pramods-MacBook-Pro-2 my-repo % staticcheck -tests=false ./...
pramodchoudhari@Pramods-MacBook-Pro-2 my-repo %
I'm not sure what i'm doing wrong in pre-commit-config.
PS: I'm using this linter for doing static analysis of my repo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(2)
在您的
.pre-commit-config.yaml
您的types
设置为text
,它将将所有像文件之类的文本传递给staticcheck
,但它仅期望go-files
。您可能想要
类型:[GO]
而不是。In your
.pre-commit-config.yaml
yourtypes
is set totext
, which will pass all text like files tostaticcheck
, but it only expectsgo-files
.You probably want
types: [go]
instead.您的配置是 close ,但有一些可以改进的东西。现在,您正在安装一个NOOP
Golang
存储库,然后对两个。/...
(Golang speak中的所有内容)和所有text> text
您的存储库中的文件(可能不是您想要的!)首先让我们来地址NOOP存储库 -
语言:Golang
指示pre-Commit
如何安装挂钩本身 -在这种情况下,您尚未告诉它安装任何内容(repo:local
Hook通常使用affe_deppedencies
安装东西),例如,您想让您想要预先支配来管理安装(毕竟这是预先承诺的一部分 - 它可以管理您的安装,因此您无需指示贡献者如何安装所有内容)这样:
现在让我们解决要通过的文件 - 上面的@jkittner击中了这一点,但我会详细说明。
pre-commit
's 参数模式:然后从使用类型的过滤文件:
,将这些文件放在一起,您的当前配置就像运行
staticcheck -tests = false。/... $(git ls -files)< /code>(假设您只有文本文件,我实际上没有一个很好的外壳方法来过滤二进制文件),
您可能想过滤到go files,而您可能不想double-lint每个文件 - 而是尝试一下:
或者,如果您始终想运行所有内容(我不建议这样做,它会一直使其一直放慢!),您可以关闭Pre-pre-提交对文件
免责声明的处理:我写了预订
your configuration is close but has a few things that can be improved. right now you're installing a noop
golang
repository and then running against both./...
(everything in golang speak) and alltext
files in your repository (probably not what you want!)first let's address that noop repository --
language: golang
instructspre-commit
how it should install the hook itself -- in this case you haven't told it to install anything (arepo: local
hook usually usesadditional_dependencies
to install things)let's say you wanted pre-commit to manage the installation (this is, part of the point of pre-commit after all -- it manages your installation so you don't need to instruct your contributors on how to install everything) -- for that you'd tell pre-commit to install something like this:
now let's tackle the files being passed -- @jkittner above hits this right on the head but I'll elaborate a little bit.
pre-commit
's argument pattern:and then from filtering files with types:
putting those to together, your current configuration is something like running
staticcheck -tests=false ./... $(git ls-files)
(assuming you only have text files, there isn't really a good shell way I know of to filter out binary files)you probably want to filter down to go files, and you probably don't want to double-lint every file -- try this instead:
alternatively, if you always want to run everything (which I wouldn't recommend, it'll make it slow all the time!) you could instead turn off pre-commit's processing of files
disclaimer: I wrote pre-commit