import { ConventionalCommit } from '../models'; /** Severity level for a rule in a ruleset. */ type RuleLevel = 'off' | 'warn' | 'error'; /** A single violation reported by the engine, tagged with its effective severity. */ interface RuleMessage { /** Effective severity for this violation */ readonly level: 'warn' | 'error'; /** Human-readable description of the violation */ readonly message: string; /** Name of the rule that produced the violation */ readonly ruleName: string; } /** Aggregated list of violations produced by the engine for a single ruleset run. */ type RuleResult = readonly RuleMessage[]; /** Runtime context passed to a rule invocation. */ interface RuleContext { /** Effective severity the engine will apply to any violations */ readonly level: RuleLevel; /** Rule-specific options resolved from the ruleset config */ readonly options?: TOptions; } /** * Pure rule definition. Implementations inspect a `ConventionalCommit` and return * zero or more violation messages. The engine applies severity from the ruleset * config and aggregates `RuleMessage`s across all rules. */ interface Rule { /** Stable identifier used to key the rule in a `Ruleset` */ readonly name: string; /** * Checks the commit against this rule. * * @param commit - Parsed conventional commit to validate * @param context - Resolved severity and options for this invocation * @returns List of violation descriptions; empty when the commit passes */ check(commit: ConventionalCommit, context: RuleContext): readonly string[]; } /** * Configuration tuple for a single rule in a ruleset. * * A bare `[level]` entry disables the rule when level is `'off'`, or enables it * with no options otherwise. The `[level, options]` form passes rule-specific * options through to the rule's `check()` implementation. */ type RuleConfig = readonly [RuleLevel] | readonly [RuleLevel, TOptions]; /** * Mapping from rule name to its config tuple. Rules not present in the map are * treated as `'off'` by the engine. */ type Ruleset = Readonly>; /** Aggregated outcome of running a ruleset over a commit. */ interface ValidationResult { /** True when no error-level violations were recorded */ readonly valid: boolean; /** Warn-level violations (non-blocking) */ readonly warnings: readonly RuleMessage[]; /** Error-level violations (blocking) */ readonly errors: readonly RuleMessage[]; } /** Options for the header-max-length rule. */ interface HeaderMaxLengthOptions { /** Maximum allowed header length. Use `null` to disable the check. */ readonly maxLength: number | null; } /** * Rule that fails when the reconstructed header (`type(scope)!: subject`) * exceeds the configured maximum length. * * @example Enforcing a 72-character header limit * ```typescript * headerMaxLengthRule.check( * parseConventionalCommit('feat(core): short subject'), * { level: 'warn', options: { maxLength: 72 } } * ) * // => [] * ``` */ declare const headerMaxLengthRule: Rule; /** Default past-tense → imperative word map used when options are omitted. */ declare const DEFAULT_IMPERATIVE_WORDLIST: Readonly>; /** Options for the imperative-mood rule. */ interface ImperativeMoodOptions { /** * Map of past-tense words (lowercase) to their suggested imperative forms. * Overrides `DEFAULT_IMPERATIVE_WORDLIST` when provided. */ readonly wordlist?: Readonly>; } /** * Rule that reports a warning when the first subject word (case-insensitive) * matches a known past-tense form. Never blocks; intended as a nudge. * * @example Hinting on past-tense verbs * ```typescript * imperativeMoodRule.check( * parseConventionalCommit('feat: added login'), * { level: 'warn' } * ) * // => ['subject should use imperative mood: use "add" instead of "added"'] * ``` */ declare const imperativeMoodRule: Rule; /** Options for the scope-enum rule. */ interface ScopeEnumOptions { /** Allowed scope identifiers. Empty array disables the check. */ readonly scopes: readonly string[]; } /** * Rule that fails when any scope on the commit is not in the configured * allow-list. A commit with no scopes (empty array) always passes; when scopes * are required, pair this rule with a separate scope-empty check. * * @example Enforcing a scope enum * ```typescript * scopeEnumRule.check( * parseConventionalCommit('feat(auth): add login'), * { level: 'error', options: { scopes: ['auth', 'api'] } } * ) * // => [] * ``` */ declare const scopeEnumRule: Rule; /** Supported subject-case modes. */ type SubjectCase = 'sentence-case' | 'lower-case' | 'upper-case' | 'kebab-case' | 'snake-case' | 'start-case'; /** Options for the subject-case rule. */ interface SubjectCaseOptions { /** One or more accepted case forms. A subject passing any accepted form is valid. */ readonly cases: readonly SubjectCase[]; } /** * Rule that fails when the commit subject does not match any of the configured * case forms. An empty subject always passes (handled by subject-empty). * * @example Enforcing lower-case subjects * ```typescript * subjectCaseRule.check( * parseConventionalCommit('feat: Add login'), * { level: 'error', options: { cases: ['lower-case'] } } * ) * // => ['subject must be one of [lower-case] but was "Add login"'] * ``` */ declare const subjectCaseRule: Rule; /** Options for the type-enum rule. */ interface TypeEnumOptions { /** Allowed commit type identifiers. Empty array disables the check. */ readonly types: readonly string[]; } /** * Rule that fails when the commit type is not in the configured allow-list. * * @example Enforcing a conventional type enum * ```typescript * typeEnumRule.check( * parseConventionalCommit('feat: add x'), * { level: 'error', options: { types: ['feat', 'fix'] } } * ) * // => [] * ``` */ declare const typeEnumRule: Rule; /** Registry of built-in rules the engine knows how to run, keyed by rule name. */ declare const BUILT_IN_RULES: Readonly>>; /** * Runs every rule configured in the ruleset against a parsed commit and * aggregates the resulting warnings and errors. * * Rules whose config is `'off'` (or absent from the ruleset) are skipped. * Unknown rule names in the ruleset are ignored: consumers extend the engine * by calling `validateCommitWithRules()` and supplying additional rules. * * @param commit - Parsed conventional commit to validate * @param ruleset - Configuration map from rule name to `[level, options?]` * @returns Aggregated validation result * * @example Validating a commit against a preset ruleset * ```typescript * validateCommit(parseConventionalCommit('feat: add login'), conventionalPreset) * // => { valid: true, warnings: [], errors: [] } * ``` */ declare function validateCommit(commit: ConventionalCommit, ruleset: Ruleset): ValidationResult; /** * Variant of `validateCommit` that accepts a caller-supplied rule registry. * Useful for consumers that want to add project-specific rules without * forking the built-in set. * * @param commit - Parsed conventional commit to validate * @param ruleset - Configuration map from rule name to `[level, options?]` * @param rules - Rule registry keyed by rule name * @returns Aggregated validation result * * @example Extending the built-in rules with a custom rule * ```typescript * const customRules = { ...BUILT_IN_RULES, 'no-wip': noWipRule } * validateCommitWithRules(commit, { 'no-wip': ['error'] }, customRules) * ``` */ declare function validateCommitWithRules(commit: ConventionalCommit, ruleset: Ruleset, rules: Readonly>>): ValidationResult; /** Conventional Commits default type enum used by the preset. */ declare const CONVENTIONAL_TYPES: readonly string[]; /** * Default ruleset mirroring `@commitlint/config-conventional`'s baseline. * * | Rule | Level | Options | * | ------------------ | ----- | ------------------------ | * | type-enum | error | `CONVENTIONAL_TYPES` | * | subject-empty | error | — | * | scope-enum | off | — | * | subject-case | off | — | * | header-max-length | warn | `{ maxLength: 72 }` | * | imperative-mood | warn | — | */ declare const conventionalPreset: Ruleset; /** * Rule that fails when the commit subject is empty or whitespace-only. * * @example Enforcing a non-empty subject * ```typescript * subjectEmptyRule.check( * parseConventionalCommit('feat: '), * { level: 'error' } * ) * // => ['subject must not be empty'] * ``` */ declare const subjectEmptyRule: Rule; /** * Parses a raw commit message and validates the resulting commit against the * supplied ruleset. Used by the `cl` bin and anywhere else validation must * start from a string rather than a parsed commit. * * @param raw - Raw commit message (as written to `.git/COMMIT_EDITMSG`) * @param ruleset - Configuration map from rule name to `[level, options?]` * @returns Aggregated validation result * * @example Validating a raw commit message * ```typescript * validateCommitMessage('feat: add login', conventionalPreset) * // => { valid: true, warnings: [], errors: [] } * * validateCommitMessage('feat: added login', conventionalPreset).warnings * // => [{ level: 'warn', ruleName: 'imperative-mood', message: ... }] * ``` */ declare function validateCommitMessage(raw: string, ruleset: Ruleset): ValidationResult; export { BUILT_IN_RULES, CONVENTIONAL_TYPES, DEFAULT_IMPERATIVE_WORDLIST, conventionalPreset, headerMaxLengthRule, imperativeMoodRule, scopeEnumRule, subjectCaseRule, subjectEmptyRule, typeEnumRule, validateCommit, validateCommitMessage, validateCommitWithRules }; export type { HeaderMaxLengthOptions, ImperativeMoodOptions, Rule, RuleConfig, RuleContext, RuleLevel, RuleMessage, RuleResult, Ruleset, ScopeEnumOptions, SubjectCase, SubjectCaseOptions, TypeEnumOptions, ValidationResult };