@felixgeelhaar/cclint
Version:
A comprehensive linter for CLAUDE.md files with multi-language code block validation
44 lines • 1.72 kB
JavaScript
import { ContextFile } from '../domain/ContextFile.js';
import { Violation } from '../domain/Violation.js';
import { Location } from '../domain/Location.js';
import { Severity } from '../domain/Severity.js';
export class ContentRule {
id = 'content';
description;
patterns;
constructor(patterns = ContentRule.getDefaultPatterns()) {
this.patterns = patterns;
const descriptions = patterns.map(p => p.description).join(', ');
this.description = `File must contain required content: ${descriptions}`;
}
static getDefaultPatterns() {
return [
{ pattern: 'npm', description: 'npm commands' },
{ pattern: 'TypeScript', description: 'TypeScript usage' },
{ pattern: 'test', description: 'testing information' },
{ pattern: 'build', description: 'build process' },
];
}
lint(file) {
const violations = [];
for (const contentPattern of this.patterns) {
if (!this.hasPattern(file, contentPattern)) {
violations.push(new Violation(this.id, `Missing required content: ${contentPattern.description} (expected: "${contentPattern.pattern}")`, Severity.WARNING, new Location(1, 1)));
}
}
return violations;
}
hasPattern(file, contentPattern) {
const content = file.content;
if (contentPattern.isRegex) {
const regex = new RegExp(contentPattern.pattern, 'i');
return regex.test(content);
}
else {
return content
.toLowerCase()
.includes(contentPattern.pattern.toLowerCase());
}
}
}
//# sourceMappingURL=ContentRule.js.map