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

linting.mddocs/

Linting Operations

The linting system provides types for executing lint operations on commit messages and processing the results. This includes configuration options, outcome reporting, and integration with the parser and rule systems.

Lint Configuration

Lint Options

interface LintOptions {
  /** If it should ignore the default commit messages (defaults to `true`) */
  defaultIgnores?: IsIgnoredOptions["defaults"];
  /** Additional commits to ignore, defined by ignore matchers */
  ignores?: IsIgnoredOptions["ignores"];
  /** The parser configuration to use when linting the commit */
  parserOpts?: Options;
  
  plugins?: PluginRecords;
  helpUrl?: string;
}

Configuration options for lint operations:

  • defaultIgnores: Whether to ignore default commit patterns (merge commits, etc.)
  • ignores: Array of custom matcher functions to ignore specific commits
  • parserOpts: Configuration for the conventional-commits-parser
  • plugins: Plugin registry for custom rules
  • helpUrl: URL to documentation for additional help

Ignore Patterns

type Matcher = (commit: string) => boolean;

interface IsIgnoredOptions {
  ignores?: Matcher[];
  defaults?: boolean;
}

System for defining which commits should be ignored during linting:

  • Matcher: Function that returns true if a commit should be ignored
  • IsIgnoredOptions: Configuration combining custom matchers with default ignore patterns

Lint Rule Configuration

type LintRuleConfig = Record<
  string,
  | Readonly<[RuleConfigSeverity.Disabled]>
  | RuleConfigTuple<void>
  | RuleConfigTuple<unknown>
>;

Mapping of rule names to their configuration tuples, used specifically in linting contexts.

Lint Results

Lint Outcome

interface LintOutcome {
  /** The linted commit, as string */
  input: string;
  /** If the linted commit is considered valid */
  valid: boolean;
  /** All errors, per rule, for the commit */
  errors: LintRuleOutcome[];
  /** All warnings, per rule, for the commit */
  warnings: LintRuleOutcome[];
}

Complete result of linting a single commit message:

  • input: Original commit message that was linted
  • valid: Overall validation status (false if any errors exist)
  • errors: Array of rule violations with severity level 2 (Error)
  • warnings: Array of rule violations with severity level 1 (Warning)

Individual Rule Outcomes

interface LintRuleOutcome {
  /** If the commit is considered valid for the rule */
  valid: boolean;
  /** The "severity" of the rule (1 = warning, 2 = error) */
  level: RuleConfigSeverity;
  /** The name of the rule */
  name: string;
  /** The message returned from the rule, if invalid */
  message: string;
}

Result of applying a single rule to a commit:

  • valid: Whether this specific rule passed
  • level: Severity level from the rule configuration
  • name: Identifier of the rule that was applied
  • message: Human-readable description of the violation (if any)

Usage Examples

Basic Linting Configuration

import { LintOptions, Matcher } from "@commitlint/types";

// Custom ignore patterns
const customIgnores: Matcher[] = [
  (commit) => commit.startsWith("WIP:"),
  (commit) => commit.includes("[skip ci]"),
  (commit) => /^Merge branch/.test(commit)
];

const lintOptions: LintOptions = {
  defaultIgnores: true,
  ignores: customIgnores,
  parserOpts: {
    headerPattern: /^(\w*)(?:\(([\w$.\-* ]*)\))?: (.*)$/,
    headerCorrespondence: ["type", "scope", "subject"]
  }
};

Processing Lint Results

import { LintOutcome, RuleConfigSeverity } from "@commitlint/types";

function processLintResult(result: LintOutcome): void {
  console.log(`Linting: "${result.input}"`);
  
  if (result.valid) {
    console.log("✅ Commit message is valid");
    return;
  }
  
  // Process errors (severity 2)
  if (result.errors.length > 0) {
    console.log("❌ Errors:");
    result.errors.forEach(error => {
      console.log(`  - ${error.name}: ${error.message}`);
    });
  }
  
  // Process warnings (severity 1)  
  if (result.warnings.length > 0) {
    console.log("⚠️  Warnings:");
    result.warnings.forEach(warning => {
      console.log(`  - ${warning.name}: ${warning.message}`);
    });
  }
}

Custom Ignore Matchers

import { Matcher, IsIgnoredOptions } from "@commitlint/types";

// Ignore commits from dependabot
const ignoreDependabot: Matcher = (commit: string) => {
  return commit.includes("dependabot") || commit.startsWith("Bump ");
};

// Ignore revert commits
const ignoreReverts: Matcher = (commit: string) => {
  return commit.startsWith("Revert ");
};

// Ignore commits with specific prefixes
const ignorePrefix: Matcher = (commit: string) => {
  const ignoredPrefixes = ["chore(release):", "docs(readme):", "test:"];
  return ignoredPrefixes.some(prefix => commit.startsWith(prefix));
};

const ignoreOptions: IsIgnoredOptions = {
  defaults: true, // Keep default ignore patterns
  ignores: [ignoreDependabot, ignoreReverts, ignorePrefix]
};

Rule-Specific Configuration

import { LintRuleConfig, RuleConfigSeverity } from "@commitlint/types";

const lintRules: LintRuleConfig = {
  "type-enum": [RuleConfigSeverity.Error, "always", ["feat", "fix", "docs"]],
  "type-case": [RuleConfigSeverity.Error, "always", "lower-case"],
  "subject-case": [RuleConfigSeverity.Warning, "always", "sentence-case"],
  "subject-max-length": [RuleConfigSeverity.Error, "always", 50],
  "body-leading-blank": [RuleConfigSeverity.Warning, "always"],
  "footer-leading-blank": [RuleConfigSeverity.Warning, "always"]
};

Error Analysis

import { LintRuleOutcome, RuleConfigSeverity } from "@commitlint/types";

function analyzeRuleViolations(outcomes: LintRuleOutcome[]): void {
  const errorsByRule = new Map<string, number>();
  const warningsByRule = new Map<string, number>();
  
  outcomes.forEach(outcome => {
    if (!outcome.valid) {
      const map = outcome.level === RuleConfigSeverity.Error ? errorsByRule : warningsByRule;
      const count = map.get(outcome.name) || 0;
      map.set(outcome.name, count + 1);
    }
  });
  
  console.log("Most common rule violations:");
  console.log("Errors:", Array.from(errorsByRule.entries()));
  console.log("Warnings:", Array.from(warningsByRule.entries()));
}