Skip to content

Commit 7d10dac

Browse files
authored
fix: use diagnostic level to choose printing as error/info (#501)
1 parent 4a27c58 commit 7d10dac

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

packages/vite-plugin-checker/src/checkers/biome/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { FileDiagnosticManager } from '../../FileDiagnosticManager.js'
77
import {
88
composeCheckerSummary,
99
consoleLog,
10+
diagnosticToConsoleLevel,
1011
diagnosticToRuntimeError,
1112
diagnosticToTerminalLog,
1213
filterLogLevel,
@@ -58,7 +59,10 @@ const createDiagnostic: CreateDiagnostic<'biome'> = (pluginConfig) => {
5859

5960
if (terminal) {
6061
for (const d of diagnostics) {
61-
consoleLog(diagnosticToTerminalLog(d, 'Biome'), 'info')
62+
consoleLog(
63+
diagnosticToTerminalLog(d, 'Biome'),
64+
diagnosticToConsoleLevel(d),
65+
)
6266
}
6367

6468
const errorCount = diagnostics.filter(

packages/vite-plugin-checker/src/checkers/eslint/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { createIgnore } from '../../glob.js'
1212
import {
1313
composeCheckerSummary,
1414
consoleLog,
15+
diagnosticToConsoleLevel,
1516
diagnosticToRuntimeError,
1617
diagnosticToTerminalLog,
1718
filterLogLevel,
@@ -88,10 +89,12 @@ const createDiagnostic: CreateDiagnostic<'eslint'> = (pluginConfig) => {
8889

8990
const dispatchDiagnostics = () => {
9091
const diagnostics = filterLogLevel(manager.getDiagnostics(), logLevel)
91-
9292
if (terminal) {
9393
for (const d of diagnostics) {
94-
consoleLog(diagnosticToTerminalLog(d, 'ESLint'), 'info')
94+
consoleLog(
95+
diagnosticToTerminalLog(d, 'ESLint'),
96+
diagnosticToConsoleLevel(d),
97+
)
9598
}
9699

97100
const errorCount = diagnostics.filter(

packages/vite-plugin-checker/src/checkers/stylelint/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { createIgnore } from '../../glob.js'
1111
import {
1212
composeCheckerSummary,
1313
consoleLog,
14+
diagnosticToConsoleLevel,
1415
diagnosticToRuntimeError,
1516
diagnosticToTerminalLog,
1617
filterLogLevel,
@@ -63,7 +64,10 @@ const createDiagnostic: CreateDiagnostic<'stylelint'> = (pluginConfig) => {
6364

6465
if (terminal) {
6566
for (const d of diagnostics) {
66-
consoleLog(diagnosticToTerminalLog(d, 'Stylelint'), 'info')
67+
consoleLog(
68+
diagnosticToTerminalLog(d, 'Stylelint'),
69+
diagnosticToConsoleLevel(d),
70+
)
6771
}
6872

6973
const errorCount = diagnostics.filter(

packages/vite-plugin-checker/src/checkers/vls/main.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import os from 'node:os'
21
import { fileURLToPath } from 'node:url'
32
import { parentPort } from 'node:worker_threads'
43

54
import { Checker } from '../../Checker.js'
65
import {
76
composeCheckerSummary,
87
consoleLog,
8+
diagnosticToConsoleLevel,
99
diagnosticToRuntimeError,
1010
diagnosticToTerminalLog,
1111
toClientPayload,
@@ -57,12 +57,12 @@ export const createDiagnostic: CreateDiagnostic<'vls'> = (pluginConfig) => {
5757
}
5858

5959
if (terminal) {
60-
consoleLog(
61-
normalized
62-
.map((d) => diagnosticToTerminalLog(d, 'VLS'))
63-
.join(os.EOL),
64-
'info',
65-
)
60+
for (const d of normalized) {
61+
consoleLog(
62+
diagnosticToTerminalLog(d, 'VLS'),
63+
diagnosticToConsoleLevel(d),
64+
)
65+
}
6666
}
6767
}
6868

packages/vite-plugin-checker/src/logger.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ export function diagnosticToTerminalLog(
128128
.join(os.EOL)
129129
}
130130

131+
export function diagnosticToConsoleLevel(d: NormalizedDiagnostic) {
132+
if (!d) return 'error'
133+
if (d.level === DiagnosticLevel.Message) return 'info'
134+
if (d.level === DiagnosticLevel.Suggestion) return 'info'
135+
if (d.level === DiagnosticLevel.Warning) return 'warn'
136+
return 'error'
137+
}
138+
131139
export function diagnosticToRuntimeError(
132140
d: NormalizedDiagnostic,
133141
): DiagnosticToRuntime

0 commit comments

Comments
 (0)