The rules and configuration system provides the core types for defining, configuring, and executing commitlint rules. This includes severity levels, rule conditions, and the complete mapping of all standard commitlint rules.
enum RuleConfigSeverity {
Disabled = 0,
Warning = 1,
Error = 2
}Rules can be disabled, generate warnings, or cause errors. This enum defines the three severity levels used throughout commitlint.
type RuleConfigCondition = "always" | "never";Rules can be enforced as "always" (rule must pass) or "never" (rule must fail). For example, header-full-stop can be "always" (require full stop) or "never" (forbid full stop).
type RuleConfigTuple<T> = T extends void
? Readonly<[RuleConfigSeverity.Disabled]> | Readonly<[RuleConfigSeverity, RuleConfigCondition]>
: Readonly<[RuleConfigSeverity.Disabled]> | Readonly<[RuleConfigSeverity, RuleConfigCondition, T]>;Rule configurations are expressed as tuples:
[RuleConfigSeverity.Disabled] - Rule is disabled[RuleConfigSeverity, RuleConfigCondition] - Rule with severity and condition[RuleConfigSeverity, RuleConfigCondition, T] - Rule with severity, condition, and additional valueenum RuleConfigQuality {
User,
Qualified
}
type QualifiedRuleConfig<T> =
| (() => RuleConfigTuple<T>)
| (() => Promise<RuleConfigTuple<T>>)
| RuleConfigTuple<T>;
type RuleConfig<V = RuleConfigQuality.Qualified, T = void> =
V extends RuleConfigQuality.Qualified ? RuleConfigTuple<T> : QualifiedRuleConfig<T>;Configuration quality distinguishes between user-provided configs (which may be functions or promises) and qualified configs (resolved to final tuple values).
type CaseRuleConfig<V = RuleConfigQuality.User> = RuleConfig<V, TargetCaseType | TargetCaseType[]>;
type LengthRuleConfig<V = RuleConfigQuality.User> = RuleConfig<V, number>;
type EnumRuleConfig<V = RuleConfigQuality.User> = RuleConfig<V, string[]>;
type AnyRuleConfig<V> = RuleConfig<V, unknown> | RuleConfig<V, void>;Specialized configuration types for common rule value patterns:
type RulesConfig<V = RuleConfigQuality.User> = {
// Body rules
"body-case": CaseRuleConfig<V>;
"body-empty": RuleConfig<V>;
"body-full-stop": RuleConfig<V, string>;
"body-leading-blank": RuleConfig<V>;
"body-max-length": LengthRuleConfig<V>;
"body-max-line-length": LengthRuleConfig<V>;
"body-min-length": LengthRuleConfig<V>;
// Footer rules
"footer-empty": RuleConfig<V>;
"footer-leading-blank": RuleConfig<V>;
"footer-max-length": LengthRuleConfig<V>;
"footer-max-line-length": LengthRuleConfig<V>;
"footer-min-length": LengthRuleConfig<V>;
// Header rules
"header-case": CaseRuleConfig<V>;
"header-full-stop": RuleConfig<V, string>;
"header-max-length": LengthRuleConfig<V>;
"header-min-length": LengthRuleConfig<V>;
"header-trim": RuleConfig<V>;
// Scope rules
"scope-case": CaseRuleConfig<V>;
"scope-empty": RuleConfig<V>;
"scope-enum": EnumRuleConfig<V>;
"scope-max-length": LengthRuleConfig<V>;
"scope-min-length": LengthRuleConfig<V>;
// Subject rules
"subject-case": CaseRuleConfig<V>;
"subject-empty": RuleConfig<V>;
"subject-full-stop": RuleConfig<V, string>;
"subject-max-length": LengthRuleConfig<V>;
"subject-min-length": LengthRuleConfig<V>;
// Type rules
"type-case": CaseRuleConfig<V>;
"type-empty": RuleConfig<V>;
"type-enum": EnumRuleConfig<V>;
"type-max-length": LengthRuleConfig<V>;
"type-min-length": LengthRuleConfig<V>;
// Other rules
"references-empty": RuleConfig<V>;
"signed-off-by": RuleConfig<V, string>;
"trailer-exists": RuleConfig<V, string>;
// Plugin rules
[key: string]: AnyRuleConfig<V>;
};The complete mapping of all 27 standard commitlint rules organized by the commit message component they validate. The [key: string] index signature allows plugins to add custom rules.
type RuleOutcome = Readonly<[boolean, string?]>;
type RuleType = "async" | "sync" | "either";
type BaseRule<Value = never, Type extends RuleType = "either"> = (
parsed: Commit,
when?: RuleConfigCondition,
value?: Value
) => Type extends "either"
? RuleOutcome | Promise<RuleOutcome>
: Type extends "async"
? Promise<RuleOutcome>
: Type extends "sync"
? RuleOutcome
: never;
type Rule<Value = never> = BaseRule<Value, "either">;
type AsyncRule<Value = never> = BaseRule<Value, "async">;
type SyncRule<Value = never> = BaseRule<Value, "sync">;Types for implementing actual rule functions:
[boolean, string?] tuple where boolean indicates success/failure and optional string provides error messageimport { RuleConfigSeverity, RulesConfig } from "@commitlint/types";
const rules: Partial<RulesConfig> = {
"type-enum": [RuleConfigSeverity.Error, "always", ["feat", "fix", "docs", "style"]],
"type-case": [RuleConfigSeverity.Error, "always", "lower-case"],
"subject-max-length": [RuleConfigSeverity.Warning, "always", 50],
"header-full-stop": [RuleConfigSeverity.Error, "never", "."]
};import { QualifiedRules, RuleConfigQuality } from "@commitlint/types";
const qualifiedRules: QualifiedRules = {
"type-enum": [2, "always", ["feat", "fix"]],
"body-leading-blank": [1, "always"]
};import { AnyRuleConfig, RuleConfigQuality } from "@commitlint/types";
const pluginRules: Record<string, AnyRuleConfig<RuleConfigQuality.User>> = {
"custom-rule": [2, "always", { customOption: true }],
"another-rule": [1, "never"]
};