fix(lint/noShadow): ignore parameters in function type annotations#9485
fix(lint/noShadow): ignore parameters in function type annotations#9485guoyangzhen wants to merge 2 commits intobiomejs:mainfrom
Conversation
Parameters in function type annotations like are type-only and should not be flagged as shadowing outer variables. Add TsFunctionType to the list of parent functions where parameters exist only at the type level and don't shadow runtime bindings. Fixes biomejs#9482
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
WalkthroughThis PR removes the NoShadow lint implementation from Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment Tip CodeRabbit can suggest fixes for GitHub Check annotations.Configure the |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/biome_js_analyze/src/lint/nursery/no_shadow.rs (1)
294-318: Good fix – consider updating the rustdoc to reflect the broader scope.The addition of
TsFunctionTypecorrectly prevents false positives for parameters inside function type annotations (e.g.,callback: (options: unknown) => void). These are indeed type-only bindings with no runtime existence.However, the function name
is_in_overload_signatureand its documentation (lines 294-297) now understate what this function covers.TsFunctionTypeisn't technically an "overload signature" – it's a function type annotation. The comment could be updated to clarify this broader scope.📝 Suggested documentation update
-/// Returns true if the binding is a parameter inside a TypeScript overload -/// signature (constructor, method, or function overload declaration without a -/// body). These parameters are type-only and should not be considered as -/// shadowing outer variables. +/// Returns true if the binding is a parameter inside a TypeScript type-only +/// function context (overload signatures, declare functions, or function type +/// annotations). These parameters are type-only and should not be considered +/// as shadowing outer variables.🤖 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_shadow.rs` around lines 294 - 318, Update the rustdoc for the function is_in_overload_signature (which checks a Binding) to reflect that it covers both TypeScript overload signatures and function type annotations (e.g., TsFunctionType) whose parameters are type-only and should not count as shadowing outer variables; change the comment wording so it explicitly mentions "overload signatures and function type annotations" and that parameters in these contexts have no runtime existence.
🤖 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_shadow.rs`:
- Around line 294-318: Update the rustdoc for the function
is_in_overload_signature (which checks a Binding) to reflect that it covers both
TypeScript overload signatures and function type annotations (e.g.,
TsFunctionType) whose parameters are type-only and should not count as shadowing
outer variables; change the comment wording so it explicitly mentions "overload
signatures and function type annotations" and that parameters in these contexts
have no runtime existence.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ee079c33-7ca5-4dac-bc91-f5e49f5da56c
📒 Files selected for processing (1)
crates/biome_js_analyze/src/lint/nursery/no_shadow.rs
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
Good catch from @coderabbitai! Updated the doc comment to clarify the broader scope of |
|
Tip For best results, initiate chat on the files or code changes.
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
Summary
Fixes
noShadowincorrectly flagging parameters inside function type annotations as shadowing outer variables.Problem
The
optionsparameter in the callback type is a type-level-only binding that doesn't exist at runtime. It should not be treated as shadowing the outeroptionsparameter.Root Cause
The
is_in_overload_signaturefunction checks for TypeScript declaration-only function types but missesTsFunctionType(function type annotations in parameter positions).Fix
Add
TsFunctionTypeto the match arm inis_in_overload_signature.Fixes #9482