UNPKG

@felixgeelhaar/cclint

Version:

Catch CLAUDE.md drift before Claude misbehaves. Lints CLAUDE.md, skills, subagents, and hooks for Claude Code projects.

67 lines 2.73 kB
import { formatResult } from './textFormatter.js'; import { formatSarifResults } from './sarifFormatter.js'; /** * Format the results of linting a whole directory of config files. * * @remarks * Mirrors the single-file {@link formatResult} contract for `--format`: * - `text` — a per-file section (reusing the single-file text renderer) * followed by an aggregate summary line. * - `json` — `{ results: [...per file...], summary: {...totals...} }`. * - `sarif` — one SARIF run carrying every file's results (SARIF supports * multiple artifacts natively). */ export function formatDirectoryResult(results, format = 'text', options = {}) { if (format === 'json') { return formatJson(results); } if (format === 'sarif') { return formatSarifResults(results); } return formatText(results, options); } /** Sum error/warning/info counts across all files. */ export function summarize(results) { return results.reduce((acc, result) => ({ files: acc.files + 1, errors: acc.errors + result.getErrorCount(), warnings: acc.warnings + result.getWarningCount(), infos: acc.infos + result.getInfoCount(), }), { files: 0, errors: 0, warnings: 0, infos: 0 }); } function formatText(results, options) { const sections = results.map(result => formatResult(result, 'text', options)); const summary = summarize(results); const parts = []; const errorText = `${summary.errors} error${summary.errors === 1 ? '' : 's'}`; const warningText = `${summary.warnings} warning${summary.warnings === 1 ? '' : 's'}`; const infoText = `${summary.infos} info`; parts.push(errorText, warningText, infoText); const fileText = `${summary.files} file${summary.files === 1 ? '' : 's'}`; const aggregate = `Checked ${fileText}: ${parts.join(', ')}`; return [...sections, '', aggregate].join('\n'); } function formatJson(results) { const payload = { results: results.map(result => ({ file: result.file.path, violations: result.violations.map(violation => ({ ruleId: violation.ruleId, message: violation.message, severity: violation.severity.name, location: { line: violation.location.line, column: violation.location.column, }, })), summary: { errors: result.getErrorCount(), warnings: result.getWarningCount(), infos: result.getInfoCount(), }, })), summary: summarize(results), }; return JSON.stringify(payload, null, 2); } //# sourceMappingURL=directoryFormatter.js.map