If someone did a quick study to see how many Git commits were for forgetting to check PEP8 compliance before pushing, I bet it would be on the order of 3% as an initial guess. This clutter can be eliminated by making a simple Git pre-commit hook that applies to all repositories.
This procedure is for Unix-like systems (Linux, MacOS) and native Windows. The script used is written in Python to make it OS agnostic.
Tell Git the directory for Git hooks:
git config --global core.hooksPath ~/.git/hooks
Create executable file
(without the .py in the filename).
This global pre-commit check hook does three things:
- get a list of Python file names that changed.
- check PEP8, mypy type hinting and that Python ≥ 3.7
breakpointdebug statements are not present.
- Checks for trailing whitespaces in any code language.
One can easily extend the concept of lint-checking for other programming languages.
These checks can be bypassed at any time for a commit by:
git commit -n
- Git precommit hooks docs