У меня есть хук 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/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
как-то не правильно. Я запускаю это на машине с Windows под cygwin (так что путь должен быть отформатирован правильно, нет?).
Или что каким-то образом мой файл конфигурации неверен, и поэтому он не применяется.