Skip to content

Commit

Permalink
fix(analyzer): allow constructor with default parameters in noUseless…
Browse files Browse the repository at this point in the history
…Constructor (#1954)
  • Loading branch information
togami2864 authored Mar 4, 2024
1 parent 7c68aa5 commit 8150c8e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
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

0 comments on commit 8150c8e

Please sign in to comment.