Skip to content

fix(lint): fix false positive in noMisleadingReturnType for nested object widening#10006

Merged
ematipico merged 3 commits intobiomejs:mainfrom
minseong0324:fix/no-misleading-return-type-nested-object-widening
Apr 18, 2026
Merged

fix(lint): fix false positive in noMisleadingReturnType for nested object widening#10006
ematipico merged 3 commits intobiomejs:mainfrom
minseong0324:fix/no-misleading-return-type-nested-object-widening

Conversation

@minseong0324
Copy link
Copy Markdown
Contributor

I used Claude Code to assist with this implementation.

Summary

Addresses items from #9810: Nested object widening

Test Plan

Snapshot tests.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 16, 2026

🦋 Changeset detected

Latest commit: 952eef2

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 Apr 16, 2026
@minseong0324 minseong0324 force-pushed the fix/no-misleading-return-type-nested-object-widening branch 3 times, most recently from dbb2fd6 to 5b79e61 Compare April 16, 2026 15:12

while let Some((ann, inf)) = stack.pop() {
iterations += 1;
if iterations > 50 {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same iteration guard as is_nonunion_wider. Prevents infinite loops on cyclic types like interface Node { parent: Node }. 50 is a generous ceiling - real code never nests anywhere near that deep.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't use magic numbers though. Create a constant and document

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

is_nonunion_wider already uses the same 50 for the same iteration guard. Extract both into one shared constant in this PR, or split it into a separate cleanup PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ematipico 952eef2 extracts both into a shared constant. Let me know if you'd rather have a separate PR for it.

@minseong0324 minseong0324 marked this pull request as ready for review April 16, 2026 15:16
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 16, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 196 skipped benchmarks1


Comparing minseong0324:fix/no-misleading-return-type-nested-object-widening (952eef2) with main (f42405f)

Open in CodSpeed

Footnotes

  1. 196 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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 16, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Refactors is_only_property_literal_widening in the noMisleadingReturnType nursery lint to a unified stack-based traversal of (annotation_type, inferred_type) pairs. The traversal decomposes Tuple elements and Object member/index-signature pairs, tracks whether any literal widening occurred, enforces a 50-step iteration cap (returns false if exceeded), and returns false on unresolved or incompatible type mismatches. Adds two valid tests covering nested object and nested tuple return shapes and a changeset for a patch release.

Possibly related PRs

Suggested labels

A-Diagnostic

Suggested reviewers

  • dyc3
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: fixing a false positive in noMisleadingReturnType for nested object widening, which aligns with the file modifications and issue #9810.
Description check ✅ Passed The description is directly related to the changeset, explaining the motivation (addressing nested object widening from issue #9810) and test approach, with proper AI assistance disclosure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/tidy-planes-stay.md:
- Line 5: Update the changeset description in .changeset/tidy-planes-stay.md to
include a link to the referenced issue (`#9810`); edit the single-line summary
("Fixed `noMisleadingReturnType` incorrectly flagging nested object literals
with widened properties.") or the body to append the issue URL (e.g. "See:
https://github.com/<org>/<repo>/issues/9810" or the appropriate repo link) so
the bug-fix changeset contains the issue reference per guidelines.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 20347756-606a-44d8-a0de-25b550290520

📥 Commits

Reviewing files that changed from the base of the PR and between 8bf50e2 and 5b79e61.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/nursery/noMisleadingReturnType/valid.ts.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (3)
  • .changeset/tidy-planes-stay.md
  • crates/biome_js_analyze/src/lint/nursery/no_misleading_return_type.rs
  • crates/biome_js_analyze/tests/specs/nursery/noMisleadingReturnType/valid.ts

Comment thread .changeset/tidy-planes-stay.md Outdated
@minseong0324 minseong0324 force-pushed the fix/no-misleading-return-type-nested-object-widening branch from 5b79e61 to 65f01b5 Compare April 16, 2026 15:51
@minseong0324 minseong0324 marked this pull request as draft April 16, 2026 16:17
@minseong0324 minseong0324 marked this pull request as ready for review April 16, 2026 17:10
@minseong0324 minseong0324 marked this pull request as draft April 16, 2026 18:11
@minseong0324 minseong0324 force-pushed the fix/no-misleading-return-type-nested-object-widening branch from 65f01b5 to e79b09d Compare April 16, 2026 18:57
@minseong0324 minseong0324 marked this pull request as ready for review April 16, 2026 19:07
Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
crates/biome_js_analyze/src/lint/nursery/no_misleading_return_type.rs (1)

467-495: Optional: index-signature branch doesn't recurse into nested value types.

Unlike the named-member branch below (which pushes mismatched pairs onto the stack), the index-signature path only accepts matches via types_match or is_base_type_of_literal. So an annotation like Record<string, { x: string }> against an inferred { a: { x: "y" } } would bail out here rather than being recognised as pure literal widening. Not a regression introduced by this PR and arguably outside its scope — just flagging for a potential follow-up so the two branches stay symmetrical.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_js_analyze/src/lint/nursery/no_misleading_return_type.rs` around
lines 467 - 495, The index-signature branch (starting at
annotated_index_signature and using index_signature_value_type) currently only
accepts direct matches via types_match or is_base_type_of_literal and therefore
doesn't recurse into nested value types; update this branch to mirror the
named-member logic by, when a mismatch is found between
index_signature_value_type and an inferred_type (and it isn't a simple
base/literal match), push the pair (index_signature_value_type, inferred_type)
onto the same comparison stack (or invoke the same recursion routine used by the
named-member branch) so nested object literal widening (e.g., Record<string, {
x: string }> vs { a: { x: "y" } }) is recognized; keep the existing
index_signature_has_widening handling for base-of-literal cases and only return
false if the pushed comparisons ultimately fail.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/biome_js_analyze/src/lint/nursery/no_misleading_return_type.rs`:
- Around line 467-495: The index-signature branch (starting at
annotated_index_signature and using index_signature_value_type) currently only
accepts direct matches via types_match or is_base_type_of_literal and therefore
doesn't recurse into nested value types; update this branch to mirror the
named-member logic by, when a mismatch is found between
index_signature_value_type and an inferred_type (and it isn't a simple
base/literal match), push the pair (index_signature_value_type, inferred_type)
onto the same comparison stack (or invoke the same recursion routine used by the
named-member branch) so nested object literal widening (e.g., Record<string, {
x: string }> vs { a: { x: "y" } }) is recognized; keep the existing
index_signature_has_widening handling for base-of-literal cases and only return
false if the pushed comparisons ultimately fail.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aee22f9e-80cb-49ac-8c81-f9330b5245c2

📥 Commits

Reviewing files that changed from the base of the PR and between 65f01b5 and e79b09d.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/nursery/noMisleadingReturnType/valid.ts.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (3)
  • .changeset/tidy-planes-stay.md
  • crates/biome_js_analyze/src/lint/nursery/no_misleading_return_type.rs
  • crates/biome_js_analyze/tests/specs/nursery/noMisleadingReturnType/valid.ts
✅ Files skipped from review due to trivial changes (2)
  • .changeset/tidy-planes-stay.md
  • crates/biome_js_analyze/tests/specs/nursery/noMisleadingReturnType/valid.ts

@minseong0324 minseong0324 force-pushed the fix/no-misleading-return-type-nested-object-widening branch from e79b09d to 9425f15 Compare April 18, 2026 09:24
@minseong0324 minseong0324 force-pushed the fix/no-misleading-return-type-nested-object-widening branch from 99f712b to 38a6526 Compare April 18, 2026 09:28
@ematipico ematipico merged commit cf4c1c9 into biomejs:main Apr 18, 2026
30 checks passed
@github-actions github-actions bot mentioned this pull request Apr 18, 2026
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.

2 participants