Skip to content

TypeScript Types

Complete TypeScript type reference for the claudelint API. All types are exported from claude-code-lint.

typescript
import {
  ClaudeLint, LintResult, LintMessage, ClaudeLintOptions,
  ClaudeLintConfig, Formatter, RuleMetadata,
} from 'claude-code-lint';

Result Types

LintResult

Complete validation result for a single file.

typescript
interface LintResult {
  filePath: string;
  messages: LintMessage[];
  suppressedMessages: LintMessage[];
  errorCount: number;
  warningCount: number;
  fixableErrorCount: number;
  fixableWarningCount: number;
  source?: string;
  output?: string;
  deprecatedRulesUsed?: DeprecatedRuleUsage[];
  stats?: {
    validationTime: number;
  };
}
PropertyTypeDescription
filePathstringAbsolute path to the linted file
messagesLintMessage[]Validation messages (errors and warnings)
suppressedMessagesLintMessage[]Messages suppressed via inline disable comments
errorCountnumberNumber of error-level messages
warningCountnumberNumber of warning-level messages
fixableErrorCountnumberNumber of errors with automatic fixes
fixableWarningCountnumberNumber of warnings with automatic fixes
sourcestring?Original source code (when available)
outputstring?Fixed source code (when fixes applied)
deprecatedRulesUsedDeprecatedRuleUsage[]?Deprecated rules that were triggered
statsobject?Performance statistics (validationTime in ms)

LintMessage

Individual validation message for a specific issue.

typescript
interface LintMessage {
  ruleId: string | null;
  severity: 'error' | 'warning';
  message: string;
  line?: number;
  column?: number;
  endLine?: number;
  endColumn?: number;
  fix?: FixInfo;
  suggestions?: SuggestionInfo[];
  explanation?: string;
  howToFix?: string;
}
PropertyTypeDescription
ruleIdstring | nullRule identifier (null for non-rule messages)
severity'error' | 'warning'Severity level
messagestringHuman-readable description of the issue
linenumber?Line number where issue starts (1-based)
columnnumber?Column number where issue starts (1-based)
endLinenumber?Line number where issue ends (1-based). Reserved for future use.
endColumnnumber?Column number where issue ends (1-based). Reserved for future use.
fixFixInfo?Automatic fix information
suggestionsSuggestionInfo[]?Alternative fix suggestions. Reserved for future use.
explanationstring?Detailed explanation of why this matters
howToFixstring?Step-by-step fix instructions

FixInfo

Information about an automatic fix.

typescript
interface FixInfo {
  range: [number, number];
  text: string;
}
  • range - Start and end character offsets (0-based, start inclusive, end exclusive)
  • text - Replacement text to insert at the range

When fix is present on a LintMessage, you can apply it by splicing the source string:

typescript
const fixed = source.slice(0, fix.range[0]) + fix.text + source.slice(fix.range[1]);

You can also use ClaudeLint.outputFixes(results) or check result.output for auto-fixed content.

SuggestionInfo

Information about a suggested fix.

typescript
interface SuggestionInfo {
  desc: string;
  fix: FixInfo;
}
  • desc - Description of what this suggestion does
  • fix - The suggested fix information

Options Types

ClaudeLintOptions

Constructor options for the ClaudeLint class. Also used by the functional lint() wrapper as LintOptions.

typescript
interface ClaudeLintOptions {
  // Configuration
  config?: ClaudeLintConfig;
  overrideConfigFile?: string;

  // Linting behavior
  fix?: boolean | ((message: LintMessage) => boolean);
  fixTypes?: string[];
  allowInlineConfig?: boolean;
  reportUnusedDisableDirectives?: boolean;

  // File handling
  cwd?: string;
  ignore?: boolean;
  ignorePatterns?: string[];
  errorOnUnmatchedPattern?: boolean;

  // Caching
  cache?: boolean;
  cacheLocation?: string;
  cacheStrategy?: 'metadata' | 'content';

  // Progress callbacks
  onStart?: (fileCount: number) => void;
  onProgress?: (file: string, index: number, total: number) => void;
  onComplete?: (results: LintResult[]) => void;

  // Filtering
  ruleFilter?: (ruleId: string) => boolean;
}

Configuration:

  • config - Explicit ClaudeLintConfig object (overrides config file)
  • overrideConfigFile - Path to config file (overrides auto-discovery)

Linting behavior:

  • fix - Enable auto-fix: boolean or predicate function (default: false)
  • fixTypes - Types of fixes to apply (e.g., ['problem', 'suggestion'])
  • allowInlineConfig - Allow inline disable comments (default: true)
  • reportUnusedDisableDirectives - Warn about unused disable comments (default: false)

File handling:

  • cwd - Working directory (default: process.cwd())
  • ignore - Enable ignore patterns from config (default: true)
  • ignorePatterns - Additional glob patterns to ignore
  • errorOnUnmatchedPattern - Throw if patterns match no files (default: true)

Caching:

  • cache - Enable result caching (default: false)
  • cacheLocation - Cache directory (default: '.claudelint-cache')
  • cacheStrategy - 'metadata' or 'content' (default: 'metadata')

Progress callbacks:

  • onStart - Called when linting starts with file count
  • onProgress - Called for each file with path, index, and total
  • onComplete - Called when linting completes with results

Filtering:

  • ruleFilter - Predicate to filter which rules run

LintTextOptions

Options for linting text content.

typescript
interface LintTextOptions {
  filePath?: string;
  warnIgnored?: boolean;
}
  • filePath - Virtual file path that determines which validators run (default: random temp file)
  • warnIgnored - Warn if the file path would be ignored

