Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-no-shadow-function-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#9482](https://github.com/biomejs/biome/issues/9482): [`noShadow`](https://biomejs.dev/linter/rules/no-shadow/) no longer reports parameter names declared inside TypeScript function type signatures as shadowing outer variables.
22 changes: 21 additions & 1 deletion crates/biome_js_analyze/src/lint/nursery/no_shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ fn evaluate_shadowing(model: &SemanticModel, binding: &Binding, upper_binding: &
return false;
}
} else if is_inside_function_parameters(binding)
&& (is_inside_type_parameter(binding) || is_inside_type_member(binding))
&& (is_inside_type_parameter(binding)
|| is_inside_type_member(binding)
|| is_inside_function_type(binding))
{
return false;
}
Expand Down Expand Up @@ -291,6 +293,24 @@ fn is_inside_function_parameters(binding: &Binding) -> bool {
.any(|ancestor| ancestor.cast::<JsParameterList>().is_some())
}

/// Whether the binding is a parameter inside a function type signature.
///
/// Function type parameters are type-only and don't create actual bindings at
/// runtime, so they should not be flagged for shadowing.
///
/// ```ts
/// function fn(options: unknown, cb: (options: unknown) => void) {}
/// // ^^^^^^^ type-only parameter
/// ```
fn is_inside_function_type(binding: &Binding) -> bool {
use biome_js_syntax::TsFunctionType;
binding
.syntax()
.ancestors()
.skip(1)
.any(|ancestor| ancestor.cast::<TsFunctionType>().is_some())
}

/// 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
Expand Down
Loading