or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

Commit Message Validator

Build a commit message validator that enforces or warns about subject length limits with configurable strictness levels.

Background

Git commit messages should be concise and well-formatted. A common convention is to limit the subject line (the first line) to a maximum length, typically 50-72 characters. However, teams may want different levels of enforcement: some teams want to strictly block commits that exceed this limit, while others prefer gentle warnings that allow developers to proceed anyway.

Requirements

Create a validator function that checks commit message subject length against a maximum limit. The validator should support two modes:

  1. Error Mode (default): Strictly enforces the limit and returns an error when exceeded
  2. Warning Mode: Returns a warning message but allows the commit to proceed

Inputs

Your function should accept:

  • A commit message subject string
  • A maximum subject length (default: 50 characters)
  • A validation mode flag that determines whether to treat length violations as errors or warnings

Outputs

Return an object with:

  • valid: boolean indicating if the subject length is within the limit
  • message: string describing the validation result (error or warning text, or success message)
  • severity: string indicating "error", "warning", or "success"

Validation Rules

  • If subject length ≤ maximum length: return success
  • If subject length > maximum length in error mode: return error with severity "error"
  • If subject length > maximum length in warning mode: return warning with severity "warning"

Test Cases

  • The validator returns success when subject is within the limit @test
  • The validator returns error when subject exceeds limit in error mode @test
  • The validator returns warning when subject exceeds limit in warning mode @test
  • The validator uses default max length of 50 when not specified @test

Implementation

@generates

API

export interface ValidationResult {
  valid: boolean;
  message: string;
  severity: 'success' | 'warning' | 'error';
}

export interface ValidatorOptions {
  maxSubjectLength?: number;
  ignoreCheckMaxSubjectLength?: boolean;
}

export function validateSubjectLength(
  subject: string,
  options?: ValidatorOptions
): ValidationResult;

Dependencies { .dependencies }

czg { .dependency }

Provides interactive commit message generation with configurable validation modes.