git 挂钩中未应用 Flake8 配置
Flake8 config not being applied in git hook
我有一个 pre-commit
git 挂钩,如果添加的行不遵循指定的样式指南,它应该会阻碍提交。
所以在我的存储库的根文件夹中,我有一个 .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 机器上 运行 这个(所以路径格式应该正确,不是吗?)。
或者我的配置文件有问题,因此无法应用。
在存储库的根目录中挂钩 运行,因此选项应该只是 --config=.flake8
我有一个 pre-commit
git 挂钩,如果添加的行不遵循指定的样式指南,它应该会阻碍提交。
所以在我的存储库的根文件夹中,我有一个 .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 机器上 运行 这个(所以路径格式应该正确,不是吗?)。
或者我的配置文件有问题,因此无法应用。
在存储库的根目录中挂钩 运行,因此选项应该只是 --config=.flake8