+
Skip to content

Conversation

siketyan
Copy link
Member

@siketyan siketyan commented Sep 14, 2025

Summary

Fixes #6893

The rule is used to find a first ancestor node that is a valid expression. However, some nodes including a shorthand object member doesn't have an expression inside. To catch these cases, I changed the logic to also find a reference identifier while searching the ancestors.

Test Plan

Added a snapshot test.

Docs

N/A

@siketyan siketyan requested review from a team September 14, 2025 13:31
@siketyan siketyan self-assigned this Sep 14, 2025
Copy link

changeset-bot bot commented Sep 14, 2025

🦋 Changeset detected

Latest commit: 9a42881

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-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Sep 14, 2025
Copy link
Contributor

coderabbitai bot commented Sep 14, 2025

Walkthrough

  • Adds a changeset for a patch release of @biomejs/biome.
  • Updates useExhaustiveDependencies rule to recognise JsReferenceIdentifier and convert shorthand object members into identifier expressions when constructing dependency arrays.
  • Adjusts imports to use JsReferenceIdentifier from biome_js_syntax and StableHookResult/UseExhaustiveDependenciesOptions from biome_rule_options::use_exhaustive_dependencies.
  • Adds a test case (issue6893.js) covering shorthand object members inside useEffect and empty dependency arrays.

Possibly related issues

Suggested labels

A-Linter, L-JavaScript, A-Diagnostic

Suggested reviewers

  • arendjr
  • ematipico
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/GH-6893

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately describes the primary change: a fix to the useExhaustiveDependencies lint rule that correctly derives dependency lists when a shorthand object member captures identifiers, which matches the code changes and added test. It's specific, concise, and readable for a teammate scanning history.
Description Check ✅ Passed The PR description accurately summarises the change: it explains that the useExhaustiveDependencies rule now also searches for reference identifiers to handle shorthand object members, references issue #6893, and notes a snapshot test was added, which matches the code changes and new test in the diff.

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)
.changeset/brave-camels-sin.md (1)

5-5: Changeset punctuation: end sentences with a period.

Guidelines ask for every sentence to end with a period. Replace the colons after “For example” and “is now correctly fixed to” with full stops.

- Fixed [#6893](https://github.com/biomejs/biome/issues/6893): The [`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/) rule now correctly adds a dependency that is captured in a shorthand object member. For example:
+ Fixed [#6893](https://github.com/biomejs/biome/issues/6893): The [`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/) rule now correctly adds a dependency that is captured in a shorthand object member. For example.
@@
-is now correctly fixed to:
+This is now correctly fixed as follows.

Also applies to: 13-13

crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs (1)

1003-1008: Correctly lift JsReferenceIdentifier to an identifier expression when fixing deps.

This fixes the shorthand-member gap by preferring a JsReferenceIdentifier ancestor and constructing a JsIdentifierExpression, falling back to AnyJsExpression otherwise. The trim_trivia() keeps edits clean. Nice and targeted.

Two tiny considerations (non-blocking):

  • This walks ancestors per fix; negligible, but if you batch more nodes later, consider hoisting the cast once.
  • Add a spec where the capture is within nested object literals: console.log({ foo: { bar } }) to guard regressions.
📜 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 b2da976 and 9a42881.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/correctness/useExhaustiveDependencies/issue6893.js.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (3)
  • .changeset/brave-camels-sin.md (1 hunks)
  • crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs (2 hunks)
  • crates/biome_js_analyze/tests/specs/correctness/useExhaustiveDependencies/issue6893.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
.changeset/*.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

.changeset/*.md: In changeset files, only use #### or ##### headers; avoid other header levels
Changeset descriptions should use past tense for what you did (e.g., "Added...")
Describe current Biome behavior in present tense within changesets (e.g., "Biome now supports...")
For bug fixes in changesets, start with a link to the issue (e.g., "Fixed #1234: ...")
When referencing rules or assists in changesets, include links to their documentation pages
Include a minimal code block in the changeset when applicable to demonstrate the change
End every sentence in the changeset description with a period

Files:

  • .changeset/brave-camels-sin.md
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/correctness/useExhaustiveDependencies/issue6893.js
  • crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs
crates/biome_*/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place core crates under /crates/biome_*/

Files:

  • crates/biome_js_analyze/tests/specs/correctness/useExhaustiveDependencies/issue6893.js
  • crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs
**/tests/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place test files under a tests/ directory in each crate

Files:

  • crates/biome_js_analyze/tests/specs/correctness/useExhaustiveDependencies/issue6893.js
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Format all Rust source files before committing (just f)

Files:

  • crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs
🧠 Learnings (8)
📚 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_analyze/src/lint/correctness/use_exhaustive_dependencies.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_analyze/src/lint/correctness/use_exhaustive_dependencies.rs
📚 Learning: 2025-09-10T08:05:22.867Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-09-10T08:05:22.867Z
Learning: Applies to crates/biome_analyze/crates/biome_js_analyze/lib/src/{lint,assist}/**/*.rs : When banning globals (e.g., `noConsoleLog`), check the semantic model to avoid false positives from locally shadowed bindings

Applied to files:

  • crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs
📚 Learning: 2025-09-10T08:05:22.867Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-09-10T08:05:22.867Z
Learning: Applies to crates/biome_analyze/**/src/{lint,assist}/**/*.rs : Avoid deep indentation and panics; prefer `?`, `ok()?`, and combinators (`map`, `and_then`, `filter`) over nested `if let`/`unwrap`/`expect`

Applied to files:

  • crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs
📚 Learning: 2025-09-10T08:05:22.867Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-09-10T08:05:22.867Z
Learning: Applies to crates/biome_analyze/crates/biome_rule_options/lib/**/*.rs : Define per-rule options types in `biome_rule_options` crate (one file per rule, e.g., `lib/use_my_rule.rs`)

Applied to files:

  • crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.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_analyze/src/lint/correctness/use_exhaustive_dependencies.rs
📚 Learning: 2025-08-11T11:48:52.001Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-08-11T11:48:52.001Z
Learning: Applies to crates/biome_js_formatter/**/Cargo.toml : Add biome_js_formatter as a path dependency in Cargo.toml: biome_js_formatter = { version = "0.0.1", path = "../biome_js_formatter" }

Applied to files:

  • crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs
📚 Learning: 2025-09-10T08:05:22.867Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-09-10T08:05:22.867Z
Learning: Applies to crates/biome_analyze/**/src/{lint,assist}/**/*.rs : If a rule returns a code action (implements `action`), add `fix_kind` in `declare_lint_rule!` and use `ctx.metadata().applicability()` when building the action

Applied to files:

  • crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs (1)
crates/biome_rowan/src/ast/mod.rs (1)
  • cast_ref (142-151)
⏰ 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). (24)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Check Dependencies
  • GitHub Check: Bench (biome_html_parser)
  • GitHub Check: Documentation
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_html_formatter)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
🔇 Additional comments (2)
crates/biome_js_analyze/src/lint/correctness/use_exhaustive_dependencies.rs (2)

