What is @commitlint/format?
@commitlint/format is a package used to format commit messages according to specified rules. It is part of the commitlint suite, which helps enforce consistent commit message conventions.
What are @commitlint/format's main functionalities?
Format Commit Messages
This feature allows you to format the results of commit message linting. The `format` function takes an object with a `results` array and returns a formatted string that can be logged or displayed.
const { format } = require('@commitlint/format');
const results = [
{ valid: true, errors: [], warnings: [] },
{ valid: false, errors: [{ message: 'type may not be empty' }], warnings: [] }
];
const output = format({ results });
console.log(output);
Other packages similar to @commitlint/format
commitizen
Commitizen is a tool that helps you write consistent commit messages by providing an interactive prompt. Unlike @commitlint/format, which focuses on formatting and linting commit messages, Commitizen guides you through the process of writing them.
conventional-changelog
Conventional Changelog is a tool that generates changelogs based on commit messages that follow a specific convention. While @commitlint/format is used for formatting commit messages, Conventional Changelog focuses on generating changelogs from those messages.
semantic-release
Semantic Release automates the versioning and package publishing process based on commit messages. It uses commit message conventions to determine the type of release. Unlike @commitlint/format, which is used for formatting commit messages, Semantic Release automates the release process.
Format commitlint reports
@commitlint/format
Getting started
npm install --save @commitlint/format
Example
const format = require('@commitlint/format').default;
const output = format(
{
valid: false,
errorCount: 1,
warningCount: 1,
results: [
{
valid: false,
input: 'some: commit message',
errors: [
{
valid: false,
level: 2,
name: 'some-error',
message: 'This will show up red as it has level 2',
},
],
warnings: [
{
valid: true,
level: 0,
name: 'some-hint',
message: 'This will not show up as it has level 0',
},
{
valid: false,
level: 1,
name: 'some-warning',
message: 'This will show up yellow as it has level 1',
},
],
},
],
},
{
color: false,
}
);
process.stdout.write(output);
Consult docs/api for comprehensive documentation.