Skip to content

fix: handle undefined code field in oxlint diagnostics - #1637

Draft
skoshx wants to merge 3 commits into
mainfrom
cursor/triage-1635-8108
Draft

fix: handle undefined code field in oxlint diagnostics#1637
skoshx wants to merge 3 commits into
mainfrom
cursor/triage-1635-8108

Conversation

@skoshx

@skoshx skoshx commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Root Cause

The error occurs in parseRuleCode when processing oxlint diagnostics that don't include a code field. Some oxlint diagnostics (like parse errors) omit this field, causing code.match() to throw TypeError: Cannot read properties of undefined (reading 'match').

The bug can trigger in two code paths:

  1. Line 441: When processing diagnostics with prepared source maps (e.g. Astro files)
  2. Line 469: When mapping filtered diagnostics (though this is protected by isMappableOxlintDiagnostic which requires a string code)

Fix

Added a defensive null check at the start of parseRuleCode:

if (!code) return { plugin: "unknown", rule: "unknown" };

This returns a safe fallback when code is undefined, null, or empty string.

Scope

The fix is narrowly scoped to handle the missing code field gracefully without changing any other behavior. Updated the type signature from code: string to code: string | undefined to reflect reality.

Testing

  • Added unit tests in packages/core/tests/oxlint-missing-code.test.ts covering all edge cases (undefined, null, empty, missing)
  • Added regression test documentation in packages/react-doctor/tests/regressions/scan-resilience.test.ts
  • All existing tests pass
  • Parity check in progress

Closes #1635

Open in Web Open in Cursor 

cursoragent and others added 3 commits August 12, 2026 08:18
Add defensive null check in parseRuleCode to prevent crash when
oxlint diagnostic has no code field. Some diagnostics (like parse
errors) may not include a code, causing 'Cannot read properties of
undefined (reading 'match')' crash.

Returns { plugin: 'unknown', rule: 'unknown' } when code is
undefined/null/empty.

Issue: #1635

Co-authored-by: Skosh <skoshx@users.noreply.github.com>
Add test coverage in scan-resilience documenting that parseRuleCode
handles diagnostics with missing code fields without crashing.

The fix is already in place in the previous commit.

Co-authored-by: Skosh <skoshx@users.noreply.github.com>
Co-authored-by: Skosh <skoshx@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants