
Note that because this is a commit-msg hook, we would need to have ran pre-commit install -t commit-msg to install it. While installing commit hooks with pre-commit are as easy as running pre-commit install, this can be integrated with Maven using the Exec Maven Plugin configured to run against the “initialize” phase. This does still require the file to be configured. There is a hook configuration, commitlint-pre-commit-hook, for using commitlint. Ultimately, if we are wanting to conform to one of the Conventional Commits formats for our commit messages, then we will end up using NPM in our hooks. If one of your developers doesn’t have node installed but modifies a JavaScript file, pre-commit automatically handles downloading and building node to run eslint without root.

pre-commit is specifically designed to not require root access. You specify a list of hooks you want and pre-commit manages the installation and execution of any hook written in any language before every commit. It is a multi-language package manager for pre-commit hooks. We built pre-commit to solve our hook issues. If you’re writing a project in node you should be able to use scss-lint as a pre-commit hook without adding a Gemfile to your project or understanding how to get scss-lint installed. For example scss-lint is a linter for SCSS written in Ruby. Some of the best linters are written in languages that you do not use in your project or have installed on your machine.

We believe that you should always use the best industry standard linters. The introduction for this tool describes it best. Pre-commit is a framework for managing and maintaining multi-language pre-commit hooks. I wanted to find a solution that could be integrated with the Maven lifecycle, like Husky does for NPM. I had a look for a similar solution for Maven, but could not immediately find one. With this, I have been using commitlint for ensuring commit messages conform to a standard format, as well as ensuring code has had linting checks ran against it.

In the NPM world, Husky is a tool which is used to maintain commit hooks through the package.json file, and integrates with the NPM build lifecycle to keep the contents of the local “.git/hooks” folder up to date. However, the configuration files which control these client-side hooks cannot be committed to the repository and need to be configured on each client once the repository has been checked out. Git hooks are a fantastic first step for identifying issues before code is pushed to a repository.
