Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@arendjr
Copy link
Contributor

@arendjr arendjr commented Aug 19, 2025

Summary

After a previous fix, I left two ways of handling rest parameters in the code. This deduplicates them.

Test Plan

Everything should stay green.

@changeset-bot
Copy link

changeset-bot bot commented Aug 19, 2025

⚠️ No Changeset found

Latest commit: f913a39

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 19, 2025

Walkthrough

Function-parameter handling in crates/biome_js_type_info/src/local_inference.rs was refactored. JsRestParameter handling in FunctionParameter::from_any_js_parameter now delegates to Self::from_js_rest_parameter. A new private helper from_binding_with_annotation(resolver, scope_id, binding, annotation, is_optional, is_rest) centralises extraction of an optional name from AnyJsBinding/AnyJsBindingPattern, derives TypeData from TS annotations, and constructs either NamedFunctionParameter or PatternFunctionParameter with the appropriate is_optional and is_rest flags. from_js_formal_parameter and from_js_rest_parameter both route through this helper. Public API signatures are unchanged.

Suggested labels

A-Project

✨ Finishing Touches
  • πŸ“ Generate Docstrings
πŸ§ͺ Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added L-JavaScript Language: JavaScript and super languages A-Type-Inference Area: type inference labels Aug 19, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (1)
crates/biome_js_type_info/src/local_inference.rs (1)

1481-1483: Optional: unify the remaining formal/rest parameter duplication

from_js_formal_parameter and from_js_rest_parameter still share almost identical name/type extraction and pattern-binding code. Consider a small internal helper (e.g., from_js_param_common(..., is_optional, is_rest)) to DRY this up further. Not blocking; just a follow-up nicety.

πŸ“œ Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

πŸ’‘ Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 8a8e2e6 and 3e66712.

πŸ“’ Files selected for processing (1)
  • crates/biome_js_type_info/src/local_inference.rs (1 hunks)
🧰 Additional context used
πŸ““ Path-based instructions (6)
**/*.{rs,toml}

πŸ“„ CodeRabbit Inference Engine (CONTRIBUTING.md)

Format Rust and TOML files before committing (use just f/just format).

Files:

  • crates/biome_js_type_info/src/local_inference.rs
crates/biome_js_type_info/src/**/*.rs

πŸ“„ CodeRabbit Inference Engine (crates/biome_js_type_info/CONTRIBUTING.md)

crates/biome_js_type_info/src/**/*.rs: Represent links between types using TypeReference (not Arc) to avoid cross-module retention and recursive structures; store type data in linear vectors
Use TypeData::Unknown for unimplemented inference and TypeData::UnknownKeyword for the explicit TypeScript unknown keyword; treat them semantically the same but keep them distinct for measurement

Files:

  • crates/biome_js_type_info/src/local_inference.rs
crates/biome_js_type_info/src/local_inference.rs

πŸ“„ CodeRabbit Inference Engine (crates/biome_js_type_info/CONTRIBUTING.md)

Local inference must not perform type resolution; it should only create TypeReference::Qualifier entries from syntax

Files:

  • crates/biome_js_type_info/src/local_inference.rs
crates/biome_js_type_info/{src,resolver,biome_module_graph/src}/**/*.rs

πŸ“„ CodeRabbit Inference Engine (crates/biome_js_type_info/CONTRIBUTING.md)

Implement and use type resolution via the TypeResolver trait; resolvers own TypeStore vectors and provide fast by-id and hashed lookups

Files:

  • crates/biome_js_type_info/src/local_inference.rs
crates/biome_js_type_info/{src,biome_module_graph/src}/**/*.rs

πŸ“„ CodeRabbit Inference Engine (crates/biome_js_type_info/CONTRIBUTING.md)

When pattern-matching on ResolvedTypeData via as_raw_data(), ensure any nested TypeReferences are subsequently resolved using the correct ResolverId; never use the raw data with a resolver without applying the right ResolverId to avoid panics

Files:

  • crates/biome_js_type_info/src/local_inference.rs
crates/biome_*/**

πŸ“„ CodeRabbit Inference Engine (CLAUDE.md)

Place core crates under /crates/biome_*/

Files:

  • crates/biome_js_type_info/src/local_inference.rs
