chore(linter): port @typescript-eslint/no-dupe-class-members tests

This commit is contained in:
Boshen 2023-07-01 18:40:42 +08:00
parent a5b4f8bec1
commit 13290f8612
No known key found for this signature in database
GPG key ID: A69211CB52CC6548
3 changed files with 176 additions and 96 deletions

View file

@ -21,6 +21,7 @@ declare_oxc_lint!(
/// Disallow array constructor
///
/// ### Why is this bad?
///
/// Use of the Array constructor to construct a new array is generally discouraged in favor of array literal notation because of the single-argument pitfall and because the Array global may be redefined.
/// The exception is when the Array constructor is used to intentionally create sparse arrays of a specified size by giving the constructor a single numeric argument.
///

View file

@ -127,93 +127,95 @@ fn test() {
use crate::tester::Tester;
let pass = vec![
("class A { foo() {} bar() {} }", None),
("class A { static foo() {} foo() {} }", None),
("class A { get foo() {} set foo(value) {} }", None),
("class A { static foo() {} get foo() {} set foo(value) {} }", None),
("class A { foo() { } } class B { foo() { } }", None),
("class A { [foo]() {} foo() {} }", None),
("class A { 'foo'() {} 'bar'() {} baz() {} }", None),
("class A { *'foo'() {} *'bar'() {} *baz() {} }", None),
("class A { get 'foo'() {} get 'bar'() {} get baz() {} }", None),
("class A { 1() {} 2() {} }", None),
("class A { ['foo']() {} ['bar']() {} }", None),
("class A { [`foo`]() {} [`bar`]() {} }", None),
("class A { [12]() {} [123]() {} }", None),
("class A { [1.0]() {} ['1.0']() {} }", None),
("class A { [0x1]() {} [`0x1`]() {} }", None),
("class A { [null]() {} ['']() {} }", None),
("class A { get ['foo']() {} set ['foo'](value) {} }", None),
("class A { ['foo']() {} static ['foo']() {} }", None),
("class A { ['constructor']() {} constructor() {} }", None),
("class A { 'constructor'() {} [`constructor`]() {} }", None),
("class A { constructor() {} get [`constructor`]() {} }", None),
("class A { 'constructor'() {} set ['constructor'](value) {} }", None),
("class A { ['foo' + '']() {} ['foo']() {} }", None),
("class A { [`foo${''}`]() {} [`foo`]() {} }", None),
("class A { [-1]() {} ['-1']() {} }", None),
("class A { [foo]() {} [foo]() {} }", None),
("class A { foo; static foo; }", None),
("class A { foo; #foo; }", None),
("class A { '#foo'; #foo; }", None),
// Function overload of typescript
(
"class Foo {
foo(a: string): string;
foo(a: number): number;
foo(a: any): any {}
}",
None,
),
(
"abstract class X {
abstract foo(): number;
abstract foo(): string;
}",
None,
),
"class A { foo() {} bar() {} }",
"class A { static foo() {} foo() {} }",
"class A { get foo() {} set foo(value) {} }",
"class A { static foo() {} get foo() {} set foo(value) {} }",
"class A { foo() { } } class B { foo() { } }",
"class A { [foo]() {} foo() {} }",
"class A { 'foo'() {} 'bar'() {} baz() {} }",
"class A { *'foo'() {} *'bar'() {} *baz() {} }",
"class A { get 'foo'() {} get 'bar'() {} get baz() {} }",
"class A { 1() {} 2() {} }",
"class A { ['foo']() {} ['bar']() {} }",
"class A { [`foo`]() {} [`bar`]() {} }",
"class A { [12]() {} [123]() {} }",
"class A { [1.0]() {} ['1.0']() {} }",
"class A { [0x1]() {} [`0x1`]() {} }",
"class A { [null]() {} ['']() {} }",
"class A { get ['foo']() {} set ['foo'](value) {} }",
"class A { ['foo']() {} static ['foo']() {} }",
// computed "constructor" key doesn't create constructor
"class A { ['constructor']() {} constructor() {} }",
"class A { 'constructor'() {} [`constructor`]() {} }",
"class A { constructor() {} get [`constructor`]() {} }",
"class A { 'constructor'() {} set ['constructor'](value) {} }",
// not assumed to be statically-known values
"class A { ['foo' + '']() {} ['foo']() {} }",
"class A { [`foo${''}`]() {} [`foo`]() {} }",
"class A { [-1]() {} ['-1']() {} }",
// not supported by this rule
"class A { [foo]() {} [foo]() {} }",
// private and public
"class A { foo; static foo; }",
"class A { static foo() {}; foo() {}; }",
"class A { foo; #foo; }",
"class A { '#foo'; #foo; }",
// typescript-eslint
"class A { foo() {} bar() {} }",
"class A { static foo() {} foo() {} }",
"class A { get foo() {} set foo(value) {} }",
"class A { static foo() {} get foo() {} set foo(value) {} }",
"class A { foo() {} } class B { foo() {} }",
"class A { [foo]() {} foo() {} } ",
"class A { foo() {} bar() {} baz() {} }",
"class A { *foo() {} *bar() {} *baz() {} }",
"class A { get foo() {} get bar() {} get baz() {} }",
"class A { 1() {} 2() {} }",
"class Foo { foo(a: string): string; foo(a: number): number; foo(a: any): any {} }",
];
let fail = vec![
("class A { foo() {} foo() {} }", None),
("!class A { foo() {} foo() {} };", None),
("class A { 'foo'() {} 'foo'() {} }", None),
("class A { 10() {} 1e1() {} }", None),
("class A { ['foo']() {} ['foo']() {} }", None),
("class A { static ['foo']() {} static foo() {} }", None),
("class A { set 'foo'(value) {} set ['foo'](val) {} }", None),
("class A { ''() {} ['']() {} }", None),
("class A { [`foo`]() {} [`foo`]() {} }", None),
("class A { static get [`foo`]() {} static get ['foo']() {} }", None),
("class A { foo() {} [`foo`]() {} }", None),
("class A { get [`foo`]() {} 'foo'() {} }", None),
("class A { static 'foo'() {} static [`foo`]() {} }", None),
("class A { ['constructor']() {} ['constructor']() {} }", None),
("class A { static [`constructor`]() {} static constructor() {} }", None),
("class A { static constructor() {} static 'constructor'() {} }", None),
("class A { [123]() {} [123]() {} }", None),
("class A { [0x10]() {} 16() {} }", None),
("class A { [100]() {} [1e2]() {} }", None),
("class A { [123.00]() {} [`123`]() {} }", None),
("class A { static '65'() {} static [0o101]() {} }", None),
("class A { [123n]() {} 123() {} }", None),
("class A { [null]() {} 'null'() {} }", None),
("class A { foo() {} foo() {} foo() {} }", None),
("class A { static foo() {} static foo() {} }", None),
("class A { foo() {} get foo() {} }", None),
("class A { set foo(value) {} foo() {} }", None),
("class A { foo; foo; }", None),
("class A { get foo() {} set foo(val) {} get foo() {} }", None),
(
"class Foo {
foo(a: string): string;
foo(a: number): number;
foo(a: any): any {}
foo(b: string | number): any {}
}",
None,
),
"class A { foo() {} foo() {} }",
"!class A { foo() {} foo() {} };",
"class A { 'foo'() {} 'foo'() {} }",
"class A { 10() {} 1e1() {} }",
"class A { ['foo']() {} ['foo']() {} }",
"class A { static ['foo']() {} static foo() {} }",
"class A { set 'foo'(value) {} set ['foo'](val) {} }",
"class A { ''() {} ['']() {} }",
"class A { [`foo`]() {} [`foo`]() {} }",
"class A { static get [`foo`]() {} static get ['foo']() {} }",
"class A { foo() {} [`foo`]() {} }",
"class A { get [`foo`]() {} 'foo'() {} }",
"class A { static 'foo'() {} static [`foo`]() {} }",
"class A { ['constructor']() {} ['constructor']() {} }",
"class A { static [`constructor`]() {} static constructor() {} }",
"class A { static constructor() {} static 'constructor'() {} }",
"class A { [123]() {} [123]() {} }",
"class A { [0x10]() {} 16() {} }",
"class A { [100]() {} [1e2]() {} }",
"class A { [123.00]() {} [`123`]() {} }",
"class A { static '65'() {} static [0o101]() {} }",
"class A { [123n]() {} 123() {} }",
"class A { [null]() {} 'null'() {} }",
"class A { foo() {} foo() {} foo() {} }",
"class A { static foo() {} static foo() {} }",
"class A { foo() {} get foo() {} }",
"class A { set foo(value) {} foo() {} }",
"class A { foo; foo; }",
// typescript-eslint
"class A { foo() {} foo() {}}",
"!class A { foo() {} foo() {}};",
"class A { 'foo'() {} 'foo'() {}}",
"class A { 10() {} 1e1() {}}",
"class A { foo() {} foo() {} foo() {}}",
"class A { static foo() {} static foo() {}}",
"class A { foo() {} get foo() {}}",
"class A { set foo(value) {} foo() {}}",
"class A { foo; foo = 42;}",
"class A { foo; foo() {}}",
];
Tester::new(NoDupeClassMembers::NAME, pass, fail).test_and_snapshot();
Tester::new_without_config(NoDupeClassMembers::NAME, pass, fail).test_and_snapshot();
}

