Skip to content

Commit

Permalink
refactor(noRedeclare): ignore var named as the enclosing function exp…
Browse files Browse the repository at this point in the history
…ression name (#3758)
  • Loading branch information
Conaclos committed Sep 2, 2024
1 parent ac0408f commit 7bcda36
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

Contributed by @Conaclos

- [noRedeclare](https://biomejs.dev/linter/rules/no-redeclare/) no longer report a variable named as the function expression where it is declared. Contributed by @Conaclos

- [noMultipleSpacesInRegularExpressionLiterals](https://biomejs.dev/linter/rules/no-multiple-spaces-in-regular-expression-literals/) now correctly provides a code fix when unicode characters are used.

- `useAdjacentOverloadSignatures` no longer reports a `#private` class member and a public class member that share the same name ([#3309](https://github.com/biomejs/biome/issues/3309)).
Expand Down
7 changes: 5 additions & 2 deletions crates/biome_js_analyze/src/lint/suspicious/no_redeclare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ fn check_redeclarations_in_single_scope(scope: &Scope, redeclarations: &mut Vec<
for binding in function_scope.bindings() {
let id_binding = binding.tree();
if let Some(decl) = id_binding.declaration() {
let name = id_binding.text();
declarations.insert(name, (id_binding.syntax().text_trimmed_range(), decl));
// Ignore the function itself.
if !matches!(decl, AnyJsBindingDeclaration::JsFunctionExpression(_)) {
let name = id_binding.text();
declarations.insert(name, (id_binding.syntax().text_trimmed_range(), decl));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"class C { static { var a; { let a; } } }",
"class C { static { let a; { let a; } } }",
"class C { static { { let a; } { let a; } } }",
"interface A { [index: string]: string; [index: number]: string; }"
"interface A { [index: string]: string; [index: number]: string; }",
"const foo = function foo() { const foo = 0; }"
]
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ class C { static { { let a; } { let a; } } }
interface A { [index: string]: string; [index: number]: string; }
```


# Input
```cjs
const foo = function foo() { const foo = 0; }
```

0 comments on commit 7bcda36

Please sign in to comment.