🧠 Learnings (5)
πŸ““ Common learnings
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/{src,biome_module_graph/src}/**/*.rs : When pattern-matching on ResolvedTypeData via as_raw_data(), ensure any nested TypeReferences are subsequently resolved using the correct ResolverId; never use the raw data with a resolver without applying the right ResolverId to avoid panics
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/src/local_inference.rs : Local inference must not perform type resolution; it should only create TypeReference::Qualifier entries from syntax
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/{src,resolver,biome_module_graph/src}/**/*.rs : Implement and use type resolution via the TypeResolver trait; resolvers own TypeStore vectors and provide fast by-id and hashed lookups
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/js_module_info/scoped_resolver.rs : Full inference resolves TypeReference::Import across modules into TypeReference::Resolved using the module graph; do not cache full-inference results
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/js_module_info/collector.rs : Thin (module-level) inference may resolve qualifiers to local declarations or globals (TypeReference::Resolved), mark imported bindings as TypeReference::Import, and set unresolved to TypeReference::Unknown; it must not look beyond the current module
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/src/**/*.rs : Represent links between types using TypeReference (not Arc) to avoid cross-module retention and recursive structures; store type data in linear vectors
πŸ“š Learning: 2025-08-11T11:50:12.090Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/src/local_inference.rs : Local inference must not perform type resolution; it should only create TypeReference::Qualifier entries from syntax

Applied to files:

  • crates/biome_js_type_info/src/local_inference.rs
πŸ“š Learning: 2025-08-11T11:50:12.090Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/{src,biome_module_graph/src}/**/*.rs : When pattern-matching on ResolvedTypeData via as_raw_data(), ensure any nested TypeReferences are subsequently resolved using the correct ResolverId; never use the raw data with a resolver without applying the right ResolverId to avoid panics

Applied to files:

  • crates/biome_js_type_info/src/local_inference.rs
πŸ“š Learning: 2025-08-11T11:50:12.090Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/js_module_info/scoped_resolver.rs : Full inference resolves TypeReference::Import across modules into TypeReference::Resolved using the module graph; do not cache full-inference results

Applied to files:

  • crates/biome_js_type_info/src/local_inference.rs
πŸ“š Learning: 2025-08-11T11:50:12.090Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/src/**/*.rs : Use TypeData::Unknown for unimplemented inference and TypeData::UnknownKeyword for the explicit TypeScript unknown keyword; treat them semantically the same but keep them distinct for measurement

Applied to files:

  • crates/biome_js_type_info/src/local_inference.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Test Node.js API
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Documentation
  • GitHub Check: End-to-end tests
  • GitHub Check: autofix
πŸ”‡ Additional comments (1)
crates/biome_js_type_info/src/local_inference.rs (1)

1481-1483: Centralising rest-parameter handling β€” nice tidy-up

Routing JsRestParameter through from_js_rest_parameter removes the duplicate branch and keeps the semantics (is_rest, typing, destructuring) in one place. Exactly the kind of de-dup we like to see.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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_type_info/src/local_inference.rs (2)

1535-1542: Nit: prefer existing helper for token-to-text for consistency

Minor style tweak: use text_from_token directly to align with the rest of the file and avoid manual trimming.

Apply:

-        let name = binding
-            .as_ref()
-            .ok()
-            .and_then(AnyJsBindingPattern::as_any_js_binding)
-            .and_then(AnyJsBinding::as_js_identifier_binding)
-            .and_then(|identifier| identifier.name_token().ok())
-            .map(|token| token.token_text_trimmed().into());
+        let name = binding
+            .as_ref()
+            .ok()
+            .and_then(AnyJsBindingPattern::as_any_js_binding)
+            .and_then(AnyJsBinding::as_js_identifier_binding)
+            .and_then(|identifier| text_from_token(identifier.name_token()));

1517-1525: Confirm default rest-parameter type semantics
Currently, from_binding_with_annotation falls back to Default::default() (i.e. unknown) even when is_rest == true, so an unannotated rest param becomes unknown not unknown[]. That’s a behavioural change from treating rest params as arrays. Please:

β€’ Verify TS expectations for unannotated rest params (should be an array)
β€’ If you agree, adjust the fallback in crates/biome_js_type_info/src/local_inference.rs around from_binding_with_annotation to default is_rest cases to TypeData::array_of(scope_id, TypeReference::unknown())

Example optional patch:

 let ty = match (is_rest, annotation.and_then(|a| a.ty().ok())) {
     (true, None)   => TypeData::array_of(scope_id, TypeReference::unknown()),
     (_,    Some(t))=> TypeData::from_any_ts_type(resolver, scope_id, &t),
     _              => TypeData::unknown(),
 };
πŸ“œ Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

πŸ’‘ Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 8744530 and f913a39.

πŸ“’ Files selected for processing (1)
  • crates/biome_js_type_info/src/local_inference.rs (4 hunks)
🧰 Additional context used
πŸ““ Path-based instructions (6)
**/*.{rs,toml}

πŸ“„ CodeRabbit Inference Engine (CONTRIBUTING.md)

Format Rust and TOML files before committing (use just f/just format).

Files:

  • crates/biome_js_type_info/src/local_inference.rs
crates/biome_js_type_info/src/**/*.rs

πŸ“„ CodeRabbit Inference Engine (crates/biome_js_type_info/CONTRIBUTING.md)

