diff --git a/.changeset/fix-no-shadow-function-types.md b/.changeset/fix-no-shadow-function-types.md new file mode 100644 index 000000000000..5653da58aea3 --- /dev/null +++ b/.changeset/fix-no-shadow-function-types.md @@ -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. diff --git a/crates/biome_js_analyze/src/lint/nursery/no_shadow.rs b/crates/biome_js_analyze/src/lint/nursery/no_shadow.rs index 8006fe16dcf9..9f72d3633118 100644 --- a/crates/biome_js_analyze/src/lint/nursery/no_shadow.rs +++ b/crates/biome_js_analyze/src/lint/nursery/no_shadow.rs @@ -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; } @@ -291,6 +293,24 @@ fn is_inside_function_parameters(binding: &Binding) -> bool { .any(|ancestor| ancestor.cast::().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::().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