Skip to content

Commit 42d3024

Browse files
committed
feat(cli): add support for message diagnostics
1 parent 5fbdc80 commit 42d3024

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

packages/cli/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const darkGray = (s: string) => '\x1b[90m' + s + _reset;
1717
const lightRed = (s: string) => '\x1b[91m' + s + _reset;
1818
const lightGreen = (s: string) => '\x1b[92m' + s + _reset;
1919
const lightYellow = (s: string) => '\x1b[93m' + s + _reset;
20+
const lightBlue = (s: string) => '\x1b[94m' + s + _reset;
2021

2122
// https://talyian.github.io/ansicolors/
2223
const tsColor = (s: string) => '\x1b[34m' + s + _reset;
@@ -124,6 +125,7 @@ class Project {
124125
let passed = 0;
125126
let errors = 0;
126127
let warnings = 0;
128+
let messages = 0;
127129
let cached = 0;
128130

129131
if (isTTY) {
@@ -350,8 +352,10 @@ class Project {
350352
[passed, 'passed', lightGreen] as const,
351353
[errors, 'errors', lightRed] as const,
352354
[warnings, 'warnings', lightYellow] as const,
355+
[messages, 'messages', lightBlue] as const,
353356
[excluded, 'excluded', darkGray] as const,
354357
];
358+
const hasFailed = !!(errors || warnings || messages);
355359

356360
let summary = data
357361
.filter(([count]) => count)
@@ -360,12 +364,12 @@ class Project {
360364

361365
if (hasFix) {
362366
summary += darkGray(` (Use `) + cyan(`--fix`) + darkGray(` to apply automatic fixes.)`);
363-
} else if (errors || warnings) {
367+
} else if (hasFailed) {
364368
summary += darkGray(` (No fixes available.)`);
365369
}
366370

367371
clack.outro(summary);
368-
process.exit(errors ? 1 : 0);
372+
process.exit(hasFailed ? 1 : 0);
369373

370374
async function startWorker(linterWorker: ReturnType<typeof worker.create>) {
371375
const unfinishedProjects = projects.filter(project => project.currentFileIndex < project.fileNames.length);
@@ -452,6 +456,10 @@ class Project {
452456
warnings++;
453457
log(output, 2);
454458
}
459+
else if (diagnostic.category === ts.DiagnosticCategory.Message) {
460+
messages++;
461+
log(output);
462+
}
455463
else {
456464
log(output);
457465
}
@@ -524,6 +532,8 @@ class Project {
524532
clack.log.error(msg);
525533
} else if (code === 2) {
526534
clack.log.warn(msg);
535+
} else if (code === 3) {
536+
clack.log.message(msg);
527537
} else {
528538
clack.log.step(msg);
529539
}

0 commit comments

Comments
 (0)