ConfigOptions, FileInfoOptions, LoadFormatterOptions

These option types all accept a single optional field:

typescript
interface ConfigOptions {
  cwd?: string;  // Working directory (default: process.cwd())
}
// FileInfoOptions and LoadFormatterOptions have the same shape

Configuration Types

ClaudeLintConfig

Complete claudelint configuration object.

typescript
interface ClaudeLintConfig {
  extends?: string | string[];
  rules?: Record<string, RuleConfig | 'off' | 'warn' | 'error'>;
  overrides?: ConfigOverride[];
  ignorePatterns?: string[];
  output?: {
    format?: 'stylish' | 'json' | 'compact' | 'sarif' | 'github';
    verbose?: boolean;
    color?: boolean;
    collapseRepetitive?: boolean;
  };
  reportUnusedDisableDirectives?: boolean;
  maxWarnings?: number;
}
PropertyTypeDescription
extendsstring | string[]Extend base configuration(s)
rulesRecord<string, RuleConfig | 'off' | 'warn' | 'error'>Rule configuration map (accepts objects or shorthand strings)
overridesConfigOverride[]File-specific rule overrides
ignorePatternsstring[]Glob patterns to ignore
outputobjectOutput settings: format (built-in name), verbose, color, collapseRepetitive
reportUnusedDisableDirectivesbooleanWarn about unused disable comments
maxWarningsnumberMaximum warnings before exit code 1

Example:

typescript
const config: ClaudeLintConfig = {
  extends: 'recommended',
  rules: {
    'claude-md-size': 'warn',
    'skill-missing-examples': { severity: 'error', options: { minExamples: 2 } },
  },
  ignorePatterns: ['node_modules/**', 'dist/**'],
  overrides: [
    {
      files: ['skills/**/*.md'],
      rules: { 'skill-body-too-long': 'off' },
    },
  ],
  maxWarnings: 10,
};

RuleConfig

Configuration for a single rule. The rules map accepts both shorthand strings and full objects.

typescript
// Shorthand (in rules map values)
type RuleConfigShorthand = 'error' | 'warn' | 'off';

// Full form
interface RuleConfig {
  severity: 'off' | 'warn' | 'error';
  options?: Record<string, unknown>;
}

Usage:

typescript
const rules = {
  'claude-md-size': 'warn',                                    // shorthand
  'skill-missing-examples': 'off',                                     // shorthand
  'skill-body-too-long': { severity: 'error', options: { maxLength: 5000 } },  // full
};

ConfigOverride

File-specific rule overrides applied by glob pattern.

typescript
interface ConfigOverride {
  files: string[];
  rules: Record<string, RuleConfig | 'off' | 'warn' | 'error'>;
}
  • files - Glob patterns to match (uses minimatch)
  • rules - Rule configuration to apply to matched files

LintOptions

Alias for ClaudeLintOptions, used by the functional lint() wrapper.

typescript
type LintOptions = ClaudeLintOptions;

DeprecatedRuleUsage

Information about a deprecated rule that was triggered during linting.

typescript
interface DeprecatedRuleUsage {
  ruleId: string;
  reason: string;
  replacedBy?: string[];
  deprecatedSince?: string;
  removeInVersion?: string | null;
  url?: string;
}
PropertyTypeDescription
ruleIdstringRule ID of the deprecated rule
reasonstringWhy this rule is deprecated
replacedBystring[]?Replacement rule IDs
deprecatedSincestring?Version when deprecated
removeInVersionstring | null?Version when it will be removed
urlstring?URL to migration guide

Formatter Types

Formatter

Interface for formatting lint results. Both built-in and custom formatters implement this.

typescript
interface Formatter {
  format(results: LintResult[]): string;
}

BaseFormatter

Abstract base class for custom formatters with path resolution helpers.

typescript
abstract class BaseFormatter implements Formatter {
  abstract format(results: LintResult[]): string;
  protected getRelativePath(filePath: string): string;
  protected getSummary(results: LintResult[]): {
    fileCount: number;
    errorCount: number;
    warningCount: number;
    fixableErrorCount: number;
    fixableWarningCount: number;
    totalIssues: number;
  };
}

FormatterOptions

typescript
interface FormatterOptions {
  cwd?: string;
  color?: boolean;
}

Metadata Types

RuleMetadata

Metadata about a validation rule, returned by getRules() and getRulesMetaForResults().

typescript
interface RuleMetadata {
  ruleId: string;
  description: string;
  category: string;
  severity: 'error' | 'warning';
  fixable: boolean;
  explanation?: string;
  docs?: string;
}
PropertyTypeDescription
ruleIdstringUnique rule identifier
descriptionstringBrief description
categorystringRule category (e.g., 'CLAUDE.md', 'Skills')
severity'error' | 'warning'Default severity level
fixablebooleanWhether the rule supports auto-fix
explanationstring?Detailed explanation
docsstring?Documentation URL

FileInfo

Information about a file without linting it.

typescript
interface FileInfo {
  ignored: boolean;
  validators: string[];
}
  • ignored - Whether the file matches ignore patterns
  • validators - Names of validators that would run on this file

Utility Functions

These helper functions are also exported from claude-code-lint:

FunctionDescription
isBuiltinFormatter(name: string): booleanCheck if a formatter name is built-in
isFormatter(obj: unknown): obj is FormatterType guard to validate the Formatter interface
findConfigFile(startDir: string): string | nullFind the nearest config file by walking up the directory tree
loadConfig(configPath: string): ClaudeLintConfigLoad and parse a configuration file

See Also