Skip to content

Commit 14e24a8

Browse files
authored
oxlint json parse failure fallback (#37)
* oxlint json parse failure fallback * changeset
1 parent b0e4a9f commit 14e24a8

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

.changeset/fresh-suits-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bomb.sh/tools": patch
3+
---
4+
5+
In some failure or no-op cases, oxlint seems to return output which is not json-parseable even with --json passed. Log output directly in these instances.

src/commands/lint.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,31 @@ export async function runOxlint(targets: string[], fix?: boolean): Promise<Viola
2525
const args = ['-c', oxlintConfig, '--format=json', ...targets];
2626
if (fix) args.push('--fix');
2727
const result = await x(local('oxlint'), args, { throwOnError: false });
28-
const json = JSON.parse(result.stdout);
29-
return (json.diagnostics ?? []).map(
30-
(d: {
31-
message: string;
32-
code: string;
33-
severity: string;
34-
filename?: string;
35-
labels?: Array<{ span?: { line?: number; column?: number } }>;
36-
}) => ({
37-
tool: 'oxlint' as const,
38-
level: d.severity === 'error' ? 'error' : 'warning',
39-
code: d.code ?? 'unknown',
40-
message: d.message,
41-
file: d.filename,
42-
line: d.labels?.[0]?.span?.line,
43-
column: d.labels?.[0]?.span?.column,
44-
}),
45-
);
28+
try {
29+
const json = JSON.parse(result.stdout);
30+
return (json.diagnostics ?? []).map(
31+
(d: {
32+
message: string;
33+
code: string;
34+
severity: string;
35+
filename?: string;
36+
labels?: Array<{ span?: { line?: number; column?: number } }>;
37+
}) => ({
38+
tool: 'oxlint' as const,
39+
level: d.severity === 'error' ? 'error' : 'warning',
40+
code: d.code ?? 'unknown',
41+
message: d.message,
42+
file: d.filename,
43+
line: d.labels?.[0]?.span?.line,
44+
column: d.labels?.[0]?.span?.column,
45+
}),
46+
);
47+
} catch {
48+
// in some cases, failures or no-ops do not produce valid JSON
49+
// fallback to raw output rather than throwing an error
50+
console.log(result.stdout);
51+
return [];
52+
}
4653
}
4754

4855
export async function runKnip(): Promise<Violation[]> {

0 commit comments

Comments
 (0)