Shared TypeScript type definitions for the commitlint ecosystem.
npx @tessl/cli install tessl/npm-commitlint--types@19.8.0@commitlint/types provides shared TypeScript type definitions for the commitlint ecosystem, a tool that checks if commit messages meet conventional commit format standards. This package serves as the foundational type library that enables type safety and consistency across all commitlint components including linting, configuration, formatting, and rule validation.
npm install @commitlint/typesimport {
RuleConfigSeverity,
RulesConfig,
LintOutcome,
UserConfig,
Formatter,
TargetCaseType
} from "@commitlint/types";For CommonJS:
const {
RuleConfigSeverity,
RulesConfig,
LintOutcome,
UserConfig,
Formatter,
TargetCaseType
} = require("@commitlint/types");import { RuleConfigSeverity, RulesConfig, LintOutcome } from "@commitlint/types";
// Define rule configuration
const rules: Partial<RulesConfig> = {
"type-enum": [RuleConfigSeverity.Error, "always", ["feat", "fix", "docs"]],
"subject-max-length": [RuleConfigSeverity.Warning, "always", 50]
};
// Process lint results
function handleLintResult(result: LintOutcome): void {
if (!result.valid) {
result.errors.forEach(error => {
console.error(`Error: ${error.name} - ${error.message}`);
});
result.warnings.forEach(warning => {
console.warn(`Warning: ${warning.name} - ${warning.message}`);
});
}
}@commitlint/types is organized into eight specialized modules:
Core types for defining commitlint rules, their severity levels, and configuration options. These types power the entire rule validation system.
enum RuleConfigSeverity {
Disabled = 0,
Warning = 1,
Error = 2
}
type RuleConfigCondition = "always" | "never";
type RuleConfigTuple<T> = T extends void
? Readonly<[RuleConfigSeverity.Disabled]> | Readonly<[RuleConfigSeverity, RuleConfigCondition]>
: Readonly<[RuleConfigSeverity.Disabled]> | Readonly<[RuleConfigSeverity, RuleConfigCondition, T]>;
interface RulesConfig<V = RuleConfigQuality.User> {
"body-case": CaseRuleConfig<V>;
"body-empty": RuleConfig<V>;
"header-max-length": LengthRuleConfig<V>;
"type-enum": EnumRuleConfig<V>;
// ... 27+ standard commitlint rules
[key: string]: AnyRuleConfig<V>;
}Types for executing lint operations on commit messages and processing the results with detailed error and warning information.
interface LintOutcome {
input: string;
valid: boolean;
errors: LintRuleOutcome[];
warnings: LintRuleOutcome[];
}
interface LintRuleOutcome {
valid: boolean;
level: RuleConfigSeverity;
name: string;
message: string;
}
interface LintOptions {
defaultIgnores?: boolean;
ignores?: Matcher[];
parserOpts?: Options;
plugins?: PluginRecords;
helpUrl?: string;
}Types for loading, processing, and validating commitlint configuration files with support for extends, plugins, and presets.
interface UserConfig {
extends?: string | string[];
formatter?: string;
rules?: Partial<RulesConfig>;
parserPreset?: string | ParserPreset | Promise<ParserPreset>;
ignores?: ((commit: string) => boolean)[];
defaultIgnores?: boolean;
plugins?: (string | Plugin)[];
helpUrl?: string;
prompt?: UserPromptConfig;
[key: string]: unknown;
}
interface QualifiedConfig {
extends: string[];
formatter: string;
rules: QualifiedRules;
parserPreset?: ParserPreset;
ignores?: ((commit: string) => boolean)[];
defaultIgnores?: boolean;
plugins: PluginRecords;
helpUrl: string;
prompt: UserPromptConfig;
}Types for customizing the display and formatting of lint results with support for colors, symbols, and various output formats.
type Formatter = (
report: FormattableReport,
options: FormatOptions
) => string;
interface FormattableReport {
results?: (FormattableResult & WithInput)[];
}
interface FormatOptions {
color?: boolean;
signs?: readonly [string, string, string];
colors?: readonly [ChalkColor, ChalkColor, ChalkColor];
verbose?: boolean;
helpUrl?: string;
}Types for enforcing consistent text case formatting across different parts of commit messages.
type TargetCaseType =
| "camel-case"
| "kebab-case"
| "snake-case"
| "pascal-case"
| "start-case"
| "upper-case"
| "uppercase"
| "sentence-case"
| "sentencecase"
| "lower-case"
| "lowercase"
| "lowerCase";Types for creating and integrating custom rules and functionality through the commitlint plugin architecture.
interface Plugin {
rules: {
[ruleName: string]: Rule | AsyncRule | SyncRule;
};
}
type PluginRecords = Record<string, Plugin>;
type Rule<Value = never> = BaseRule<Value, "either">;
type AsyncRule<Value = never> = BaseRule<Value, "async">;
type SyncRule<Value = never> = BaseRule<Value, "sync">;Types for creating guided commit message creation interfaces with customizable prompts and validation.
type RuleField = "header" | "type" | "scope" | "subject" | "body" | "footer";
type PromptName =
| RuleField
| "isBreaking"
| "breakingBody"
| "breaking"
| "isIssueAffected"
| "issuesBody"
| "issues";
interface PromptConfig {
settings: {
scopeEnumSeparator: string;
enableMultipleScopes: boolean;
};
messages: PromptMessages;
questions: Partial<
Record<
PromptName,
{
description?: string;
messages?: { [K: string]: string };
enum?: {
[enumName: string]: {
description?: string;
title?: string;
emoji?: string;
};
};
}
>
>;
}Types for integrating with conventional-commits-parser to parse and analyze commit message structure.
type Parser = (message: string, options: Options) => Omit<Commit, "raw">;type Matcher = (commit: string) => boolean;
interface IsIgnoredOptions {
ignores?: Matcher[];
defaults?: boolean;
}
type RuleOutcome = Readonly<[boolean, string?]>;
type RuleType = "async" | "sync" | "either";
enum RuleConfigQuality {
User,
Qualified
}