Code linting with pre-commit
Though a very small & basic thing, code linting often gets ignored by many people in many projects. Probably because it's small.
There's a problem that I've been facing consistently during code reviews. I, personally, can't ignore incorrect indentations, and often when I found one, I keep looking for them. Hence, my focus shifts from finding potential logical bugs to linting errors. There goes the code quality👇 !
While setting up the foundation of Plio's enhanced platform, we knew this small thing (along with some other practices) had to be taken seriously from the beginning. In my quest to find what's the best way to do this without troubling programmers to configure their code editors, I came across Pre-commit.
As the name suggests, it uses git hooks to perform certain actions right before a commit happens.
Here's how the pre-commit-config.yaml file for Plio backend (Django) app looks like:
The best thing is pre-commit is multi-lingual, so we're following the same practice for the frontend app as well!
Here's how the pre-commit-config.yaml file for the Plio frontend (VueJS) app looks like:
With just a file and a couple of commands, the hook warns and fixes the linting errors in the files that are going into the commit whenever changes are committed. This is an easy and persistent way to get the formatted code checked in and improve code review quality!
More at Pre-commit official website.