Appearance
Formatters
@lapidist/design-lint
uses formatter functions to turn lint results into human- or machine-readable output. A formatter receives an array of LintResult
objects and an optional useColor
flag and returns a string to print.
Built-in formatters
stylish
– default, colorized summary intended for terminals.json
– raw JSON results, useful for piping to other tools.sarif
– emits a SARIF 2.1.0 log for CI systems.
Select a formatter with the --format
CLI option or the getFormatter(name)
API.
Creating a custom formatter
You can supply your own formatter module without modifying @lapidist/design-lint
.
Create the formatter module:
ts// minimal-formatter.ts import type { LintResult } from '@lapidist/design-lint'; export default function minimal(results: LintResult[]): string { return results.map((r) => `${r.filePath}: ${r.messages.length}`).join('\n'); }
Use the formatter from the CLI:
bashnpx design-lint src --format ./minimal-formatter.ts
Or from the API:
tsimport { getFormatter } from '@lapidist/design-lint'; const formatter = await getFormatter('./minimal-formatter.ts'); console.log(formatter(results));
Formatters receive a useColor
boolean as the second argument. Respect this flag if your formatter supports colored output. For inspiration, see the built-in formatter implementations in src/formatters
.