crates/biome_js_type_info/src/**/*.rs: Represent links between types using TypeReference (not Arc) to avoid cross-module retention and recursive structures; store type data in linear vectors
Use TypeData::Unknown for unimplemented inference and TypeData::UnknownKeyword for the explicit TypeScript unknown keyword; treat them semantically the same but keep them distinct for measurement

Files:

  • crates/biome_js_type_info/src/local_inference.rs
crates/biome_js_type_info/src/local_inference.rs

πŸ“„ CodeRabbit Inference Engine (crates/biome_js_type_info/CONTRIBUTING.md)

Local inference must not perform type resolution; it should only create TypeReference::Qualifier entries from syntax

Files:

  • crates/biome_js_type_info/src/local_inference.rs
crates/biome_js_type_info/{src,resolver,biome_module_graph/src}/**/*.rs

πŸ“„ CodeRabbit Inference Engine (crates/biome_js_type_info/CONTRIBUTING.md)

Implement and use type resolution via the TypeResolver trait; resolvers own TypeStore vectors and provide fast by-id and hashed lookups

Files:

  • crates/biome_js_type_info/src/local_inference.rs
crates/biome_js_type_info/{src,biome_module_graph/src}/**/*.rs

πŸ“„ CodeRabbit Inference Engine (crates/biome_js_type_info/CONTRIBUTING.md)

When pattern-matching on ResolvedTypeData via as_raw_data(), ensure any nested TypeReferences are subsequently resolved using the correct ResolverId; never use the raw data with a resolver without applying the right ResolverId to avoid panics

Files:

  • crates/biome_js_type_info/src/local_inference.rs
crates/biome_*/**

πŸ“„ CodeRabbit Inference Engine (CLAUDE.md)

Place core crates under /crates/biome_*/

Files:

  • crates/biome_js_type_info/src/local_inference.rs
🧠 Learnings (6)
πŸ““ Common learnings
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/src/**/*.rs : Use TypeData::Unknown for unimplemented inference and TypeData::UnknownKeyword for the explicit TypeScript unknown keyword; treat them semantically the same but keep them distinct for measurement
πŸ“š Learning: 2025-08-11T11:50:12.090Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/src/**/*.rs : Use TypeData::Unknown for unimplemented inference and TypeData::UnknownKeyword for the explicit TypeScript unknown keyword; treat them semantically the same but keep them distinct for measurement

Applied to files:

  • crates/biome_js_type_info/src/local_inference.rs
πŸ“š Learning: 2025-08-11T11:50:12.090Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/js_module_info/collector.rs : Thin (module-level) inference may resolve qualifiers to local declarations or globals (TypeReference::Resolved), mark imported bindings as TypeReference::Import, and set unresolved to TypeReference::Unknown; it must not look beyond the current module

Applied to files:

  • crates/biome_js_type_info/src/local_inference.rs
πŸ“š Learning: 2025-08-11T11:50:12.090Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/src/local_inference.rs : Local inference must not perform type resolution; it should only create TypeReference::Qualifier entries from syntax

Applied to files:

  • crates/biome_js_type_info/src/local_inference.rs
πŸ“š Learning: 2025-08-11T11:50:12.090Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/biome_module_graph/src/js_module_info/scoped_resolver.rs : Full inference resolves TypeReference::Import across modules into TypeReference::Resolved using the module graph; do not cache full-inference results

Applied to files:

  • crates/biome_js_type_info/src/local_inference.rs
πŸ“š Learning: 2025-08-11T11:50:12.090Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:50:12.090Z
Learning: Applies to crates/biome_js_type_info/src/**/*.rs : Represent links between types using TypeReference (not Arc) to avoid cross-module retention and recursive structures; store type data in linear vectors

Applied to files:

  • crates/biome_js_type_info/src/local_inference.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: End-to-end tests
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
πŸ”‡ Additional comments (4)
crates/biome_js_type_info/src/local_inference.rs (4)

5-5: Import of AnyJsBinding is correct and necessary

Used by the new helper for identifier extraction; tidy and to the point.


1482-1482: Good call: delegate JsRestParameter handling

Routing via from_js_rest_parameter removes duplication and keeps from_any_js_parameter lean.


1502-1510: Nice de-dupe: centralise formal parameter handling

Switching to from_binding_with_annotation(.., is_optional, /*is_rest=*/ false) keeps semantics and removes repeated code.


1527-1569: Helper reads well and keeps local inference constraints

Centralising binding-name extraction and TS annotation handling is a solid improvement. It keeps to local-inference rules (no resolution; Unknown vs UnknownKeyword preserved via from_any_ts_type).

@arendjr arendjr merged commit ee21e95 into biomejs:main Aug 19, 2025
12 checks passed
ematipico pushed a commit that referenced this pull request Aug 26, 2025
SkyBird233 pushed a commit to SkyBird233/biomejs that referenced this pull request Aug 28, 2025
SkyBird233 pushed a commit to SkyBird233/biomejs that referenced this pull request Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Type-Inference Area: type inference L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant