mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
test(linter/no-useless-constructor): add cases for initializers in subclass constructors (#6390)
This commit is contained in:
parent
5ea9ef7af7
commit
84aa2a237c
1 changed files with 41 additions and 0 deletions
|
|
@ -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![
|
||||
|
|
|
|||
Loading…
Reference in a new issue