Skip to content

fix(lint/noShadow): ignore parameters in function type signatures#9508

Closed
sudabg wants to merge 2 commits intobiomejs:mainfrom
sudabg:fix/no-shadow-function-type
Closed

fix(lint/noShadow): ignore parameters in function type signatures#9508
sudabg wants to merge 2 commits intobiomejs:mainfrom
sudabg:fix/no-shadow-function-type

Conversation

@sudabg
Copy link

@sudabg sudabg commented Mar 16, 2026

Summary

Fixes #9482

The noShadow rule incorrectly flags parameter names in function type signatures as shadowing outer variables. For example:

function fn(options: unknown, callback: (options: unknown) => void) {}
//                                     ^^^^^^^^ incorrectly flagged

Function type parameters are type-only and don't create runtime bindings — they should not trigger shadowing warnings.

Changes

  • Added is_inside_function_type() helper that checks if a binding is inside a TsFunctionType ancestor
  • Extended the existing function parameter type-only check in evaluate_shadowing() to also skip bindings inside function types

This follows the same pattern as the existing is_inside_type_parameter() and is_inside_type_member() checks.

Test plan

Parameters in function type signatures like (options: unknown) => void
are type-only and don't create runtime bindings. They should not be
flagged for shadowing outer variables.

Adds is_inside_function_type() check using TsFunctionType ancestor
detection, similar to existing is_inside_type_parameter() and
is_inside_type_member() checks.

Fixes biomejs#9482
@changeset-bot
Copy link

changeset-bot bot commented Mar 16, 2026

🦋 Changeset detected

Latest commit: 9baba0d

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 Mar 16, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ea0ecc96-869a-4934-8e71-426ffae5d25b

📥 Commits

Reviewing files that changed from the base of the PR and between 76c514a and 9baba0d.

📒 Files selected for processing (2)
  • .changeset/fix-no-shadow-function-types.md
  • crates/biome_js_analyze/src/lint/nursery/no_shadow.rs
✅ Files skipped from review due to trivial changes (1)
  • .changeset/fix-no-shadow-function-types.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_js_analyze/src/lint/nursery/no_shadow.rs

Walkthrough

This PR updates the no_shadow nursery lint to skip reporting bindings that appear as parameter identifiers inside TypeScript TsFunctionType signatures. It adds is_inside_function_type(binding: &Binding) -> bool which walks syntax ancestors to detect TsFunctionType, and extends the early-exit logic that already excluded TsTypeParameter and TsPropertySignatureTypeMember contexts. A changeset records the patch release and links the fix to issue #9482.

Possibly related PRs

  • fix(noShadow): ts overloads #9360: Modifies the same crates/biome_js_analyze/src/lint/nursery/no_shadow.rs to exclude type-only parameter contexts (handles function-type parameters and overload signatures).

Suggested reviewers

  • ematipico
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing the noShadow rule to ignore parameters in function type signatures, which is the primary objective of this PR.
Description check ✅ Passed The description is clearly related to the changeset, explaining the issue, the rationale, and the implementation approach with a concrete example.
Linked Issues check ✅ Passed The PR successfully addresses issue #9482 by adding the is_inside_function_type() helper and extending evaluate_shadowing() to exclude bindings in TsFunctionType, directly meeting the core requirement.
Out of Scope Changes check ✅ Passed All changes are scoped to the noShadow rule fix and the changeset entry. No unrelated modifications are present; the implementation follows the established pattern used for type-only parameter checks.

✏️ 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
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

Needs a changeset

Comment on lines +302 to +303
/// function fn(options: unknown, cb: (options: unknown) => void) {}
/// // ^^^^^^^^ type-only parameter
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the pointer is misaligned

@dyc3 dyc3 self-assigned this Mar 20, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 20, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 156 skipped benchmarks1


Comparing sudabg:fix/no-shadow-function-type (9baba0d) with main (1710cf1)2

Open in CodSpeed

Footnotes

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

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

Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

Actually, looking at the snapshot diff, I'm not convinced this is a complete fix

@ematipico
Copy link
Member

That's a bot, I'll close the PR

@ematipico ematipico closed this Mar 21, 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.

💅 nusery/noShadow should not flag parameter names of function types

3 participants