-
-
Notifications
You must be signed in to change notification settings - Fork 724
feat: add react library aliases #7488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add react library aliases #7488
Conversation
🦋 Changeset detectedLatest commit: 5e177a6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughReactLibrary::import_names for Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
crates/biome_js_analyze/src/react.rs (2)
136-141
: Naming consistency: drop the get_ prefix.Other accessors are
import_names()
/global_name()
. Preferimport_aliases()
for symmetry and update the call site.Apply:
- pub const fn get_import_aliases(self) -> &'static [&'static str] { + pub const fn import_aliases(self) -> &'static [&'static str] { match self { Self::React => &["@rbxts/react"], Self::ReactDOM => &[], } }And:
- lib.import_names().contains(&source_text) - || lib.get_import_aliases().contains(&source_text) + lib.import_names().contains(&source_text) + || lib.import_aliases().contains(&source_text)Also applies to: 334-338
271-277
: Consider applying aliases across all import checks, not just “global” detection.Right now
is_react_export
/is_named_react_export
only considerimport_names()
. If a project uses@rbxts/react
, cases likeReact.createElement
or named React exports may still be missed.Optional patch to use aliases too:
fn is_react_export(binding: &Binding, lib: ReactLibrary) -> bool { binding .syntax() .ancestors() .find_map(|ancestor| JsImport::cast(ancestor)?.source_text().ok()) - .is_some_and(|source| lib.import_names().contains(&source.text())) + .is_some_and(|source| { + let t = source.text(); + lib.import_names().contains(&t) || lib.import_aliases().contains(&t) + }) } fn is_named_react_export(binding: &Binding, lib: ReactLibrary, name: &str) -> Option<bool> { … import .source_text() .ok() - .map(|import_name| lib.import_names().contains(&import_name.text())) + .map(|import_name| { + let t = import_name.text(); + lib.import_names().contains(&t) || lib.import_aliases().contains(&t) + }) }Sanity-check request:
- Do
@rbxts/react
users rely onReact.createElement
/named exports? If yes, the above avoids surprising gaps.- I can add focused tests for:
import React from "@rbxts/react"
import * as React from "@rbxts/react"
import { Fragment as F } from "@rbxts/react"
(if supported)Also applies to: 279-301
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/biome_js_analyze/src/react.rs
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
crates/biome_*_{syntax,parser,formatter,analyze,factory,semantic}/**
📄 CodeRabbit inference engine (CLAUDE.md)
Maintain the per-language crate structure: biome_{lang}_{syntax,parser,formatter,analyze,factory,semantic}
Files:
crates/biome_js_analyze/src/react.rs
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_js_analyze/src/react.rs
**/*.rs
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Format all Rust source files before committing (just f)
Files:
crates/biome_js_analyze/src/react.rs
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/react.rs (1)
crates/biome_js_syntax/src/import_ext.rs (1)
source_text
(29-31)
🔇 Additional comments (1)
crates/biome_js_analyze/src/react.rs (1)
334-338
: Alias check in is_global_react_import is spot on.Including "@rbxts/react" here will correctly recognise default/namespace imports of React under the classic runtime. Nice and tidy.
CodSpeed Performance ReportMerging #7488 will not alter performanceComparing Summary
|
Since this is a minor, hence a new feature, this PR must be merged into I won't block the PR, but please make sure we do that |
Summary
This updates the
is_global_react_import
function to include aliases for React. This is useful in cases where you are using thereactClassic
jsxRuntime, but won't actually be importing from React, but a React-like library. The most prevalent (and only example I personally know of) would be the "@rbxts/react" package, which is used by hundreds of developers in the roblox-ts community.See #7487.
Test Plan
My pull request merely adds a hardcoded reference to "@rbxts/react". I do not foresee a significant amount of users otherwise ever having to modify this behavior to point to a separate package, so I believe what we have now will suffice.