Using pre-commit to improve our code
What is pre-commit?
Git hooks can catch trivial issues like missing semicolons or trailing whitespace before code review, freeing up reviewer time for more in-depth architectural examinations. However, distributing these hooks across projects can be difficult, especially when various languages or environments are used.
Pre-commit is a hooks package management that supports multiple languages. Specify the hooks you require, and it will install and execute them before each commit. There is no requirement for root access or manual tweaks for various project architectures. It even handles dependencies, such as downloading and constructing node for ESLint if the developer does not have node installed.
Installation
Steps for getting started with Pre-Commit
- Install Pre-Commit
use the above commands to install pre-commit
Add a pre-commit configuration
create a file named
.pre-commit-config.yaml
Set up the git hook scripts
To configure the git hook scripts, run pre-commit install.
Run against All files
pre-commit run --all-files
Conclusion
To summarise, including pre-commit into your development workflow can improve code quality, streamline collaboration, and minimize needless errors. Pre-commit helps teams discover errors early by automating checks and guaranteeing uniform code standards, resulting in a more efficient and reliable development process. Adopting this technology not only improves codebase health but also fosters a quality and collaboration culture among engineers. Consider using pre-commit to improve your coding practices and confidently deliver higher-quality products.
Subscribe to my newsletter
Read articles from Aditya Pachauri directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by