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

tessl/npm-commitlint--types

Shared TypeScript type definitions for the commitlint ecosystem.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@commitlint/types@19.8.x

To install, run

npx @tessl/cli install tessl/npm-commitlint--types@19.8.0

index.mddocs/

@commitlint/types

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

Package Information

  • Package Name: @commitlint/types
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @commitlint/types

Core Imports

import {
  RuleConfigSeverity,
  RulesConfig,
  LintOutcome,
  UserConfig,
  Formatter,
  TargetCaseType
} from "@commitlint/types";

For CommonJS:

const {
  RuleConfigSeverity,
  RulesConfig,
  LintOutcome,
  UserConfig,
  Formatter,
  TargetCaseType
} = require("@commitlint/types");

Basic Usage

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}`);
    });
  }
}

Architecture

@commitlint/types is organized into eight specialized modules:

  • Rules Engine: Core types for rule definition, configuration, and execution
  • Configuration System: Types for loading and validating commitlint configurations
  • Linting Pipeline: Types for the commit message linting process and results
  • Formatting System: Types for customizable output formatting and reporting
  • Parser Integration: Types for commit message parsing using conventional-commits-parser
  • Plugin System: Types for extending commitlint with custom rules and functionality
  • Case Validation: Types for enforcing text case conventions across commit components
  • Interactive Prompts: Types for guided commit message creation and validation

Capabilities

Rules and Configuration

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>;
}

Rules and Configuration

Linting Operations

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;
}

Linting Operations

Configuration Loading

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;
}

Configuration Loading

Output Formatting

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;
}

Output Formatting

Case Validation

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";

Case Validation

Plugin System

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">;

Plugin System

Interactive Prompts

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;
          };
        };
      }
    >
  >;
}

Interactive Prompts

Commit Parsing

Types for integrating with conventional-commits-parser to parse and analyze commit message structure.

type Parser = (message: string, options: Options) => Omit<Commit, "raw">;

Commit Parsing

Common Types

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
}