From 9231031a6dcd1fd2a478ce705de0fc836412294a Mon Sep 17 00:00:00 2001 From: luhc228 Date: Tue, 6 Feb 2024 09:21:11 +0800 Subject: [PATCH] feat: add snapshot --- .../src/rules/typescript/array_type.rs | 2 +- .../oxc_linter/src/snapshots/array_type.snap | 569 ++++++++++++++++++ 2 files changed, 570 insertions(+), 1 deletion(-) create mode 100644 crates/oxc_linter/src/snapshots/array_type.snap diff --git a/crates/oxc_linter/src/rules/typescript/array_type.rs b/crates/oxc_linter/src/rules/typescript/array_type.rs index a093462f36634..df107489c04b1 100644 --- a/crates/oxc_linter/src/rules/typescript/array_type.rs +++ b/crates/oxc_linter/src/rules/typescript/array_type.rs @@ -875,5 +875,5 @@ fn test() { ("const foo: ReadonlyArray void> = [];", "const foo: readonly (new (...args: any[]) => void)[] = [];", Some(serde_json::json!([{"default":"array"}]))), ]; - Tester::new(ArrayType::NAME, pass, fail).expect_fix(fix).test(); + Tester::new(ArrayType::NAME, pass, fail).expect_fix(fix).test_and_snapshot(); } diff --git a/crates/oxc_linter/src/snapshots/array_type.snap b/crates/oxc_linter/src/snapshots/array_type.snap new file mode 100644 index 0000000000000..7e4d0d0e22c7a --- /dev/null +++ b/crates/oxc_linter/src/snapshots/array_type.snap @@ -0,0 +1,569 @@ +--- +source: crates/oxc_linter/src/tester.rs +assertion_line: 150 +expression: array_type +--- + + ⚠ Array type using 'Array' is forbidden. Use 'number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ───────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'T[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ────────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden. Use 'readonly number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ───────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden. Use 'readonly T[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ────────────────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ───────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'T[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ────────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden. Use 'readonly number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ───────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden. Use 'readonly T[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ────────────────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ───────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'T[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ────────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden for simple types. Use 'readonly number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ───────────────────── + ╰──── + + ⚠ Array type using 'readonly T[]' is forbidden for non-simple types. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly (string | number)[] = []; + · ──────────────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ───────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'T[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ────────────────────── + ╰──── + + ⚠ Array type using 'readonly number[]' is forbidden. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly number[] = []; + · ───────────────── + ╰──── + + ⚠ Array type using 'readonly T[]' is forbidden. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly (string | number)[] = []; + · ──────────────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden for simple types. Use 'number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ───────────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: (string | number)[] = []; + · ─────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden for simple types. Use 'readonly number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ───────────────────── + ╰──── + + ⚠ Array type using 'readonly T[]' is forbidden for non-simple types. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly (string | number)[] = []; + · ──────────────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden for simple types. Use 'number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ───────────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: (string | number)[] = []; + · ─────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden. Use 'readonly number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ───────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden. Use 'readonly T[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ────────────────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden for simple types. Use 'number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ───────────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: (string | number)[] = []; + · ─────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden for simple types. Use 'readonly number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ───────────────────── + ╰──── + + ⚠ Array type using 'readonly T[]' is forbidden for non-simple types. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly (string | number)[] = []; + · ──────────────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden for simple types. Use 'number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: Array = []; + · ───────────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: (string | number)[] = []; + · ─────────────────── + ╰──── + + ⚠ Array type using 'readonly number[]' is forbidden. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly number[] = []; + · ───────────────── + ╰──── + + ⚠ Array type using 'readonly T[]' is forbidden. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly (string | number)[] = []; + · ──────────────────────────── + ╰──── + + ⚠ Array type using 'number[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: number[] = []; + · ──────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: (string | number)[] = []; + · ─────────────────── + ╰──── + + ⚠ Array type using 'readonly number[]' is forbidden. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly number[] = []; + · ───────────────── + ╰──── + + ⚠ Array type using 'readonly T[]' is forbidden. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly (string | number)[] = []; + · ──────────────────────────── + ╰──── + + ⚠ Array type using 'number[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: number[] = []; + · ──────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: (string | number)[] = []; + · ─────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden. Use 'readonly number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ───────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden. Use 'readonly T[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ────────────────────────────── + ╰──── + + ⚠ Array type using 'number[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: number[] = []; + · ──────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: (string | number)[] = []; + · ─────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden for simple types. Use 'readonly number[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ───────────────────── + ╰──── + + ⚠ Array type using 'readonly T[]' is forbidden for non-simple types. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly (string | number)[] = []; + · ──────────────────────────── + ╰──── + + ⚠ Array type using 'number[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: number[] = []; + · ──────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: (string | number)[] = []; + · ─────────────────── + ╰──── + + ⚠ Array type using 'readonly number[]' is forbidden. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly number[] = []; + · ───────────────── + ╰──── + + ⚠ Array type using 'readonly T[]' is forbidden. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly (string | number)[] = []; + · ──────────────────────────── + ╰──── + + ⚠ Array type using 'bigint[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: bigint[] = []; + · ──────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: (string | bigint)[] = []; + · ─────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden for simple types. Use 'readonly bigint[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: ReadonlyArray = []; + · ───────────────────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: (string | bigint)[] = []; + · ─────────────────── + ╰──── + + ⚠ Array type using 'readonly bigint[]' is forbidden. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly bigint[] = []; + · ───────────────── + ╰──── + + ⚠ Array type using 'readonly T[]' is forbidden. Use 'ReadonlyArray' instead. + ╭─[array_type.tsx:1:8] + 1 │ let a: readonly (string | bigint)[] = []; + · ──────────────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'Bar[]' instead. + ╭─[array_type.tsx:1:15] + 1 │ let a: { foo: Array }[] = []; + · ────────── + ╰──── + + ⚠ Array type using 'Bar[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:21] + 1 │ let a: Array<{ foo: Bar[] }> = []; + · ───── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'Bar[]' instead. + ╭─[array_type.tsx:1:17] + 1 │ function foo(a: Array): Array {} + · ────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'Bar[]' instead. + ╭─[array_type.tsx:1:30] + 1 │ function foo(a: Array): Array {} + · ────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden for simple types. Use 'undefined[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let x: Array = [undefined] as undefined[]; + · ──────────────── + ╰──── + + × Expected `<` but found `EOF` + ╭─[array_type.tsx:1:1] + 1 │ let y: string[] = >['2']; + ╰──── + + ⚠ Array type using 'Array' 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' instead. + ╭─[array_type.tsx:1:24] + 1 │ let ya = [[1, '2']] as [number, string][]; + · ────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden for simple types. Use 'T[]' instead. + ╭─[array_type.tsx:1:15] + 1 │ type Arr = Array; + · ──────── + ╰──── + + ⚠ Array type using 'Array' is forbidden for simple types. Use 'T[]' instead. + ╭─[array_type.tsx:3:14] + 2 │ interface ArrayClass { + 3 │ foo: Array; + · ──────── + 4 │ bar: T[]; + ╰──── + + ⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead. + ╭─[array_type.tsx:2:35] + 1 │ + 2 │ function barFunction(bar: ArrayClass[]) { + · ──────────────────── + 3 │ return bar.map(e => e.bar); + ╰──── + + ⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead. + ╭─[array_type.tsx:1:13] + 1 │ let barVar: ((c: number) => number)[]; + · ───────────────────────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead. + ╭─[array_type.tsx:1:17] + 1 │ type barUnion = (string | number | boolean)[]; + · ───────────────────────────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead. + ╭─[array_type.tsx:1:24] + 1 │ type barIntersection = (string & number)[]; + · ─────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'undefined[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let x: Array = [undefined] as undefined[]; + · ──────────────── + ╰──── + + × Expected `<` but found `EOF` + ╭─[array_type.tsx:1:1] + 1 │ let y: string[] = >['2']; + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'any[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let z: Array = [3, '4']; + · ───── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'T[]' instead. + ╭─[array_type.tsx:1:15] + 1 │ type Arr = Array; + · ──────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'T[]' instead. + ╭─[array_type.tsx:3:14] + 2 │ interface ArrayClass { + 3 │ foo: Array; + · ──────── + 4 │ bar: T[]; + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'T[]' instead. + ╭─[array_type.tsx:2:35] + 1 │ + 2 │ function fooFunction(foo: Array>) { + · ───────────────────────── + 3 │ return foo.map(e => e.foo); + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'T[]' instead. + ╭─[array_type.tsx:1:13] + 1 │ let fooVar: Array<(c: number) => number>; + · ──────────────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'T[]' instead. + ╭─[array_type.tsx:1:17] + 1 │ type fooUnion = Array; + · ──────────────────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'T[]' instead. + ╭─[array_type.tsx:1:24] + 1 │ type fooIntersection = Array; + · ────────────────────── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'any[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let x: Array; + · ───── + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'any[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let x: Array<>; + · ─────── + ╰──── + + ⚠ Array type using 'Array' is forbidden for simple types. Use 'any[]' instead. + ╭─[array_type.tsx:1:8] + 1 │ let x: Array; + · ───── + ╰──── + + ⚠ Array type using 'Array' 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' instead. + ╭─[array_type.tsx:1:31] + 1 │ let x: Array = [1] as number[]; + · ──────── + ╰──── + + × Expected `<` but found `EOF` + ╭─[array_type.tsx:1:1] + 1 │ let y: string[] = >['2']; + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:24] + 1 │ let ya = [[1, '2']] as [number, string][]; + · ────────────────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:4:14] + 3 │ foo: Array; + 4 │ bar: T[]; + · ─── + 5 │ baz: Arr; + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:2:35] + 1 │ + 2 │ function barFunction(bar: ArrayClass[]) { + · ──────────────────── + 3 │ return bar.map(e => e.bar); + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:13] + 1 │ let barVar: ((c: number) => number)[]; + · ───────────────────────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:17] + 1 │ type barUnion = (string | number | boolean)[]; + · ───────────────────────────── + ╰──── + + ⚠ Array type using 'T[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:1:24] + 1 │ type barIntersection = (string & number)[]; + · ─────────────────── + ╰──── + + ⚠ Array type using 'string[]' is forbidden. Use 'Array' instead. + ╭─[array_type.tsx:3:24] + 2 │ interface FooInterface { + 3 │ '.bar': { baz: string[] }; + · ──────── + 4 │ } + ╰──── + + ⚠ Array type using 'Array' is forbidden. Use 'T[]' instead. + ╭─[array_type.tsx:1:12] + 1 │ const foo: Array void> = []; + · ─────────────────────────────────── + ╰──── + + ⚠ Array type using 'ReadonlyArray' is forbidden. Use 'readonly T[]' instead. + ╭─[array_type.tsx:1:12] + 1 │ const foo: ReadonlyArray void> = []; + · ─────────────────────────────────────────── + ╰──── +