@abelspithost/commitlint
v0.0.3
Published
Shared commitlint preset extending @commitlint/config-conventional with stricter defaults
Maintainers
Readme
@abelspithost/commitlint
A shared commitlint preset that extends @commitlint/config-conventional with stricter defaults, plus a CLI to set everything up with one command.
What's included
- Commitlint configuration that extends
@commitlint/config-conventional - Scope is optional by default
- A
createConfighelper to customize allowed types and scopes (when you provide scopes, they become mandatory) - An
initCLI that installs and configures commitlint + husky automatically - Automatic package manager detection (npm, yarn, pnpm, bun)
Quick setup
Run the init command in your project root:
npx -p @abelspithost/commitlint initThe CLI detects your package manager by looking for bun.lockb/bun.lock, pnpm-lock.yaml, yarn.lock, or falling back to npm. It will:
- Install
husky,@commitlint/cli, and@abelspithost/commitlintas dev dependencies - Initialize husky
- Remove the default
pre-commithook that husky creates - Create a
.husky/commit-msghook (using the correct runner for your package manager) - Generate a
commitlint.config.tsthat re-exports the preset (skip if one already exists)
Manual setup (npm)
Install the required dependencies:
npm install --save-dev husky @commitlint/cli @abelspithost/commitlintCreate a commitlint.config.ts in your project root:
export { default } from '@abelspithost/commitlint';Set up husky and add the commit-msg hook:
npx husky initThen create a .husky/commit-msg file with the following content:
npx --no -- commitlint --edit $1Using createConfig
Use the createConfig helper to customize allowed scopes and types:
import { createConfig } from '@abelspithost/commitlint';
export default createConfig({
scopes: ['api', 'ui', 'core'],
});Options
| Option | Type | Default | Description |
| -------- | ---------- | -------------- | ------------------------------------ |
| scopes | string[] | — | Restrict commits to these scopes (makes scope mandatory) |
| types | string[] | COMMIT_TYPES | Override the allowed commit types |
When you omit scopes, scope is optional and you can use any value. When you provide scopes, scope becomes required and must match one of the listed values. When you omit types, it defaults to the built-in COMMIT_TYPES.
Examples
// Restrict scopes only
import { createConfig } from '@abelspithost/commitlint';
export default createConfig({
scopes: ['api', 'ui', 'core', 'docs'],
});// Custom types and scopes
import { createConfig } from '@abelspithost/commitlint';
export default createConfig({
scopes: ['api', 'ui'],
types: ['feat', 'fix', 'chore'],
});Extending the preset manually
Import the default config and spread it into your own configuration in commitlint.config.ts:
import baseConfig, { RuleConfigSeverity, type UserConfig } from '@abelspithost/commitlint';
const configuration: UserConfig = {
...baseConfig,
rules: {
...baseConfig.rules,
// require a scope in this project
'scope-empty': [RuleConfigSeverity.Error, 'never'],
},
};
export default configuration;This package re-exports RuleConfigSeverity and UserConfig, so you don't need to install @commitlint/types separately.
Commit message format
Write your commits in the Conventional Commits format:
type: description
type(scope): descriptionAllowed types
build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test
Examples
feat: add login endpoint
fix(api): handle null response from user service
docs(readme): add installation instructions