chore: unduplicate branch#7274
Conversation
|
WalkthroughFunction-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
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
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 duplicationfrom_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.
📒 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-upRouting 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.
There was a problem hiding this comment.
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 consistencyMinor style tweak: use
text_from_tokendirectly 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_annotationfalls back toDefault::default()(i.e.unknown) even whenis_rest == true, so an unannotated rest param becomesunknownnotunknown[]. 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 incrates/biome_js_type_info/src/local_inference.rsaroundfrom_binding_with_annotationto defaultis_restcases toTypeData::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.
📒 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 necessaryUsed by the new helper for identifier extraction; tidy and to the point.
1482-1482: Good call: delegate JsRestParameter handlingRouting via
from_js_rest_parameterremoves duplication and keepsfrom_any_js_parameterlean.
1502-1510: Nice de-dupe: centralise formal parameter handlingSwitching 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 constraintsCentralising 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).
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.