Skip to content

Commit

Permalink
fix(noUnusedFunctionParameters): ignore parameter in constructor types (
Browse files Browse the repository at this point in the history
#4237)

Co-authored-by: zoomdong <[email protected]>
  • Loading branch information
Conaclos and fireairforce authored Oct 10, 2024
1 parent af3b550 commit 6e69622
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
35 changes: 25 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,33 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

Contributed by @Conaclos

- Fixes [#4059](https://github.com/biomejs/biome/issues/4059), the rule [noUselessFragments](https://biomejs.dev/linter/rules/no-useless-fragments/) now correctly handles fragments containing HTML escapes (e.g. `&nbsp;`) inside expression escapes `{ ... }`.
The following code is no longer reported:
- [noUselessFragments](https://biomejs.dev/linter/rules/no-useless-fragments/) now correctly handles fragments containing HTML escapes (e.g. `&nbsp;`) inside expression escapes `{ ... }` ([#4059](https://github.com/biomejs/biome/issues/4059)).

```jsx
function Component() {
return (
<div key={index}>{line || <>&nbsp;</>}</div>
)
}
```
The following code is no longer reported:

```jsx
function Component() {
return (
<div key={index}>{line || <>&nbsp;</>}</div>
)
}
```

Contributed by @fireairforce
Contributed by @fireairforce

- [noUnusedFunctionParameters](https://biomejs.dev/linter/rules/no-unused-function-parameters/) and [noUnusedVariables](https://biomejs.dev/linter/rules/no-unused-variables/) no longer reports a parameter as unused when another parameter has a constructor type with the same parameter name ([#4227](https://github.com/biomejs/biome/issues/4227)).

In the following code, the `name` parameter is no longer reported as unused.

```ts
export class Foo {
bar(name: string, _class: new (name: string) => any) {
return name
}
}
```

Contributed by @Conaclos

### Parser

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Foo {
bar(name: string, _class: new (name: string) => any) {
return name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: issue4227.ts
---
# Input
```ts
class Foo {
bar(name: string, _class: new (name: string) => any) {
return name
}
}
```
8 changes: 6 additions & 2 deletions crates/biome_js_semantic/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ impl SemanticEventExtractor {
let node = node.syntax();
if matches!(
node.kind(),
JsSyntaxKind::TS_FUNCTION_TYPE | JsSyntaxKind::TS_MAPPED_TYPE
JsSyntaxKind::TS_CONSTRUCTOR_TYPE
| JsSyntaxKind::TS_FUNCTION_TYPE
| JsSyntaxKind::TS_MAPPED_TYPE
) {
self.push_scope(
node.text_trimmed_range(),
Expand Down Expand Up @@ -811,7 +813,9 @@ impl SemanticEventExtractor {
let node = node.syntax();
if matches!(
node.kind(),
JsSyntaxKind::TS_FUNCTION_TYPE | JsSyntaxKind::TS_MAPPED_TYPE
JsSyntaxKind::TS_CONSTRUCTOR_TYPE
| JsSyntaxKind::TS_FUNCTION_TYPE
| JsSyntaxKind::TS_MAPPED_TYPE
) {
self.pop_scope(node.text_trimmed_range());
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_semantic/src/semantic_model/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl SemanticModelBuilder {
| JS_FOR_IN_STATEMENT
| JS_SWITCH_STATEMENT
| JS_CATCH_CLAUSE
| TS_CONSTRUCTOR_TYPE
| TS_FUNCTION_TYPE
| TS_MAPPED_TYPE => {
self.scope_node_by_range
Expand Down

0 comments on commit 6e69622

Please sign in to comment.