feat: add typescript-eslint rule array-type (#2292)

Ref: https://github.com/oxc-project/oxc/issues/2180
This commit is contained in:
luhc228 2024-02-06 11:35:29 +08:00 committed by GitHub
parent 839e7c5c22
commit 8771c6410f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 2219 additions and 0 deletions

View file

@ -100,6 +100,7 @@ mod eslint {
mod typescript {
pub mod adjacent_overload_signatures;
pub mod array_type;
pub mod ban_ts_comment;
pub mod ban_types;
pub mod no_duplicate_enum_values;
@ -389,6 +390,7 @@ oxc_macros::declare_all_lint_rules! {
eslint::use_isnan,
eslint::valid_typeof,
typescript::adjacent_overload_signatures,
typescript::array_type,
typescript::ban_ts_comment,
typescript::ban_types,
typescript::no_duplicate_enum_values,

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,569 @@
---
source: crates/oxc_linter/src/tester.rs
assertion_line: 150
expression: array_type
---
⚠ Array type using 'Array<number>' is forbidden. Use 'number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<number> = [];
· ─────────────
╰────
⚠ Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<string | number> = [];
· ──────────────────────
╰────
⚠ Array type using 'ReadonlyArray<number>' is forbidden. Use 'readonly number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<number> = [];
· ─────────────────────
╰────
⚠ Array type using 'ReadonlyArray<T>' is forbidden. Use 'readonly T[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<string | number> = [];
· ──────────────────────────────
╰────
⚠ Array type using 'Array<number>' is forbidden. Use 'number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<number> = [];
· ─────────────
╰────
⚠ Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<string | number> = [];
· ──────────────────────
╰────
⚠ Array type using 'ReadonlyArray<number>' is forbidden. Use 'readonly number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<number> = [];
· ─────────────────────
╰────
⚠ Array type using 'ReadonlyArray<T>' is forbidden. Use 'readonly T[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<string | number> = [];
· ──────────────────────────────
╰────
⚠ Array type using 'Array<number>' is forbidden. Use 'number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<number> = [];
· ─────────────
╰────
⚠ Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<string | number> = [];
· ──────────────────────
╰────
⚠ Array type using 'ReadonlyArray<number>' is forbidden for simple types. Use 'readonly number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<number> = [];
· ─────────────────────
╰────
⚠ Array type using 'readonly T[]' is forbidden for non-simple types. Use 'ReadonlyArray<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly (string | number)[] = [];
· ────────────────────────────
╰────
⚠ Array type using 'Array<number>' is forbidden. Use 'number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<number> = [];
· ─────────────
╰────
⚠ Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<string | number> = [];
· ──────────────────────
╰────
⚠ Array type using 'readonly number[]' is forbidden. Use 'ReadonlyArray<number>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly number[] = [];
· ─────────────────
╰────
⚠ Array type using 'readonly T[]' is forbidden. Use 'ReadonlyArray<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly (string | number)[] = [];
· ────────────────────────────
╰────
⚠ Array type using 'Array<number>' is forbidden for simple types. Use 'number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<number> = [];
· ─────────────
╰────
⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: (string | number)[] = [];
· ───────────────────
╰────
⚠ Array type using 'ReadonlyArray<number>' is forbidden for simple types. Use 'readonly number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<number> = [];
· ─────────────────────
╰────
⚠ Array type using 'readonly T[]' is forbidden for non-simple types. Use 'ReadonlyArray<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly (string | number)[] = [];
· ────────────────────────────
╰────
⚠ Array type using 'Array<number>' is forbidden for simple types. Use 'number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<number> = [];
· ─────────────
╰────
⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: (string | number)[] = [];
· ───────────────────
╰────
⚠ Array type using 'ReadonlyArray<number>' is forbidden. Use 'readonly number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<number> = [];
· ─────────────────────
╰────
⚠ Array type using 'ReadonlyArray<T>' is forbidden. Use 'readonly T[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<string | number> = [];
· ──────────────────────────────
╰────
⚠ Array type using 'Array<number>' is forbidden for simple types. Use 'number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<number> = [];
· ─────────────
╰────
⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: (string | number)[] = [];
· ───────────────────
╰────
⚠ Array type using 'ReadonlyArray<number>' is forbidden for simple types. Use 'readonly number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<number> = [];
· ─────────────────────
╰────
⚠ Array type using 'readonly T[]' is forbidden for non-simple types. Use 'ReadonlyArray<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly (string | number)[] = [];
· ────────────────────────────
╰────
⚠ Array type using 'Array<number>' is forbidden for simple types. Use 'number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: Array<number> = [];
· ─────────────
╰────
⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: (string | number)[] = [];
· ───────────────────
╰────
⚠ Array type using 'readonly number[]' is forbidden. Use 'ReadonlyArray<number>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly number[] = [];
· ─────────────────
╰────
⚠ Array type using 'readonly T[]' is forbidden. Use 'ReadonlyArray<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly (string | number)[] = [];
· ────────────────────────────
╰────
⚠ Array type using 'number[]' is forbidden. Use 'Array<number>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: number[] = [];
· ────────
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: (string | number)[] = [];
· ───────────────────
╰────
⚠ Array type using 'readonly number[]' is forbidden. Use 'ReadonlyArray<number>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly number[] = [];
· ─────────────────
╰────
⚠ Array type using 'readonly T[]' is forbidden. Use 'ReadonlyArray<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly (string | number)[] = [];
· ────────────────────────────
╰────
⚠ Array type using 'number[]' is forbidden. Use 'Array<number>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: number[] = [];
· ────────
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: (string | number)[] = [];
· ───────────────────
╰────
⚠ Array type using 'ReadonlyArray<number>' is forbidden. Use 'readonly number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<number> = [];
· ─────────────────────
╰────
⚠ Array type using 'ReadonlyArray<T>' is forbidden. Use 'readonly T[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<string | number> = [];
· ──────────────────────────────
╰────
⚠ Array type using 'number[]' is forbidden. Use 'Array<number>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: number[] = [];
· ────────
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: (string | number)[] = [];
· ───────────────────
╰────
⚠ Array type using 'ReadonlyArray<number>' is forbidden for simple types. Use 'readonly number[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<number> = [];
· ─────────────────────
╰────
⚠ Array type using 'readonly T[]' is forbidden for non-simple types. Use 'ReadonlyArray<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly (string | number)[] = [];
· ────────────────────────────
╰────
⚠ Array type using 'number[]' is forbidden. Use 'Array<number>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: number[] = [];
· ────────
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: (string | number)[] = [];
· ───────────────────
╰────
⚠ Array type using 'readonly number[]' is forbidden. Use 'ReadonlyArray<number>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly number[] = [];
· ─────────────────
╰────
⚠ Array type using 'readonly T[]' is forbidden. Use 'ReadonlyArray<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly (string | number)[] = [];
· ────────────────────────────
╰────
⚠ Array type using 'bigint[]' is forbidden. Use 'Array<bigint>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: bigint[] = [];
· ────────
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: (string | bigint)[] = [];
· ───────────────────
╰────
⚠ Array type using 'ReadonlyArray<bigint>' is forbidden for simple types. Use 'readonly bigint[]' instead.
╭─[array_type.tsx:1:8]
1 │ let a: ReadonlyArray<bigint> = [];
· ─────────────────────
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: (string | bigint)[] = [];
· ───────────────────
╰────
⚠ Array type using 'readonly bigint[]' is forbidden. Use 'ReadonlyArray<bigint>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly bigint[] = [];
· ─────────────────
╰────
⚠ Array type using 'readonly T[]' is forbidden. Use 'ReadonlyArray<T>' instead.
╭─[array_type.tsx:1:8]
1 │ let a: readonly (string | bigint)[] = [];
· ────────────────────────────
╰────
⚠ Array type using 'Array<Bar>' is forbidden. Use 'Bar[]' instead.
╭─[array_type.tsx:1:15]
1 │ let a: { foo: Array<Bar> }[] = [];
· ──────────
╰────
⚠ Array type using 'Bar[]' is forbidden. Use 'Array<Bar>' instead.
╭─[array_type.tsx:1:21]
1 │ let a: Array<{ foo: Bar[] }> = [];
· ─────
╰────
⚠ Array type using 'Array<Bar>' is forbidden. Use 'Bar[]' instead.
╭─[array_type.tsx:1:17]
1 │ function foo(a: Array<Bar>): Array<Bar> {}
· ──────────
╰────
⚠ Array type using 'Array<Bar>' is forbidden. Use 'Bar[]' instead.
╭─[array_type.tsx:1:30]
1 │ function foo(a: Array<Bar>): Array<Bar> {}
· ──────────
╰────
⚠ Array type using 'Array<undefined>' is forbidden for simple types. Use 'undefined[]' instead.
╭─[array_type.tsx:1:8]
1 │ let x: Array<undefined> = [undefined] as undefined[];
· ────────────────
╰────
× Expected `<` but found `EOF`
╭─[array_type.tsx:1:1]
1 │ let y: string[] = <Array<string>>['2'];
╰────
⚠ Array type using 'Array<any>' is forbidden for simple types. Use 'any[]' instead.
╭─[array_type.tsx:1:8]
1 │ let z: Array = [3, '4'];
· ─────
╰────
⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.
╭─[array_type.tsx:1:24]
1 │ let ya = [[1, '2']] as [number, string][];
· ──────────────────
╰────
⚠ Array type using 'Array<T>' is forbidden for simple types. Use 'T[]' instead.
╭─[array_type.tsx:1:15]
1 │ type Arr<T> = Array<T>;
· ────────
╰────
⚠ Array type using 'Array<T>' is forbidden for simple types. Use 'T[]' instead.
╭─[array_type.tsx:3:14]
2 │ interface ArrayClass<T> {
3 │ foo: Array<T>;
· ────────
4 │ bar: T[];
╰────
⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.
╭─[array_type.tsx:2:35]
1 │
2 │ function barFunction(bar: ArrayClass<String>[]) {
· ────────────────────
3 │ return bar.map(e => e.bar);
╰────
⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.
╭─[array_type.tsx:1:13]
1 │ let barVar: ((c: number) => number)[];
· ─────────────────────────
╰────
⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.
╭─[array_type.tsx:1:17]
1 │ type barUnion = (string | number | boolean)[];
· ─────────────────────────────
╰────
⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.
╭─[array_type.tsx:1:24]
1 │ type barIntersection = (string & number)[];
· ───────────────────
╰────
⚠ Array type using 'Array<undefined>' is forbidden. Use 'undefined[]' instead.
╭─[array_type.tsx:1:8]
1 │ let x: Array<undefined> = [undefined] as undefined[];
· ────────────────
╰────
× Expected `<` but found `EOF`
╭─[array_type.tsx:1:1]
1 │ let y: string[] = <Array<string>>['2'];
╰────
⚠ Array type using 'Array<any>' is forbidden. Use 'any[]' instead.
╭─[array_type.tsx:1:8]
1 │ let z: Array = [3, '4'];
· ─────
╰────
⚠ Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
╭─[array_type.tsx:1:15]
1 │ type Arr<T> = Array<T>;
· ────────
╰────
⚠ Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
╭─[array_type.tsx:3:14]
2 │ interface ArrayClass<T> {
3 │ foo: Array<T>;
· ────────
4 │ bar: T[];
╰────
⚠ Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
╭─[array_type.tsx:2:35]
1 │
2 │ function fooFunction(foo: Array<ArrayClass<string>>) {
· ─────────────────────────
3 │ return foo.map(e => e.foo);
╰────
⚠ Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
╭─[array_type.tsx:1:13]
1 │ let fooVar: Array<(c: number) => number>;
· ────────────────────────────
╰────
⚠ Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
╭─[array_type.tsx:1:17]
1 │ type fooUnion = Array<string | number | boolean>;
· ────────────────────────────────
╰────
⚠ Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
╭─[array_type.tsx:1:24]
1 │ type fooIntersection = Array<string & number>;
· ──────────────────────
╰────
⚠ Array type using 'Array<any>' is forbidden. Use 'any[]' instead.
╭─[array_type.tsx:1:8]
1 │ let x: Array;
· ─────
╰────
⚠ Array type using 'Array<any>' is forbidden. Use 'any[]' instead.
╭─[array_type.tsx:1:8]
1 │ let x: Array<>;
· ───────
╰────
⚠ Array type using 'Array<any>' is forbidden for simple types. Use 'any[]' instead.
╭─[array_type.tsx:1:8]
1 │ let x: Array;
· ─────
╰────
⚠ Array type using 'Array<any>' is forbidden for simple types. Use 'any[]' instead.
╭─[array_type.tsx:1:8]
1 │ let x: Array<>;
· ───────
╰────
⚠ Array type using 'number[]' is forbidden. Use 'Array<number>' instead.
╭─[array_type.tsx:1:31]
1 │ let x: Array<number> = [1] as number[];
· ────────
╰────
× Expected `<` but found `EOF`
╭─[array_type.tsx:1:1]
1 │ let y: string[] = <Array<string>>['2'];
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:1:24]
1 │ let ya = [[1, '2']] as [number, string][];
· ──────────────────
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:4:14]
3 │ foo: Array<T>;
4 │ bar: T[];
· ───
5 │ baz: Arr<T>;
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:2:35]
1 │
2 │ function barFunction(bar: ArrayClass<String>[]) {
· ────────────────────
3 │ return bar.map(e => e.bar);
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:1:13]
1 │ let barVar: ((c: number) => number)[];
· ─────────────────────────
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:1:17]
1 │ type barUnion = (string | number | boolean)[];
· ─────────────────────────────
╰────
⚠ Array type using 'T[]' is forbidden. Use 'Array<T>' instead.
╭─[array_type.tsx:1:24]
1 │ type barIntersection = (string & number)[];
· ───────────────────
╰────
⚠ Array type using 'string[]' is forbidden. Use 'Array<string>' instead.
╭─[array_type.tsx:3:24]
2 │ interface FooInterface {
3 │ '.bar': { baz: string[] };
· ────────
4 │ }
╰────
⚠ Array type using 'Array<T>' is forbidden. Use 'T[]' instead.
╭─[array_type.tsx:1:12]
1 │ const foo: Array<new (...args: any[]) => void> = [];
· ───────────────────────────────────
╰────
⚠ Array type using 'ReadonlyArray<T>' is forbidden. Use 'readonly T[]' instead.
╭─[array_type.tsx:1:12]
1 │ const foo: ReadonlyArray<new (...args: any[]) => void> = [];
· ───────────────────────────────────────────
╰────