Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .changeset/fix-missing-code-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-doctor/core": patch
---

Fix crash when oxlint diagnostic has no code field. Some diagnostics (like parse errors) omit the code field, causing parseRuleCode to throw "Cannot read properties of undefined (reading 'match')". parseRuleCode now returns { plugin: "unknown", rule: "unknown" } when code is missing.
3 changes: 2 additions & 1 deletion packages/core/src/runners/oxlint/parse-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ const resolveCleanedDiagnostic = (
};
};

const parseRuleCode = (code: string): { plugin: string; rule: string } => {
const parseRuleCode = (code: string | undefined): { plugin: string; rule: string } => {
if (!code) return { plugin: "unknown", rule: "unknown" };
const match = code.match(/^(.+)\((.+)\)$/);
if (!match) return { plugin: "unknown", rule: code };
return { plugin: match[1].replace(/^eslint-plugin-/, ""), rule: match[2] };
Expand Down
100 changes: 100 additions & 0 deletions packages/core/tests/oxlint-missing-code.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { describe, expect, it } from "vite-plus/test";
import { parseOxlintOutput } from "../src/runners/oxlint/parse-output.js";
import { buildProject } from "./helpers/oxlint-parse-harness.js";

describe("parseOxlintOutput with missing code field", () => {
it("handles diagnostics with no code field without crashing", () => {
const stdout = JSON.stringify({
diagnostics: [
{
message: "Parse error: unexpected token",
severity: "error",
causes: [],
url: "",
help: "",
filename: "src/components/widget.tsx",
labels: [{ label: "", span: { offset: 0, length: 1, line: 12, column: 3 } }],
related: [],
},
],
number_of_files: 1,
number_of_rules: 1,
});

expect(() => {
parseOxlintOutput(stdout, buildProject(), "/home/user/app");
}).not.toThrow();
});

it("handles diagnostics with undefined code field", () => {
const stdout = JSON.stringify({
diagnostics: [
{
message: "Parse error",
code: undefined,
severity: "error",
causes: [],
url: "",
help: "",
filename: "src/components/widget.tsx",
labels: [{ label: "", span: { offset: 0, length: 1, line: 12, column: 3 } }],
related: [],
},
],
number_of_files: 1,
number_of_rules: 1,
});

expect(() => {
parseOxlintOutput(stdout, buildProject(), "/home/user/app");
}).not.toThrow();
});

it("handles diagnostics with null code field", () => {
const stdout = JSON.stringify({
diagnostics: [
{
message: "Parse error",
code: null,
severity: "error",
causes: [],
url: "",
help: "",
filename: "src/components/widget.tsx",
labels: [{ label: "", span: { offset: 0, length: 1, line: 12, column: 3 } }],
related: [],
},
],
number_of_files: 1,
number_of_rules: 1,
});

expect(() => {
parseOxlintOutput(stdout, buildProject(), "/home/user/app");
}).not.toThrow();
});

it("handles diagnostics with empty string code field", () => {
const stdout = JSON.stringify({
diagnostics: [
{
message: "Parse error",
code: "",
severity: "error",
causes: [],
url: "",
help: "",
filename: "src/components/widget.tsx",
labels: [{ label: "", span: { offset: 0, length: 1, line: 12, column: 3 } }],
related: [],
},
],
number_of_files: 1,
number_of_rules: 1,
});

expect(() => {
parseOxlintOutput(stdout, buildProject(), "/home/user/app");
}).not.toThrow();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* exports — older plugin versions can lack newer compiler rules,
* so React Compiler users would otherwise hit
* "Rule 'void-use-memo' not found in plugin 'react-hooks-js'".
* #1635 — parseRuleCode must handle diagnostics with no code field —
* some oxlint diagnostics (like parse errors) omit the code field,
* causing "Cannot read properties of undefined (reading 'match')".
*/

import { spawnSync } from "node:child_process";
Expand Down
Loading