Skip to content

TypeError: Cannot read properties of undefined (reading 'match') in parseRuleCode when oxlint diagnostic has no code field #1635

Description

@shamscorner

Description

Running npx react-doctor@latest . crashes with:

Lint did not run: Failed to run oxlint: TypeError: Cannot read properties of undefined (reading 'match')
at parseRuleCode (file:///.../node_modules/react-doctor/dist/record-metric-CJxSHfJD.js:75822:21)
at file:///.../node_modules/react-doctor/dist/record-metric-CJxSHfJD.js:75926:28
at Array.flatMap ()
at parseOxlintOutput (file:///.../node_modules/react-doctor/dist/record-metric-CJxSHfJD.js:75923:68)
at spawnLintBatch (file:///.../node_modules/react-doctor/dist/record-metric-CJxSHfJD.js:76206:12)

Root Cause

The error occurs at parseRuleCode in the bundled oxlint output parser:

const parseRuleCode = (code) => {
    const match = code.match(/^(.+)\((.+)\)$/);  // ← crashes when code is undefined
    if (!match) return { plugin: "unknown", rule: code };
    return { plugin: match[1].replace(/^eslint-plugin-/, ""), rule: match[2] };
};

Some oxlint diagnostics don't include a code field, so diagnostic.code is undefined. When parseRuleCode(undefined) is called, .match() throws.

Fix

Add a null check before calling .match():

const parseRuleCode = (code) => {
    if (!code) return { plugin: "unknown", rule: "unknown" };
    const match = code.match(/^(.+)\((.+)\)$/);
    // ...
};

Environment

  • react-doctor: 0.9.11
  • Node.js: v24.15.0
  • OS: macOS (Darwin)
  • Project: Astro SSR + React islands (TypeScript 6.0.3)
  • Command: npx react-doctor@latest . --verbose --diff

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions