gpt4 book ai didi

python - 带有 .toml 配置和预提交钩子(Hook)的 Flakehell

转载 作者:行者123 更新时间:2023-12-05 01:08:52 24 4
gpt4 key购买 nike

我正在尝试将 flakehell 作为预提交 Hook 运行。

我的 .pre-commit-config.yaml:

repos:
- repo: local
hooks:
- id: flakehell
name: flakehell
entry: flakehell lint project/
language: python
pass_filenames: true
stages: [push, commit]
verbose: true

pyproject.toml:

[tool.flakehell]
exclude = ["README.md"]
format = "colored"
show_source = true

[tool.flakehell.plugins]
flake8-bandit = ["+*", "-S322"]
flake8-bugbear = ["+*"]
flake8-builtins = ["+*"]
flake8-comprehensions = ["+*"]
flake8-darglint = ["+*"]
flake8-docstrings = ["+*"]
flake8-eradicate = ["+*"]
flake8-isort = ["+*"]
flake8-mutable = ["+*"]
flake8-pytest-style = ["+*"]
flake8-spellcheck = ["+*"]
mccabe = ["+*"]
pep8-naming = ["+*"]
pycodestyle = ["+*"]
pyflakes = ["+*"]
pylint = ["+*"]

还有一些问题。当我尝试使用 git commit 时,我看到 flakehell 开始工作。几秒钟后它失败了,我得到了错误:

“UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 10 中的字节 0xb8: 无效起始字节”

没有“预提交”它会很好用(我的意思是当我只输入“flakehell lint”时)

是否可以将 flakehell 配置为预提交?

如果没有 - 您是否为 python 项目推荐任何更好/有效的解决方案?

最佳答案

您的配置不正确,您没有使用 filestypes 限制传递给您的钩子(Hook)的文件,因此它默认为您存储库中的所有文件.大概你有一些二进制文件正在传递给 flakehell

我还注意到您的配置同时传递了一个路径并具有 pass_filenames: true (pass_filenames: true 是默认设置,因此您不应该使用它)

您要么想要在 args 中列出路径(不推荐,因为您总是 lint 超过您正在更改的内容)或者您想要正确过滤文件名

此外,verbose: true 不适合在调试之外使用,因为它会给输出添加警告噪音

此外,您不是通过预提交管理 flakehell 的安装,这会给您的贡献者增加额外的负担,以尝试在本地设置任何开发环境,预提交的大部分 Gist 是它管理安装您的工具,这样您的贡献者就不必费力地进行正确的格式化/linting 设置(消除一整类“它在我的机器上工作”的问题)

此外,flakehell 似乎直接支持预提交,所以你不需要像你正在做的那样使用 repo: local 逃生舱口

把所有这些放在一起,你可能想要这样的东西:

repos:
- repo: https://github.com/life4/flakehell
rev: v.0.7.1
hooks:
- id: flakehell

如果您想使用本地配置,您可能需要以下内容:

repos:
- repo: local
hooks:
- id: flakehell
name: flakehell
entry: flakehell lint
types: [python]
files: ^project/
language: python
additional_dependencies: [flakehell==0.7.1]
stages: [push, commit]

免责声明:我是 pre-commit 的创建者

关于python - 带有 .toml 配置和预提交钩子(Hook)的 Flakehell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65658117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com