Search code examples
gitgithooksflake8

Flake8 config not being applied in git hook


I have a pre-commit git hook that is supposed to hinder the commit if the added lines don't follow the specified style-guide.

So in the root folder of my repo I have a .flake8 file that looks like:

[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 = 

And my git hook that is under .git/hooks/pre-commit with full rights: rwxrwxrwx (I know not the safest).

#!/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

The hook works if I change the LINT variable to the out commented one. Then it marks the row that is to long. But If I specify my config file instead then it does not mark it.

I think that the error is either that the --config="../../.flake8 is somehow not correct. I'm running this on a windows machine under cygwin (so the path should be formatted correct, no?).

Or that somehow my config file is wrong and thus it doesn't get applied.


Solution

  • Hooks run in the root of the repository so the option should be just --config=.flake8