How to automatically enforce coding standards for a Java codebase with pre-commit
Overview
In this video tutorial, we demonstrated how to automatically enforce coding standards for a Java codebase using pre-commit, precommit4j and Checkstyle.
When working on a codebase as a team or with multiple contributors. It’s good to have an agreed-upon coding standards to guide how new code changes will occur.
Pre-commit is a development tool that runs pre-configured checks on the source code before an Engineer commits their changes locally. This way, every code change made to production will conform to the established standard.
In this tutorial, we will go through:
- Setting up pre-commit on the local machine
- Configuring pre-commit for a codebase
- Using precommit4j to run Checkstyle and validate Java source files
- Adding pre-commit check to the pipeline for guaranteed compliance
Resources
-
Complete source code https://github.com/SeunMatt/request-v…
-
precommit4j is available here https://github.com/SeunMatt/precommit4j/
-
pre-commit homepage https://pre-commit.com/#intro
-
Checkstyle homage https://checkstyle.sourceforge.io/
Happy Coding