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(analyzer): allow constructor with default parameters in noUselessConstructor #1954

Merged
merged 3 commits into from
Mar 4, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
- Fix [#1932](https://github.com/biomejs/biome/issues/1932) Allow redeclaration of type parameters in different declarations.
Contributed by @keita-hino

- Fix [#1945](https://github.com/biomejs/biome/issues/1945) Allow constructor with default parameters in `noUselessConstructor`

### Parser

#### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ declare_rule! {
/// ```
///
/// ```ts
/// class D {
/// constructor(public arg: number){}
/// }
///
/// class F extends D {
/// // constructor with default parameters are allowed.
/// constructor(arg = 4) {
/// super(arg)
/// }
/// }
/// ```
///
/// ```ts
/// @Decorator
/// class C {
/// constructor (prop: number) {}
Expand Down Expand Up @@ -227,6 +240,14 @@ fn is_delegating_initialization(
let param = param.ok()?;
let arg = arg.ok()?;
match (param, arg) {
(
AnyJsConstructorParameter::AnyJsFormalParameter(
AnyJsFormalParameter::JsFormalParameter(param),
),
_,
) if param.initializer().is_some() => {
return Some(false);
}
(
AnyJsConstructorParameter::JsRestParameter(param),
AnyJsCallArgument::JsSpread(arg),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ class G extends B {
super(bar);
}
}

class H extends B {
constructor(name = "default") {
super(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class G extends B {
}
}

class H extends B {
constructor(name = "default") {
super(name);
}
}

```


2 changes: 2 additions & 0 deletions website/src/content/docs/internals/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
- Fix [#1932](https://github.com/biomejs/biome/issues/1932) Allow redeclaration of type parameters in different declarations.
Contributed by @keita-hino

- Fix [#1945](https://github.com/biomejs/biome/issues/1945) Allow constructor with default parameters in `noUselessConstructor`

### Parser

#### Bug fixes
Expand Down
13 changes: 13 additions & 0 deletions website/src/content/docs/linter/rules/no-useless-constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ class C {
}
```

```ts
class D {
constructor(public arg: number){}
}

class F extends D {
// constructor with default parameters are allowed.
constructor(arg = 4) {
super(arg)
}
}
```

```ts
@Decorator
class C {
Expand Down
Loading