View file

@ -265,23 +265,100 @@ expression: no_dupe_class_members
⚠ eslint(no-dupe-class-members): Duplicate class member: "foo"
╭─[no_dupe_class_members.tsx:1:1]
1 │ class A { get foo() {} set foo(val) {} get foo() {} }
· ─┬─ ─┬─
· │ ╰── "foo" is re-declared here
1 │ class A { foo() {} foo() {}}
· ─┬─ ─┬─
· │ ╰── "foo" is re-declared here
· ╰── "foo" is previously declared here
╰────
help: The last declaration overwrites previous ones, remove one of them or rename if both should be retained
⚠ eslint(no-dupe-class-members): Duplicate class member: "foo"
╭─[no_dupe_class_members.tsx:1:1]
1 │ !class A { foo() {} foo() {}};
· ─┬─ ─┬─
· │ ╰── "foo" is re-declared here
· ╰── "foo" is previously declared here
╰────
help: The last declaration overwrites previous ones, remove one of them or rename if both should be retained
⚠ eslint(no-dupe-class-members): Duplicate class member: "foo"
╭─[no_dupe_class_members.tsx:1:1]
1 │ class A { 'foo'() {} 'foo'() {}}
· ──┬── ──┬──
· │ ╰── "foo" is re-declared here
· ╰── "foo" is previously declared here
╰────
help: The last declaration overwrites previous ones, remove one of them or rename if both should be retained
⚠ eslint(no-dupe-class-members): Duplicate class member: "10"
╭─[no_dupe_class_members.tsx:1:1]
1 │ class A { 10() {} 1e1() {}}
· ─┬ ─┬─
· │ ╰── "10" is re-declared here
· ╰── "10" is previously declared here
╰────
help: The last declaration overwrites previous ones, remove one of them or rename if both should be retained
⚠ eslint(no-dupe-class-members): Duplicate class member: "foo"
╭─[no_dupe_class_members.tsx:1:1]
1 │ class A { foo() {} foo() {} foo() {}}
· ─┬─ ─┬─
· │ ╰── "foo" is re-declared here
· ╰── "foo" is previously declared here
╰────
help: The last declaration overwrites previous ones, remove one of them or rename if both should be retained
⚠ eslint(no-dupe-class-members): Duplicate class member: "foo"
╭─[no_dupe_class_members.tsx:1:1]
1 │ class A { foo() {} foo() {} foo() {}}
· ─┬─ ─┬─
· │ ╰── "foo" is re-declared here
· ╰── "foo" is previously declared here
╰────
help: The last declaration overwrites previous ones, remove one of them or rename if both should be retained
⚠ eslint(no-dupe-class-members): Duplicate class member: "foo"
╭─[no_dupe_class_members.tsx:1:1]
1 │ class A { static foo() {} static foo() {}}
· ─┬─ ─┬─
· │ ╰── "foo" is re-declared here
· ╰── "foo" is previously declared here
╰────
help: The last declaration overwrites previous ones, remove one of them or rename if both should be retained
⚠ eslint(no-dupe-class-members): Duplicate class member: "foo"
╭─[no_dupe_class_members.tsx:1:1]
1 │ class A { foo() {} get foo() {}}
· ─┬─ ─┬─
· │ ╰── "foo" is re-declared here
· ╰── "foo" is previously declared here
╰────
help: The last declaration overwrites previous ones, remove one of them or rename if both should be retained
⚠ eslint(no-dupe-class-members): Duplicate class member: "foo"
╭─[no_dupe_class_members.tsx:1:1]
1 │ class A { set foo(value) {} foo() {}}
· ─┬─ ─┬─
· │ ╰── "foo" is re-declared here
· ╰── "foo" is previously declared here
╰────
help: The last declaration overwrites previous ones, remove one of them or rename if both should be retained
⚠ eslint(no-dupe-class-members): Duplicate class member: "foo"
╭─[no_dupe_class_members.tsx:3:1]
3 │ foo(a: number): number;
4 │ foo(a: any): any {}
· ─┬─
· ╰── "foo" is previously declared here
5 │ foo(b: string | number): any {}
· ─┬─
· ╰── "foo" is re-declared here
6 │ }
╭─[no_dupe_class_members.tsx:1:1]
1 │ class A { foo; foo = 42;}
· ─┬─ ─┬─
· │ ╰── "foo" is re-declared here
· ╰── "foo" is previously declared here
╰────
help: The last declaration overwrites previous ones, remove one of them or rename if both should be retained
⚠ eslint(no-dupe-class-members): Duplicate class member: "foo"
╭─[no_dupe_class_members.tsx:1:1]
1 │ class A { foo; foo() {}}
· ─┬─ ─┬─
· │ ╰── "foo" is re-declared here
· ╰── "foo" is previously declared here
╰────
help: The last declaration overwrites previous ones, remove one of them or rename if both should be retained