@hybrbase-staxomni/commitlint-config
v1.0.0
Published
A shareable commitlint configuration for projects.
Downloads
2
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 @hybrbase-staxomni/commitlint-config
To configure the
commitlint.config.js
file, include the following line:module.exports = { extends: ['@hybrbase-staxomni/commitlint-config'], }
This extends the
@hybrbase-staxomni/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: ['@hybrbase-staxomni/commitlint-config'],
rules: {
'body-leading-blank': [2, 'always'],
},
}