-
-
Notifications
You must be signed in to change notification settings - Fork 714
feat: add useSpread rule #7681
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
base: main
Are you sure you want to change the base?
feat: add useSpread rule #7681
Conversation
🦋 Changeset detectedLatest commit: ecc82f9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 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 |
4592484
to
b89944e
Compare
WalkthroughAdds a new nursery lint rule Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
CodSpeed Performance ReportMerging #7681 will not alter performanceComparing Summary
Footnotes
|
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: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (7)
crates/biome_configuration/src/analyzer/linter/rules.rs
is excluded by!**/rules.rs
and included by**
crates/biome_diagnostics_categories/src/categories.rs
is excluded by!**/categories.rs
and included by**
crates/biome_js_analyze/src/lint/nursery.rs
is excluded by!**/nursery.rs
and included by**
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js.snap
is excluded by!**/*.snap
and included by**
crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js.snap
is excluded by!**/*.snap
and included by**
packages/@biomejs/backend-jsonrpc/src/workspace.ts
is excluded by!**/backend-jsonrpc/src/workspace.ts
and included by**
packages/@biomejs/biome/configuration_schema.json
is excluded by!**/configuration_schema.json
and included by**
📒 Files selected for processing (6)
.changeset/proud-bananas-smoke.md
(1 hunks)crates/biome_js_analyze/src/lint/nursery/use_spread.rs
(1 hunks)crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
(1 hunks)crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js
(1 hunks)crates/biome_rule_options/src/lib.rs
(1 hunks)crates/biome_rule_options/src/use_spread.rs
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
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/tests/specs/nursery/useSpread/valid.js
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js
crates/biome_rule_options/src/lib.rs
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
crates/biome_rule_options/src/use_spread.rs
**/tests/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place test files under a tests/ directory in each crate
Files:
crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
**/*.{rs,toml}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Before committing, format Rust and TOML files (e.g., via
just f
/just format
)
Files:
crates/biome_rule_options/src/lib.rs
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
crates/biome_rule_options/src/use_spread.rs
**/*.rs
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Document rules, assists, and options via inline rustdoc in Rust source
Files:
crates/biome_rule_options/src/lib.rs
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
crates/biome_rule_options/src/use_spread.rs
.changeset/**/*.md
📄 CodeRabbit inference engine (CONTRIBUTING.md)
.changeset/**/*.md
: Create changesets using thejust new-changeset
command; do not author them manually
In changeset markdown, only use headers #### or #####
Changeset descriptions must end every sentence with a full stop (.)
For bug fixes, start the changeset description with a linked issue reference like “Fixed #1234”
Prefer past tense for what was done and present tense for current behavior in changesets
Files:
.changeset/proud-bananas-smoke.md
🧠 Learnings (3)
📚 Learning: 2025-10-02T12:57:33.209Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-10-02T12:57:33.209Z
Learning: Applies to crates/biome_analyze/crates/biome_js_analyze/tests/specs/nursery/** : Place snapshot tests for new rules under tests/specs/nursery/<ruleName>/ with files prefixed by invalid* and valid*
Applied to files:
crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
📚 Learning: 2025-10-02T12:57:33.209Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-10-02T12:57:33.209Z
Learning: Applies to crates/biome_analyze/crates/biome_js_analyze/lib/src/lint/nursery/*.rs : Place all new JavaScript lint rules in the nursery group under biome_js_analyze/lib/src/lint/nursery/<rule_name>.rs
Applied to files:
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
📚 Learning: 2025-10-02T12:57:33.209Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-10-02T12:57:33.209Z
Learning: Applies to crates/biome_analyze/crates/biome_rule_options/lib/*.rs : Define per-rule options in biome_rule_options/lib/<rule>.rs with a dedicated options struct/enum (camelCase serde names, deny_unknown_fields, default) and derive Serialize/Deserialize/Deserializable (and schemars JsonSchema when schema feature is on)
Applied to files:
crates/biome_rule_options/src/use_spread.rs
🧬 Code graph analysis (2)
crates/biome_js_analyze/src/lint/nursery/use_spread.rs (2)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (2)
FixKind
(7920-7920)UseSpreadOptions
(8273-8273)crates/biome_js_factory/src/generated/node_factory.rs (4)
js_call_arguments
(293-306)js_call_argument_list
(6808-6828)js_spread
(3312-3320)js_call_expression
(307-317)
crates/biome_rule_options/src/use_spread.rs (1)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (1)
UseSpreadOptions
(8273-8273)
⏰ 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). (13)
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: Documentation
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Check Dependencies
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: Check JS Files
- GitHub Check: Test Node.js API
- GitHub Check: autofix
- GitHub Check: Bench (biome_js_formatter)
- GitHub Check: Bench (biome_js_analyze)
- GitHub Check: Bench (biome_js_parser)
- GitHub Check: Bench (biome_configuration)
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.
That's a good start! I left some feedback that should be addressed. Also, please address CodeRabbit suggestions, they are valid
let node = ctx.query(); | ||
let callee = node.callee().ok()?; | ||
|
||
let member_expr = AnyJsMemberExpression::cast(callee.into_syntax())?; |
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.
let member_expr = AnyJsMemberExpression::cast(callee.into_syntax())?; | |
let member_expr = AnyJsMemberExpression::cast_ref(callee.syntax())?; |
let applied_object = member_expr.object().ok()?; | ||
|
||
let is_this_correct = if let Some(object_member) = | ||
AnyJsMemberExpression::cast(applied_object.clone().into_syntax()) |
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.
Use cast_ref
|
||
let applied_object = member_expr.object().ok()?; | ||
|
||
let is_this_correct = if let Some(object_member) = |
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.
Please find a better name for the variable.
let is_this_correct = if let Some(object_member) = | ||
AnyJsMemberExpression::cast(applied_object.clone().into_syntax()) | ||
{ | ||
object_member.object().ok()?.syntax().text_trimmed() == this_arg.syntax().text_trimmed() |
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.
What is this comparison doing? At first glance, I would say it's incorrect because we're comparing the text of two nodes, which is something we never do because it causes many errors. Calling text_trimmed
on a node removes the trivia that belong to the node, but it doesn't remove the trivia that belong to all the descendants.
We usually query the tokens we want to compare, so they don't contain trivia
"Use the spread operator instead of "<Emphasis>".apply()"</Emphasis>"." | ||
}, |
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.
Please reword the diagnostics to match our rule pillars: https://biomejs.dev/linter/#rule-pillars
Also "use the..." Sentence is already part of the action, so it's redundant here
language: "js", | ||
sources: &[RuleSource::Eslint("prefer-spread").same()], | ||
recommended: true, | ||
fix_kind: FixKind::Safe, |
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.
I would start with an unsafe fix, since it's a new rule
let callee = node.callee().ok()?; | ||
let member_expr = AnyJsMemberExpression::cast(callee.into_syntax())?; | ||
let object = member_expr.object().ok()?; |
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.
We're repeating code here. Why don't you use the State
to pass the information you need?
c3ca6d4
to
6cbc9ad
Compare
6cbc9ad
to
2e1ae7d
Compare
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
♻️ Duplicate comments (2)
crates/biome_js_analyze/src/lint/nursery/use_spread.rs (2)
83-86
: Add documentation explaining the array literal exclusion.As per past review feedback, please document in the rustdoc why
.apply()
calls with array literals as the second argument are excluded from this rule. This helps future maintainers understand the design decision.Based on past review comments.
159-170
: Critical: Parentheses still break detection.This was flagged in a previous review but remains unresolved. When comparing
obj
to(obj)
, the text comparison fails becausetext_trimmed()
preserves parentheses. ESLint catches these cases, so we lose parity.Consider using
omit_parentheses()
or a semantic comparison before extracting the identifier token. For example:fn are_nodes_equal(node1: &AnyJsExpression, node2: &AnyJsExpression) -> bool { let object_token = get_identifier_token(&node1.omit_parentheses()); let this_token = get_identifier_token(&node2.omit_parentheses()); // ... rest of comparison }Based on past review comments.
🧹 Nitpick comments (2)
crates/biome_js_analyze/src/lint/nursery/use_spread.rs (2)
90-91
: Consider a more descriptive variable name.
is_this_correct
is vague. Something likeis_this_binding_valid
orthis_arg_matches_object
would better convey that we're verifying thethis
argument corresponds to the object being called.Based on past review comments.
110-111
: Consider enriching the diagnostic message.Biome's rule pillars encourage explaining the benefit. Rather than just stating what to do, briefly mention why spread is preferred (e.g., more concise, clearer). The current message tells the user what to change but not why it matters.
Based on coding guidelines: rule pillars from https://biomejs.dev/linter/#rule-pillars
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
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/lint/nursery/use_spread.rs
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
**/*.{rs,toml}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Before committing, format Rust and TOML files (e.g., via
just f
/just format
)
Files:
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
**/*.rs
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Document rules, assists, and options via inline rustdoc in Rust source
Files:
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/nursery/use_spread.rs (3)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (2)
FixKind
(7920-7920)UseSpreadOptions
(8273-8273)crates/biome_rowan/src/ast/mod.rs (1)
cast_ref
(142-151)crates/biome_js_factory/src/generated/node_factory.rs (4)
js_call_arguments
(293-306)js_call_argument_list
(6808-6828)js_spread
(3312-3320)js_call_expression
(307-317)
🔇 Additional comments (2)
crates/biome_js_analyze/src/lint/nursery/use_spread.rs (2)
159-170
: Limited scope: only identifier expressions are compared.
are_nodes_equal
only handlesJsIdentifierExpression
. Cases likeobj.prop.apply(obj.prop, args)
won't be detected becauseget_identifier_token
returnsNone
for member expressions. This is acceptable for an initial implementation but limits coverage compared to ESLint.If broader coverage is desired, consider implementing a more comprehensive equality check or document this limitation in the rule's rustdoc.
68-70
: Maintain.text()
usage for member_name comparisons
All existing lints usemember_expr.member_name()?.text()
and, sincemember_name()
returns an identifier token, this comparison is precise—no change needed.
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: 1
🧹 Nitpick comments (2)
crates/biome_js_analyze/src/lint/nursery/use_spread.rs (2)
88-97
: Consider adding explanatory comments.The
is_same_reference
logic correctly handles two distinct cases:
- When
applied_object
is a member expression (e.g.,obj.foo
), it compares the base object with thethis
argument- When it's a simple reference (e.g.,
foo
), it verifies thethis
argument isnull
orundefined
Adding brief inline comments would help future maintainers quickly understand these branches.
148-168
: Conservative identifier comparison is safe.The helper functions correctly extract identifier tokens and compare them. Using
text_trimmed()
on tokens is sound since tokens lack descendants with trivia.The current approach is conservative: if either expression isn't a simple identifier (e.g., due to parentheses),
are_nodes_equal
returnsfalse
. This avoids false positives but may miss valid cases likeobj.foo.apply((obj), args)
.To handle parenthesized expressions, consider unwrapping them before extracting the identifier. For example:
fn get_identifier_token(node: &AnyJsExpression) -> Option<SyntaxToken<JsLanguage>> { let unwrapped = node.omit_parentheses(); match unwrapped { AnyJsExpression::JsIdentifierExpression(identifier) => identifier .name() .ok() .and_then(|name| name.value_token().ok()), _ => None, } }This refinement can be deferred if you prefer shipping the conservative version first.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js.snap
is excluded by!**/*.snap
and included by**
📒 Files selected for processing (4)
.changeset/proud-bananas-smoke.md
(1 hunks)crates/biome_js_analyze/src/lint/nursery/use_spread.rs
(1 hunks)crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
(1 hunks)crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- .changeset/proud-bananas-smoke.md
- crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js
🧰 Additional context used
📓 Path-based instructions (5)
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/lint/nursery/use_spread.rs
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
**/*.{rs,toml}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Before committing, format Rust and TOML files (e.g., via
just f
/just format
)
Files:
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
**/*.rs
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Document rules, assists, and options via inline rustdoc in Rust source
Files:
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
**/tests/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place test files under a tests/ directory in each crate
Files:
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-10-02T12:57:33.209Z
Learning: Applies to crates/biome_analyze/crates/biome_js_analyze/lib/src/lint/nursery/*.rs : Place all new JavaScript lint rules in the nursery group under biome_js_analyze/lib/src/lint/nursery/<rule_name>.rs
📚 Learning: 2025-10-02T12:57:33.209Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-10-02T12:57:33.209Z
Learning: Applies to crates/biome_analyze/crates/biome_js_analyze/lib/src/lint/nursery/*.rs : Place all new JavaScript lint rules in the nursery group under biome_js_analyze/lib/src/lint/nursery/<rule_name>.rs
Applied to files:
crates/biome_js_analyze/src/lint/nursery/use_spread.rs
📚 Learning: 2025-10-02T12:57:33.209Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-10-02T12:57:33.209Z
Learning: Applies to crates/biome_analyze/crates/biome_js_analyze/tests/specs/nursery/** : Place snapshot tests for new rules under tests/specs/nursery/<ruleName>/ with files prefixed by invalid* and valid*
Applied to files:
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/nursery/use_spread.rs (3)
packages/@biomejs/backend-jsonrpc/src/workspace.ts (2)
FixKind
(7920-7920)UseSpreadOptions
(8273-8273)crates/biome_rowan/src/ast/mod.rs (1)
cast_ref
(142-151)crates/biome_js_factory/src/generated/node_factory.rs (4)
js_call_arguments
(293-306)js_call_argument_list
(6808-6828)js_spread
(3312-3320)js_call_expression
(307-317)
🔇 Additional comments (5)
crates/biome_js_analyze/src/lint/nursery/use_spread.rs (5)
1-11
: Imports look correct.All necessary modules are imported, and the structure follows Biome's conventions for lint rules.
13-58
: Rule declaration is well-structured.The documentation provides clear examples, and the metadata correctly sets
fix_kind: FixKind::Unsafe
, aligning with the recommendation from past reviews to start conservatively.
70-73
: Member expression handling looks correct.Using
cast_ref
as requested in past reviews, and checking the member name is"apply"
.
106-115
: Diagnostic message is clear and concise.The message effectively communicates why the code is flagged without being verbose.
117-145
: Fix generation follows Biome patterns correctly.The code properly leverages the
State
to avoid duplication, constructs the replacement using factory methods, and produces a clear action message.
foo.apply(null, args); | ||
foo.apply(null, [1, 2, 3]); | ||
foo.apply(undefined, args); | ||
obj.foo.apply(obj, args); |
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.
🛠️ Refactor suggestion | 🟠 Major
❓ Verification inconclusive
Test coverage looks solid.
The four test cases cover the main patterns: null
/undefined
as the this
argument, array literals, and same-object references. These align well with the rule's intended diagnostics.
Since a past review mentioned parentheses breaking detection (supposedly addressed in 6cbc9ad), consider verifying that edge cases like obj.foo.apply((obj), args)
or (foo).apply(null, args)
are handled correctly—either flagged here or covered in a separate test file.
🏁 Script executed:
#!/bin/bash
# Description: Check if parenthesized expression test cases exist
# Expected: Find test cases with parentheses in apply calls
rg -n -A2 -B2 '\(.*\)\.apply' crates/biome_js_analyze/tests/specs/nursery/useSpread/
Length of output: 0
Add tests for parenthesized apply
calls
No existing specs cover calls like obj.foo.apply((obj), args)
or (foo).apply(null, args)
. Please include these invalid cases to ensure parentheses detection remains correct.
🤖 Prompt for AI Agents
In crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js around lines
2 to 5, add test cases that cover parenthesized callee expressions for apply
(e.g., (foo).apply(null, args), obj.foo.apply((obj), args), (obj.foo).apply(obj,
args)) so the suite includes invalid calls with parentheses; update the file by
inserting these parenthesized variants alongside the existing cases to ensure
the parser/validator rejects them the same as their non-parenthesized
counterparts.
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
♻️ Duplicate comments (1)
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js (1)
3-6
: Parenthesised test cases still missing.The past review requested test cases for parenthesised
apply
calls (e.g.,(foo).apply(null, args)
,obj.foo.apply((obj), args)
). These remain absent.Could you add a few parenthesised variants to ensure the parser handles them correctly?
🧹 Nitpick comments (1)
crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js (1)
8-10
: Consider testing with more than 2 arguments.The rule should only flag 2-argument
apply
calls. Adding a case likefoo.apply(null, args, extra)
would verify it doesn't fire on 3+ arguments.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js.snap
is excluded by!**/*.snap
and included by**
crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js.snap
is excluded by!**/*.snap
and included by**
📒 Files selected for processing (2)
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
(1 hunks)crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js
(1 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/tests/specs/nursery/useSpread/valid.js
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
**/tests/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place test files under a tests/ directory in each crate
Files:
crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
🧠 Learnings (1)
📚 Learning: 2025-10-02T12:57:33.209Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-10-02T12:57:33.209Z
Learning: Applies to crates/biome_analyze/crates/biome_js_analyze/tests/specs/nursery/** : Place snapshot tests for new rules under tests/specs/nursery/<ruleName>/ with files prefixed by invalid* and valid*
Applied to files:
crates/biome_js_analyze/tests/specs/nursery/useSpread/valid.js
crates/biome_js_analyze/tests/specs/nursery/useSpread/invalid.js
Summary
Ported the ESLint rule
prefer-spread
to a new Biome lint ruleuseSpread
.This rule enforces the use of the spread syntax
...
over the more verbose Function.prototype.apply() method when calling variadic functions, as it's the modern, idiomatic pattern in ES2015+. It includes a safe fix to automatically migrate code.Closes #7661