or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

case-validation.mdconfiguration.mdformatting.mdindex.mdlinting.mdparsing.mdplugins.mdprompts.mdrules-config.md
tile.json

rules-config.mddocs/

Rules and Configuration

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.

Rule Configuration Types

Rule Severity

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.

Rule Conditions

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).

Rule Configuration Tuples

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 value

Configuration Quality Levels

enum 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).

Specialized Rule Configurations

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:

  • CaseRuleConfig: For rules that validate text case (single case or array of acceptable cases)
  • LengthRuleConfig: For rules that validate length limits (number value)
  • EnumRuleConfig: For rules that validate against allowed values (string array)
  • AnyRuleConfig: Generic rule config for plugins and custom rules

Complete Rules Configuration

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.

Rule Implementation Types

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:

  • RuleOutcome: [boolean, string?] tuple where boolean indicates success/failure and optional string provides error message
  • RuleType: Execution type constraint for rules (async, sync, or either)
  • BaseRule: Generic rule function signature accepting parsed commit, condition, and value
  • Rule/AsyncRule/SyncRule: Specialized rule function types

Usage Examples

Basic Rule Configuration

import { 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", "."]
};

Qualified Rule Configuration

import { QualifiedRules, RuleConfigQuality } from "@commitlint/types";

const qualifiedRules: QualifiedRules = {
  "type-enum": [2, "always", ["feat", "fix"]],
  "body-leading-blank": [1, "always"]
};

Plugin Rule Configuration

import { AnyRuleConfig, RuleConfigQuality } from "@commitlint/types";

const pluginRules: Record<string, AnyRuleConfig<RuleConfigQuality.User>> = {
  "custom-rule": [2, "always", { customOption: true }],
  "another-rule": [1, "never"]
};