Skip to content

Commit

Permalink
test(linter/no-useless-constructor): add cases for initializers in su…
Browse files Browse the repository at this point in the history
…bclass constructors (#6390)
  • Loading branch information
DonIsaac committed Oct 9, 2024
1 parent 5ea9ef7 commit 84aa2a2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,47 @@ fn test() {
"class A { constructor(readonly x: number) {} }",
"class A { constructor(private readonly x: number) {} }",
"class A extends B { constructor(override x: number) { super(x); } }",
"
class A {
protected foo: number | undefined;
constructor(foo?: number) {
this.foo = foo;
}
}
class B extends A {
protected foo: number;
constructor(foo: number = 0) {
super(foo);
}
}
",
"
class A {
protected foo: number | undefined;
constructor(foo?: number) {
this.foo = foo;
}
}
class B extends A {
constructor(foo?: number) {
super(foo ?? 0);
}
}
",
// TODO: type aware linting :(
// "
// class A {
// protected foo: string;
// constructor(foo: string) {
// this.foo = foo;
// }
// }
// class B extends A {
// constructor(foo: 'a' | 'b') {
// super(foo);
// }
// }
// ",
];

let fail = vec![
Expand Down

0 comments on commit 84aa2a2

Please sign in to comment.