ClaudeLint Class API
The ClaudeLint class is the primary interface for programmatic linting. Use it when you need shared configuration, progress tracking, selective auto-fix, or multiple operations on the same instance.
For simple one-off operations, see the Functional API.
Constructor
new ClaudeLint(options?)
Creates a new ClaudeLint instance with optional configuration.
- Parameters:
options(ClaudeLintOptions, optional) - Configuration options
import { ClaudeLint } from 'claude-code-lint';
const linter = new ClaudeLint({
fix: true,
cwd: process.cwd(),
config: {
rules: { 'claude-md-size': 'warn' },
},
});Instance Methods
lintFiles()
Lints files matching the provided glob patterns.
- Parameters:
patterns(string[]) - Glob patterns to match files - Returns:
LintResult[]- One result per matched file
async lintFiles(patterns: string[]): Promise<LintResult[]>const results = await linter.lintFiles(['**/*.md', '!node_modules/**']);
for (const result of results) {
console.log(`${result.filePath}: ${result.errorCount} errors, ${result.warningCount} warnings`);
}lintText()
Lints text content without requiring a file on disk.
- Parameters:
code(string) - The text content to lint;options(LintTextOptions, optional) - ThefilePathoption determines which validators run - Returns:
LintResult[]
async lintText(code: string, options?: LintTextOptions): Promise<LintResult[]>const results = await linter.lintText('# CLAUDE.md\n\nMy instructions', {
filePath: 'CLAUDE.md',
});loadFormatter()
Loads a formatter by name or path.
- Parameters:
nameOrPath(string) - Built-in name (stylish,json,compact,sarif,github) or path to custom formatter - Returns:
Formatter
async loadFormatter(nameOrPath: string): Promise<Formatter>const formatter = await linter.loadFormatter('stylish');
console.log(formatter.format(results));calculateConfigForFile()
Calculates the effective configuration for a specific file, including overrides.
- Parameters:
filePath(string) - Path to the file - Returns:
ClaudeLintConfig- Resolved config with overrides applied
async calculateConfigForFile(filePath: string): Promise<ClaudeLintConfig>const config = await linter.calculateConfigForFile('skills/test-skill/SKILL.md');
console.log('Active rules:', config.rules);isPathIgnored()
Checks if a file path matches any ignore patterns.
- Parameters:
filePath(string) - Path to check - Returns:
boolean
isPathIgnored(filePath: string): booleanif (linter.isPathIgnored('node_modules/package/file.md')) {
console.log('File is ignored');
}getRulesMetaForResults()
Extracts rule metadata for all rules referenced in lint results.
- Parameters:
results(LintResult[]) - Lint results to extract rule info from - Returns:
Map<string, RuleMetadata>
getRulesMetaForResults(results: LintResult[]): Map<string, RuleMetadata>const rulesUsed = linter.getRulesMetaForResults(results);
for (const [ruleId, meta] of rulesUsed) {
console.log(`${ruleId}: ${meta.description} (${meta.category})`);
}getRules()
Gets metadata for all registered rules.
- Returns:
Map<string, RuleMetadata>
getRules(): Map<string, RuleMetadata>const allRules = linter.getRules();
console.log(`Total rules: ${allRules.size}`);Static Methods
outputFixes()
Writes auto-fixes to disk for all results that have fixes. Only writes files where result.output !== result.source.
- Parameters:
results(LintResult[]) - Results from a lint run withfix: true
static async outputFixes(results: LintResult[]): Promise<void>const linter = new ClaudeLint({ fix: true });
const results = await linter.lintFiles(['**/*.md']);
await ClaudeLint.outputFixes(results);getFixedContent()
Returns fixed content without writing to disk. Useful for previewing fixes.
- Parameters:
results(LintResult[]) - Results from a lint run withfix: true - Returns:
Map<string, string>- Map of file path to fixed content
static getFixedContent(results: LintResult[]): Map<string, string>const fixes = ClaudeLint.getFixedContent(results);
for (const [filePath, fixedContent] of fixes) {
console.log(`Fixed: ${filePath}`);
}getErrorResults()
Filters results to only those containing errors.
- Parameters:
results(LintResult[]) - Results to filter - Returns:
LintResult[]
static getErrorResults(results: LintResult[]): LintResult[]const errors = ClaudeLint.getErrorResults(results);
if (errors.length > 0) process.exit(1);getWarningResults()
Filters results to only those containing warnings.
- Parameters:
results(LintResult[]) - Results to filter - Returns:
LintResult[]
static getWarningResults(results: LintResult[]): LintResult[]const warnings = ClaudeLint.getWarningResults(results);
console.log(`${warnings.length} files with warnings`);findConfigFile()
Finds the nearest configuration file by walking up the directory tree.
- Parameters:
cwd(string) - Directory to start searching from - Returns:
string | null
static findConfigFile(cwd: string): string | nullconst configPath = ClaudeLint.findConfigFile(process.cwd());
if (configPath) console.log(`Found config: ${configPath}`);getVersion()
Returns the claudelint version string.
- Returns:
string
static getVersion(): stringSee Also
- Functional API - Stateless convenience functions
- Types - Complete TypeScript type reference
- Formatters - Built-in and custom formatters
- Recipes - Practical usage patterns and examples