Flake8配置未应用于Git钩子

3

我有一个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机器上运行此操作(因此路径应该格式正确,对吗?)。
或者我的配置文件有误,因此未应用配置。
1个回答

3

钩子程序运行在代码库的根目录,因此选项应该只是--config=.flake8


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接