A robust configuration for enforcing conventional commits using Husky and Commitlint, ensuring consistent and descriptive commit messages for your projects.
This repository demonstrates how to integrate Commitlint with Husky in your project to automate the validation of commit messages. By adopting this setup, you can:
- Enforce commit message standards like Conventional Commits.
- Maintain a clean, understandable commit history.
- Improve collaboration and project traceability.
- Seamless Integration: Configures Husky to automatically run Commitlint on every commit.
- Customizable Rules: Easily adapt Commitlint rules to match your project's conventions.
- Plug-and-Play: A preconfigured example you can clone or use as a reference.
Follow these steps to set up Commitlint with Husky in your project.
git clone https://github.com/GitArika/commitlint-husky.git
cd commitlint-husky
Run the following command to install required dependencies:
npm install
The repository includes pre-configured settings for Commitlint and Husky:
- Commitlint Rules: Defined in
.commitlintrc.js
. Modify the rules as needed to enforce your custom commit message conventions. - Husky Hooks: Configured in
.husky/commit-msg
to automatically validate commit messages before they are committed.
Try making a commit to test the validation:
git commit -m "invalid message"
Commitlint will reject non-conforming messages, ensuring compliance with your rules.
The default rules enforce Conventional Commits:
module.exports = {
extends: ['@commitlint/config-conventional'],
};
Feel free to extend or override these rules to match your team's standards.
The hook ensures Commitlint runs on every commit:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit "$1"
Contributions are welcome! If you'd like to enhance this repository or suggest improvements, follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature/improve-docs
- Push your changes and create a pull request.
For questions, suggestions, or collaboration opportunities, feel free to reach out:
- Email: [email protected]
- GitHub: GitArika
This repository is licensed under the MIT License. Use it freely in your projects.