@commitlint/cz-commitlint is a Commitizen adapter that integrates with commitlint configuration to provide an interactive commit message prompt system. It bridges the gap between Commitizen's interactive commit creation and commitlint's commit message validation by using a single commitlint.config.js configuration file for both tools.
npm install --save-dev @commitlint/cz-commitlint commitizen inquirer@9This package is designed as a Commitizen adapter and does not export functions for direct programmatic use. Instead, it is configured as a Commitizen adapter in your package.json:
{
"config": {
"commitizen": {
"path": "@commitlint/cz-commitlint"
}
}
}The package exports only one function for internal Commitizen integration:
import { prompter } from "@commitlint/cz-commitlint";After installation and configuration, use the adapter through Commitizen commands:
# After installation and configuration
npm run commit
# or
yarn commit
# or
git-czThe adapter workflow:
commitlint.config.js configurationThe adapter is built around several key internal components:
The main and only public entry point for Commitizen that orchestrates the entire interactive commit process.
/**
* Entry point for commitizen - the only exported function
* @param inquirerIns - Inquirer instance passed by commitizen (unused)
* @param commit - Callback to execute with complete commit message
*/
function prompter(
inquirerIns: {
prompt(questions: DistinctQuestion[]): Promise<Answers>;
},
commit: (message: string) => void
): void;This function is automatically called by Commitizen when configured as an adapter. It loads your commitlint configuration and generates interactive prompts based on your rules.
/**
* Inquirer answer type
*/
interface Answers {
[key: string]: any;
}
/**
* Inquirer question type
*/
interface DistinctQuestion {
name?: string;
type?: string;
message?: string | Function;
default?: any;
choices?: any;
validate?: Function;
filter?: Function;
transformer?: Function;
when?: Function | boolean;
pageSize?: number;
prefix?: string;
suffix?: string;
}The adapter is configured through your existing commitlint.config.js file. You can customize prompts by adding a prompt section:
module.exports = {
extends: ['@commitlint/config-conventional'],
prompt: {
questions: {
type: {
description: 'Select the type of change that you are committing:',
enum: {
feat: {
description: 'A new feature'
},
fix: {
description: 'A bug fix'
},
docs: {
description: 'Documentation only changes'
},
style: {
description: 'Changes that do not affect the meaning of the code'
},
refactor: {
description: 'A code change that neither fixes a bug nor adds a feature'
},
perf: {
description: 'A code change that improves performance'
},
test: {
description: 'Adding missing tests or correcting existing tests'
},
build: {
description: 'Changes that affect the build system or external dependencies'
},
ci: {
description: 'Changes to our CI configuration files and scripts'
},
chore: {
description: 'Other changes that do not modify src or test files'
},
revert: {
description: 'Reverts a previous commit'
}
}
},
scope: {
description: 'What is the scope of this change (e.g. component or file name)'
},
subject: {
description: 'Write a short, imperative tense description of the change'
},
body: {
description: 'Provide a longer description of the change'
},
isBreaking: {
description: 'Are there any breaking changes?'
},
breakingBody: {
description: 'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself'
},
breaking: {
description: 'Describe the breaking changes'
},
isIssueAffected: {
description: 'Does this change affect any open issues?'
},
issuesBody: {
description: 'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself'
},
issues: {
description: 'Add issue references (e.g. "fix #123", "re #123".)'
}
},
messages: {
skip: '(press enter to skip)',
max: '(max %d chars)',
min: '(min %d chars)',
emptyWarning: '%s is required',
upperLimitWarning: '%s over limit by %d chars',
lowerLimitWarning: '%s under limit by %d chars'
},
settings: {
enableMultipleScopes: false,
scopeEnumSeparator: ','
}
}
};The adapter automatically converts your commitlint rules into appropriate interactive questions:
The adapter ensures consistency between commit creation and validation by using the same configuration file for both processes.