Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(noUnusedFunctionParameters): ignore parameter in constructor types #4237

Merged
merged 1 commit into from
Oct 10, 2024
Merged
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
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
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
Loading