commithelper
raw JSON → 1.2.0 verified Fri May 01 auth: no javascript maintenance
A CLI tool for creating and linting commit messages. Current stable version is 1.2.0 (released 2021-06-11), with a maintenance cadence. It offers two modes: `prompt` for interactively building a commit message and `check` for linting existing messages. Unlike commitlint, it provides guided prompts with valid options, and unlike commitizen, it also supports linting. Configuration can be placed in package.json or a separate config file. Integrates with git hooks via husky or ghooks.
Common errors
error Cannot find module 'commithelper' ↓
cause Package not installed or incorrect import path.
fix
Run 'npm install commithelper --save-dev' and ensure you are using the correct import syntax.
error SyntaxError: Cannot use import statement outside a module ↓
cause Running ESM code in a CommonJS context.
fix
Set 'type': 'module' in package.json or use .mjs extension for your script.
error commithelper: command not found ↓
cause CLI not in PATH or bin not linked.
fix
Use npx commithelper or ensure node_modules/.bin is in PATH.
error TypeError: commithelper.check is not a function ↓
cause Wrong import or using default export instead of named export.
fix
Use import { check } from 'commithelper' instead of default import.
Warnings
breaking Package is ESM-only since v1.2.0. CommonJS require() will fail. ↓
fix Use import syntax or switch to a dynamic import if using CJS.
deprecated Version 1.1.1 had a missing shebang in the CLI entry point, causing scripts to fail. ↓
fix Upgrade to 1.2.0+.
gotcha Check mode with --fix may rewrite your commit message file; ensure you have a backup. ↓
fix Use --fix only on files under version control or after review.
gotcha Prompt mode reads from a file path specified by --file. If the file contains non-comment lines, no questions are asked and the program exits successfully. ↓
fix Ensure the file is empty or contains only comments for interactive prompting.
Install
npm install commithelper yarn add commithelper pnpm add commithelper Imports
- default wrong
const commithelper = require('commithelper')correctimport commithelper from 'commithelper' - check wrong
const check = require('commithelper/check')correctimport { check } from 'commithelper' - prompt wrong
import { prompt } from 'commithelper/prompt'correctimport { prompt } from 'commithelper'
Quickstart
import { check } from 'commithelper';
import fs from 'fs';
const commitMessage = fs.readFileSync('.git/COMMIT_EDITMSG', 'utf8');
const result = check(commitMessage);
if (!result.valid) {
console.error('Commit message invalid:', result.errors);
process.exit(1);
} else {
console.log('Commit message is valid.');
}