Skip to content

Commit

Permalink
fix(noUnusedFunctionParameters): ignore parameter in constructor types
Browse files Browse the repository at this point in the history
  • Loading branch information
fireairforce authored and Conaclos committed Oct 10, 2024
1 parent 970f498 commit df21252
Show file tree
Hide file tree
Showing 4 changed files with 48 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:/biomejs/b

Contributed by @Conaclos

- Fixes [#4059](https:/biomejs/biome/issues/4059), the rule [noUselessFragments](https://biomejs.dev/linter/rules/no-useless-fragments/) now correctly handles fragments containing HTML escapes (e.g. ` `) 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. ` `) inside expression escapes `{ ... }` ([#4059](https:/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:/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

0 comments on commit df21252

Please sign in to comment.