fix: handle undefined code field in oxlint diagnostics - #1637
Draft
skoshx wants to merge 3 commits into
Draft
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
The error occurs in
parseRuleCodewhen processing oxlint diagnostics that don't include acodefield. Some oxlint diagnostics (like parse errors) omit this field, causingcode.match()to throwTypeError: Cannot read properties of undefined (reading 'match').The bug can trigger in two code paths:
isMappableOxlintDiagnosticwhich requires a string code)Fix
Added a defensive null check at the start of
parseRuleCode:This returns a safe fallback when
codeis 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: stringtocode: string | undefinedto reflect reality.Testing
packages/core/tests/oxlint-missing-code.test.tscovering all edge cases (undefined, null, empty, missing)packages/react-doctor/tests/regressions/scan-resilience.test.tsCloses #1635