fix(jsx-no-undef): honor /* global */ comments for runtime-injected identifiers#960
Closed
skoshx wants to merge 3 commits into
Closed
fix(jsx-no-undef): honor /* global */ comments for runtime-injected identifiers#960skoshx wants to merge 3 commits into
skoshx wants to merge 3 commits into
Conversation
…dentifiers Co-authored-by: Skosh <skoshx@users.noreply.github.com>
Co-authored-by: Skosh <skoshx@users.noreply.github.com>
commit: |
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.
Summary
Fixes #959 —
jsx-no-undeffalse positives for JSX identifiers provided via runtime-injected scope (e.g., react-live<LiveProvider scope={...}>, Storybook globals, or MDX live code blocks).Root Cause
The rule flags identifiers that don't have a local binding or import, even when they're legitimately provided at runtime by:
<LiveProvider scope={...}>injecting components into playground snippets.d.tsfiles (e.g.,declare global { const X: any; })The AST-only rule can't see cross-file type declarations or runtime scope injection, so every unimported identifier is flagged.
Solution
The rule now honors ESLint-style
/* global X, Y, Z */or// global Xcomments, providing an opt-in escape hatch for files that use injected globals.Why This Approach?
react/jsx-no-undefand many other linters use the same comment syntaxExample
Before (112 false positives in react-datepicker):
After (no errors):
Scope
The fix is narrowly scoped:
/* global */comments (opt-in)Testing
RDE Parity
Per the triage playbook,
rde parityshould be run during review to validate no regressions across the OSS corpus. The fix is narrowly scoped (opt-in via comments only) and expected to have zero impact on repos without/* global */comments.Changeset
Included a patch-level changeset for
oxlint-plugin-react-doctor.Closes #959