+
Skip to content

Conversation

kedevked
Copy link
Contributor

@kedevked kedevked commented Oct 4, 2025

Summary

Ported the ESLint rule prefer-spread to a new Biome lint rule useSpread.

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

Copy link

changeset-bot bot commented Oct 4, 2025

🦋 Changeset detected

Latest commit: ecc82f9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

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

@github-actions github-actions bot added A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Oct 4, 2025
@kedevked kedevked force-pushed the feature/add-use-spread branch from 4592484 to b89944e Compare October 4, 2025 21:21
Copy link
Contributor

coderabbitai bot commented Oct 4, 2025

Walkthrough

Adds a new nursery lint rule UseSpread (ported from ESLint’s prefer-spread) that detects Function.prototype.apply calls which can be replaced with spread syntax and emits a diagnostic with an (unsafe) automatic fix rewriting object.apply(thisArg, args) to object(...args) when the this‑binding and arguments shape are compatible. Adds UseSpreadOptions, exports the rule options module, new tests for valid and invalid cases, and a changeset. References linked issue #7661.

Suggested reviewers

  • ematipico
  • dyc3
  • siketyan

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues Check ✅ Passed The changes fully implement the objectives of issue #7661 by porting the ESLint prefer-spread rule to Biome, adding the useSpread rule, configuration options and corresponding tests exactly as specified.
Out of Scope Changes Check ✅ Passed All modifications are focused on introducing the useSpread lint rule, its documentation, options and tests, with no unrelated code or functionality altered outside the scope of porting the prefer-spread rule.
Description Check ✅ Passed The pull request description clearly outlines that the ESLint rule prefer-spread has been ported to a new Biome lint rule useSpread, explains its behaviour, mentions the automatic fix and references the closing issue, so it’s directly related and sufficiently informative.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title succinctly captures the main change – the addition of a new ‘useSpread’ lint rule – using standard commit-style phrasing while remaining clear and specific about the feature being introduced.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

codspeed-hq bot commented Oct 4, 2025

CodSpeed Performance Report

Merging #7681 will not alter performance

Comparing kedevked:feature/add-use-spread (c3ca6d4) with main (a8e7301)

Summary

✅ 53 untouched
⏩ 85 skipped1

Footnotes

  1. 85 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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: 2

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efc9980 and b89944e.

⛔ 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 the just 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)

@github-actions github-actions bot added the A-CLI Area: CLI label Oct 4, 2025
Copy link
Member

@ematipico ematipico left a 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())?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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())
Copy link
Member

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) =
Copy link
Member

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()
Copy link
Member

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

Comment on lines 110 to 111
"Use the spread operator instead of "<Emphasis>".apply()"</Emphasis>"."
},
Copy link
Member

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,
Copy link
Member

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

Comment on lines 119 to 121
let callee = node.callee().ok()?;
let member_expr = AnyJsMemberExpression::cast(callee.into_syntax())?;
let object = member_expr.object().ok()?;
Copy link
Member

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?

@kedevked kedevked force-pushed the feature/add-use-spread branch from c3ca6d4 to 6cbc9ad Compare October 6, 2025 13:48
@kedevked kedevked force-pushed the feature/add-use-spread branch from 6cbc9ad to 2e1ae7d Compare October 6, 2025 13:52
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

♻️ 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 because text_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 like is_this_binding_valid or this_arg_matches_object would better convey that we're verifying the this 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

📥 Commits

Reviewing files that changed from the base of the PR and between b89944e and 6cbc9ad.

📒 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 handles JsIdentifierExpression. Cases like obj.prop.apply(obj.prop, args) won't be detected because get_identifier_token returns None 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 use member_expr.member_name()?.text() and, since member_name() returns an identifier token, this comparison is precise—no change needed.

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: 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:

  1. When applied_object is a member expression (e.g., obj.foo), it compares the base object with the this argument
  2. When it's a simple reference (e.g., foo), it verifies the this argument is null or undefined

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 returns false. This avoids false positives but may miss valid cases like obj.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

📥 Commits

Reviewing files that changed from the base of the PR and between 6cbc9ad and 2e1ae7d.

⛔ 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.

Comment on lines +2 to +5
foo.apply(null, args);
foo.apply(null, [1, 2, 3]);
foo.apply(undefined, args);
obj.foo.apply(obj, args);
Copy link
Contributor

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.

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

♻️ 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 like foo.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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e1ae7d and ecc82f9.

⛔ 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

@kedevked kedevked changed the title Feature/add use spread feat: add use spread Oct 6, 2025
@kedevked kedevked changed the title feat: add use spread feat: add useSpread rule Oct 6, 2025
@kedevked kedevked requested a review from ematipico October 11, 2025 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 Port prefer-spread rule from base eslint

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载