@wayofdev/commitlint-config
v4.0.0
Published
A shareable commitlint configuration for projects.
Downloads
254
Readme
Shareable Commitlint Config
📄 About
A shareable commitlint configuration for enforcing consistent commit messages in your projects.
→ Purpose
- Provides a set of rules to ensure that all commits in your project follow a consistent structure.
- Consistent commit messages are important for project collaboration, maintainability, and project history.
- The commitlint configuration helps ensure that all commits in your project follow a consistent structure, making it easier for your team to understand what changes were made and why.
💿 Installation
This package should be added to the root of your monorepo, where you have a file commitlint.config.js
and a package.json
file. Within your monorepo, you should have a structure with directories for your apps and packages, such as:
.
├── commitlint.config.js (root)
├── package.json (root)
├── apps
│ └── my-first-app
│ ├── package.json
│ └── ... (other app files)
└── packages
└── my-first-package
├── package.json
└── ... (other package files)
To use this configuration, you'll need to install this package as a devDependency in your monorepository's root:
pnpm add -wD @commitlint/cli @wayofdev/commitlint-config
To configure the
commitlint.config.js
file, include the following line:module.exports = { extends: ["@wayofdev/commitlint-config"], }
This extends the
@wayofdev/commitlint-config
and uses its pre-defined configuration.Alternatively the configuration can be defined in a
commitlint.config.js
,.commitlintrc.js
,.commitlintrc
,.commitlintrc.json
,.commitlintrc.yml
fileInstall Husky in your monorepository as devDependency. Husky is a handy git hook helper available on npm.
# Install as dev-dependency into root of monorepo $ pnpm add -wD husky is-ci # Activate hooks $ pnpm husky install
Add commit-msg hook:
npx husky add .husky/commit-msg 'pnpm commitlint --edit "${1}"'
Add scripts to
package.json
pnpm pkg set scripts.lint:commits="pnpm commitlint --from HEAD~1 --to HEAD --verbose" pnpm pkg set scripts.prepare="is-ci || husky install"
💻 Usage
→ Test simple usage
For a first simple usage test of commitlint you can do the following:
# using pnpm
$ pnpm commitlint --from HEAD~1 --to HEAD --verbose
# or, using npx
$ npx commitlint --from HEAD~1 --to HEAD --verbose
# or, if script was added
$ pnpm lint:commits
This will check your last commit and return an error if invalid or a positive output if valid.
→ Test the hook
You can test the hook by simply committing. If the commit message is valid, the commit will go through, otherwise you will see an error message.
Here's an example of what the error message would look like if your commit message doesn't meet the required format:
$ git commit -m "foo: this will fail"
husky > commit-msg (node v10.1.0)
No staged files match any of provided globs.
⧗ input: foo: this will fail
✖ type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test] [type-enum]
✖ found 1 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
husky > commit-msg hook failed (add --no-verify to bypass)
If your commit message meets the required format, you should see a message like this:
$ git commit -m "feat: add new feature"
husky > commit-msg (node v10.1.0)
[master 9d41607] feat: add new feature
1 file changed, 1 insertion(+)
🧩 Extending
This shows, how config can be extended with your custom rules.
commitlint.config.js
module.exports = {
extends: ["@wayofdev/commitlint-config"],
rules: {
"body-leading-blank": [2, "always"],
},
}
🤝 License
🧱 Credits and Useful Resources
Based on:
Related projects:
Guides:
🙆🏼♂️ Author Information
This repository was created in 2023 by lotyp / wayofdev.
🙌 Want to Contribute?
Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:
- 🤔 Suggest a feature
- 🐛 Report an issue
- 📖 Improve documentation
- 👨💻 Contribute to the code
You are more than welcome. Before contributing, kindly check our guidelines.