Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default defineCommand({
const allFindings: (HyperframeLintFinding & { file: string })[] = [];
let totalErrors = 0;
let totalWarnings = 0;
let totalInfos = 0;

for (const file of htmlFiles) {
const html = readFileSync(join(project.dir, file), "utf-8");
Expand All @@ -31,6 +32,7 @@ export default defineCommand({
}
totalErrors += result.errorCount;
totalWarnings += result.warningCount;
totalInfos += result.infoCount;
}

if (args.json) {
Expand All @@ -41,6 +43,7 @@ export default defineCommand({
findings: allFindings,
errorCount: totalErrors,
warningCount: totalWarnings,
infoCount: totalInfos,
filesScanned: htmlFiles.length,
}),
null,
Expand All @@ -61,7 +64,12 @@ export default defineCommand({
}

for (const finding of allFindings) {
const prefix = finding.severity === "error" ? c.error("✗") : c.warn("⚠");
const prefix =
finding.severity === "error"
? c.error("✗")
: finding.severity === "warning"
? c.warn("⚠")
: c.dim("ℹ");
const loc = finding.elementId ? ` ${c.accent(`[${finding.elementId}]`)}` : "";
console.log(
`${prefix} ${c.bold(finding.code)}${loc}: ${finding.message} ${c.dim(finding.file)}`,
Expand All @@ -72,7 +80,11 @@ export default defineCommand({
}

const summaryIcon = totalErrors > 0 ? c.error("◇") : c.success("◇");
console.log(`\n${summaryIcon} ${totalErrors} error(s), ${totalWarnings} warning(s)`);
const summaryParts = [`${totalErrors} error(s)`, `${totalWarnings} warning(s)`];
if (totalInfos > 0) {
summaryParts.push(`${totalInfos} info(s)`);
}
console.log(`\n${summaryIcon} ${summaryParts.join(", ")}`);
process.exit(totalErrors > 0 ? 1 : 0);
} catch (err: unknown) {
const message = err instanceof Error ? err.message : String(err);
Expand All @@ -85,6 +97,7 @@ export default defineCommand({
findings: [],
errorCount: 0,
warningCount: 0,
infoCount: 0,
filesScanned: 0,
}),
null,
Expand Down
15 changes: 12 additions & 3 deletions packages/core/scripts/check-hyperframe-static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ import path from "node:path";
import { lintHyperframeHtml } from "../src/lint/hyperframeLinter";
import type { HyperframeLintResult } from "../src/lint/types";

function formatCounts(result: HyperframeLintResult): string {
const parts = [`${result.warningCount} warning${result.warningCount === 1 ? "" : "s"}`];
if (result.infoCount > 0) {
parts.push(`${result.infoCount} info${result.infoCount === 1 ? "" : "s"}`);
}
return parts.join(", ");
}

function formatHumanOutput(result: HyperframeLintResult, resolvedPath: string): string {
const counts = result.ok
? formatCounts(result)
: `${result.errorCount} error${result.errorCount === 1 ? "" : "s"}, ${formatCounts(result)}`;
const lines = [
result.ok
? `PASS ${resolvedPath} (${result.warningCount} warning${result.warningCount === 1 ? "" : "s"})`
: `FAIL ${resolvedPath} (${result.errorCount} error${result.errorCount === 1 ? "" : "s"}, ${result.warningCount} warning${result.warningCount === 1 ? "" : "s"})`,
result.ok ? `PASS ${resolvedPath} (${counts})` : `FAIL ${resolvedPath} (${counts})`,
];

for (const finding of result.findings) {
Expand Down
Loading