Formatters
Formatters shape the output produced by design-lint. This page targets developers choosing report styles or authoring custom formatters.
Table of contents
Built-in formatters
| Name | Description |
|---|---|
stylish | Human-friendly terminal output with colours and a summary. |
json | Machine-readable output for scripts or dashboards. |
sarif | Emits SARIF 2.1.0 for services like GitHub code scanning. |
Selecting a formatter
Choose a formatter via the CLI or configuration file. CLI --format takes precedence when both are set.
npx design-lint src --format json{
"format": "json"
}Tip: Combine the
jsonformatter with--outputto generate artifacts in CI.
Writing a custom formatter
A formatter exports a default function receiving lint results and returning a string.
Security: Custom formatter modules are executed as code in your Node.js process. Only load formatter modules from trusted sources.
// formatter.js
export default function formatter(results) {
return results.map((r) => r.sourceId).join('\n');
}Invoke it with a relative path:
npx design-lint src --format ./formatter.jsFor a reusable package, publish the formatter to npm and reference it by name. See the plugins guide for packaging tips and plugin/formatter loading differences.
Using formatters in CI
Formatters determine how results are captured by CI systems:
stylishprints directly to the log.jsoncan be parsed to annotate pull requests.sarifintegrates with GitHub code scanning.
Store the report as an artifact for later inspection or feed it into additional tooling.