-
-
Notifications
You must be signed in to change notification settings - Fork 716
fix(lint/useExhaustiveDependencies): correctly fix the dependency list from a shorthand object member #7498
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
Conversation
…t from a shorthand object member
🦋 Changeset detectedLatest commit: 9a42881 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 |
Walkthrough
Possibly related issues
Suggested labels
Suggested reviewers
✨ Finishing touches
🧪 Generate unit tests
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.
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 Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
|
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)
.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 liftJsReferenceIdentifier
to an identifier expression when fixing deps.This fixes the shorthand-member gap by preferring a
JsReferenceIdentifier
ancestor and constructing aJsIdentifierExpression
, falling back toAnyJsExpression
otherwise. Thetrim_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
⛔ 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
: ImportJsReferenceIdentifier
is needed for the new lifting logic. LGTM.Used below to build a proper
JsIdentifierExpression
from shorthand members.
20-22
: Options moved tobiome_rule_options
.Good alignment with the “options live in biome_rule_options” guideline; no API break here.
function App() { | ||
const firstId = `${Math.random()}` | ||
const secondId = `${Math.random()}` | ||
|
||
React.useEffect(() => { | ||
console.log({firstId, secondId}) | ||
}, []) | ||
} |
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.
💡 Verification agent
🧩 Analysis chain
Make the test self-contained (import React) and assert expectations.
- Add
import React from "react";
soReact.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.
CodSpeed Performance ReportMerging #7498 will not alter performanceComparing Summary
Footnotes |
…t from a shorthand object member (biomejs#7498)
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