12-14: Import JsReferenceIdentifier is needed for the new lifting logic. LGTM.

Used below to build a proper JsIdentifierExpression from shorthand members.


20-22: Options moved to biome_rule_options.

Good alignment with the “options live in biome_rule_options” guideline; no API break here.

Comment on lines +1 to +8
function App() {
const firstId = `${Math.random()}`
const secondId = `${Math.random()}`

React.useEffect(() => {
console.log({firstId, secondId})
}, [])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Make the test self-contained (import React) and assert expectations.

  • Add import React from "react"; so React.useEffect isn’t an undeclared global in snapshots.
  • Consider adding an explicit expectation (e.g., expect diagnostic/fix) to lock behaviour.
+import React from "react";
 function App() {
 	const firstId = `${Math.random()}`
 	const secondId = `${Math.random()}`
 
 	React.useEffect(() => {
 		console.log({firstId, secondId})
 	}, [])
 }

Run this quick scan to check how similar specs handle imports/expectations:


🏁 Script executed:

#!/bin/bash
# Inspect neighbouring specs for typical patterns
rg -n -C0 'import\s+\{?\s*useEffect|React\.useEffect|expect_diagnostic|expect_fix' crates/biome_js_analyze/tests/specs/correctness/useExhaustiveDependencies

Length of output: 6164


Add React import and an explicit expectation

Add import React from "react"; to crates/biome_js_analyze/tests/specs/correctness/useExhaustiveDependencies/issue6893.js so React.useEffect isn't an undeclared global in snapshots. Add an explicit assertion (e.g., expect_diagnostic or expect_fix) to lock behaviour.

+import React from "react";
 function App() {
 	const firstId = `${Math.random()}`
 	const secondId = `${Math.random()}`
 
 	React.useEffect(() => {
 		console.log({firstId, secondId})
 	}, [])
 }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In
crates/biome_js_analyze/tests/specs/correctness/useExhaustiveDependencies/issue6893.js
around lines 1 to 8, the test file uses React.useEffect but does not import
React and lacks an explicit snapshot/assertion; add the line `import React from
"react";` at the top of the file so React.useEffect is not treated as an
undeclared global, and add a concrete assertion (for example an
`expect_diagnostic(...)` or `expect_fix(...)` call) to the test to lock the
expected behavior in the snapshot.

Copy link

codspeed-hq bot commented Sep 14, 2025

CodSpeed Performance Report

Merging #7498 will not alter performance

Comparing fix/GH-6893 (9a42881) with main (c015765)1

Summary

✅ 133 untouched

Footnotes

  1. No successful run was found on main (b2da976) during the generation of this report, so c015765 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@siketyan siketyan merged commit 002cded into main Sep 14, 2025
30 of 31 checks passed
@siketyan siketyan deleted the fix/GH-6893 branch September 14, 2025 16:30
@github-actions github-actions bot mentioned this pull request Sep 14, 2025
kedevked pushed a commit to kedevked/biome that referenced this pull request Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 useExhaustiveDependencies not suggesting correct fixes when dependencies are used inside object

2 participants

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