【发布时间】:2019-07-17 14:02:05
【问题描述】:
我有一个 pre-commit git 钩子,如果添加的行不遵循指定的样式指南,它应该会阻碍提交。
所以在我的 repo 的根文件夹中,我有一个 .flake8 文件,看起来像:
[flake8]
########## FORMATTING ##########
# Print the total number of errors.
#count =
## Print the source code generating the error/warning in question.
#show-source =
## Count the number of occurrences of each error/warning code and print a report.
#statistics =
########## OPTIONS ##########
# Set the maximum length that any line (with some exceptions) may be.
max-line-length = 90
# Set the maximum allowed McCabe complexity value for a block of code.
max-complexity = 10
########## RULES ##########
ignore = D102,D103,E265
########## TARGETS ##########
# Redirect all output to the specified file.
#output-file =
## Also print output to stdout if output-file has been configured.
#tee =
我的 git 钩子在 .git/hooks/pre-commit 下,拥有完整权限:rwxrwxrwx(我知道不是最安全的)。
#!/bin/sh
#
# Checks so that the file is correctly linted, before commiting.
# Using the same linter settings as defined in the repo root .flake8
#
LINT=$(git diff -- '***.py' | py -3 -m flake8 --diff --config="../../.flake8")
#LINT=$(git diff -- '***.py' | py -3 -m flake8 --diff --max-line-length=90)
if [ -z "$LINT" ]
then
exit 0
else
echo "$LINT"
exit 1
fi
如果我将LINT 变量更改为注释掉的变量,则该钩子会起作用。然后它标记过长的行。但是如果我指定我的配置文件,那么它不会标记它。
我认为错误是--config="../../.flake8 不知何故不正确。我在 cygwin 下的 Windows 机器上运行它(所以路径的格式应该正确,不是吗?)。
或者我的配置文件有问题,因此它没有被应用。
【问题讨论】: