Git - pre-commit-hooks
You like clean code, don't you? And you hate getting an email from your versioning tool (e.g. Github or GitLab) telling you that your last commit didn't go through, that the formatting of your code is bad; this is because you've left one space too many at the end of a line or you've used single quote instead of double (or the opposite), for example.
You've pushed your changes, already start to work on another activity, perhaps another project and boum, two hours after your last commit (because the CI server was working on a lot of pipelines before yours), boum, you get a Your last commit has failed, #gnagnagna. I hate it as much as I love clean code.
So, what should we do to avoid this?
The answer is simple! Before each push, we should run the same code analysis tools that are executed in the CI, i.e. phplint
, php-cs-fixer
, phpcbf
, phan
, phpstan
, ... (for PHP) or pylint
, mypy
, prospector
, black
, ruff
, ... (for Python) or shellcheck
and shellformat
(for Linux Bash) or ...
We should, but do we think about it every time? Unfortunately not.
Let's see how to correct this.