From 1864644ea0cebf9ea83e717e2d8daa997adc91e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Thu, 21 Mar 2024 00:17:38 +0900 Subject: [PATCH 01/13] feat: add new type --- .../eslint-plugin/src/rules/array-type.ts | 24 +- .../tests/rules/array-type.test.ts | 4280 +++++++++-------- 2 files changed, 2164 insertions(+), 2140 deletions(-) diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index fc8d5f32f80a..4da45554bfcc 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -82,7 +82,8 @@ type MessageIds = | 'errorStringArray' | 'errorStringArraySimple' | 'errorStringGeneric' - | 'errorStringGenericSimple'; + | 'errorStringGenericSimple' + | 'errorStringArrayReadonly'; export default createRule({ name: 'array-type', @@ -99,6 +100,8 @@ export default createRule({ "Array type using '{{readonlyPrefix}}{{type}}[]' is forbidden. Use '{{className}}<{{type}}>' instead.", errorStringArray: "Array type using '{{className}}<{{type}}>' is forbidden. Use '{{readonlyPrefix}}{{type}}[]' instead.", + errorStringArrayReadonly: + "Array type using '{{className}}<{{type}}>' is forbidden. Use '{{readonlyPrefix}}{{type}}' instead.", errorStringArraySimple: "Array type using '{{className}}<{{type}}>' is forbidden for simple types. Use '{{readonlyPrefix}}{{type}}[]' instead.", errorStringGenericSimple: @@ -199,13 +202,20 @@ export default createRule({ node.typeName.type !== AST_NODE_TYPES.Identifier || !( node.typeName.name === 'Array' || - node.typeName.name === 'ReadonlyArray' + node.typeName.name === 'ReadonlyArray' || + node.typeName.name === 'Readonly' ) ) { return; } - const isReadonlyArrayType = node.typeName.name === 'ReadonlyArray'; + const isReadonlyWithGenericArrayType = + node.typeName.name === 'Readonly' && + node.typeArguments?.params[0].type === AST_NODE_TYPES.TSArrayType; + const isReadonlyArrayType = + node.typeName.name === 'ReadonlyArray' || + isReadonlyWithGenericArrayType; + const currentOption = isReadonlyArrayType ? readonlyOption : defaultOption; @@ -218,7 +228,9 @@ export default createRule({ const typeParams = node.typeArguments?.params; const messageId = currentOption === 'array' - ? 'errorStringArray' + ? isReadonlyWithGenericArrayType + ? 'errorStringArrayReadonly' + : 'errorStringArray' : 'errorStringArraySimple'; if (!typeParams || typeParams.length === 0) { @@ -256,13 +268,13 @@ export default createRule({ const start = `${parentParens ? '(' : ''}${readonlyPrefix}${ typeParens ? '(' : '' }`; - const end = `${typeParens ? ')' : ''}[]${parentParens ? ')' : ''}`; + const end = `${typeParens ? ')' : ''}${isReadonlyWithGenericArrayType ? '' : `[]`}${parentParens ? ')' : ''}`; context.report({ node, messageId, data: { - className: isReadonlyArrayType ? 'ReadonlyArray' : 'Array', + className: isReadonlyArrayType ? node.typeName.name : 'Array', readonlyPrefix, type: getMessageType(type), }, diff --git a/packages/eslint-plugin/tests/rules/array-type.test.ts b/packages/eslint-plugin/tests/rules/array-type.test.ts index 44be83ff63db..21b1ed92f9f4 100644 --- a/packages/eslint-plugin/tests/rules/array-type.test.ts +++ b/packages/eslint-plugin/tests/rules/array-type.test.ts @@ -13,2163 +13,2175 @@ const ruleTester = new RuleTester({ ruleTester.run('array-type', rule, { valid: [ // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly bigint[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly (string | bigint)[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: readonly bigint[] = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // // End of base cases + // { + // code: 'let a = new Array();', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let a: { foo: Bar[] }[] = [];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'function foo(a: Array): Array {}', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let yy: number[][] = [[4, 5], [6]];', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: ` + // function fooFunction(foo: Array>) { + // return foo.map(e => e.foo); + // } + // `, + // options: [{ default: 'array-simple' }], + // }, + // { + // code: ` + // function bazFunction(baz: Arr>) { + // return baz.map(e => e.baz); + // } + // `, + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let fooVar: Array<(c: number) => number>;', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'type fooUnion = Array;', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'type fooIntersection = Array;', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: ` + // namespace fooName { + // type BarType = { bar: string }; + // type BazType = Arr; + // } + // `, + // options: [{ default: 'array-simple' }], + // }, + // { + // code: ` + // interface FooInterface { + // '.bar': { baz: string[] }; + // } + // `, + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let yy: number[][] = [[4, 5], [6]];', + // options: [{ default: 'array' }], + // }, + // { + // code: "let ya = [[1, '2']] as [number, string][];", + // options: [{ default: 'array' }], + // }, + // { + // code: ` + // function barFunction(bar: ArrayClass[]) { + // return bar.map(e => e.bar); + // } + // `, + // options: [{ default: 'array' }], + // }, + // { + // code: ` + // function bazFunction(baz: Arr>) { + // return baz.map(e => e.baz); + // } + // `, + // options: [{ default: 'array' }], + // }, + // { + // code: 'let barVar: ((c: number) => number)[];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'type barUnion = (string | number | boolean)[];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'type barIntersection = (string & number)[];', + // options: [{ default: 'array' }], + // }, + // { + // code: ` + // interface FooInterface { + // '.bar': { baz: string[] }; + // } + // `, + // options: [{ default: 'array' }], + // }, + // { + // // https://github.com/typescript-eslint/typescript-eslint/issues/172 + // code: 'type Unwrap = T extends (infer E)[] ? E : T;', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let xx: Array> = [[1, 2], [3]];', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'type Arr = Array;', + // options: [{ default: 'generic' }], + // }, + // { + // code: ` + // function fooFunction(foo: Array>) { + // return foo.map(e => e.foo); + // } + // `, + // options: [{ default: 'generic' }], + // }, + // { + // code: ` + // function bazFunction(baz: Arr>) { + // return baz.map(e => e.baz); + // } + // `, + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let fooVar: Array<(c: number) => number>;', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'type fooUnion = Array;', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'type fooIntersection = Array;', + // options: [{ default: 'generic' }], + // }, + // { + // // https://github.com/typescript-eslint/typescript-eslint/issues/172 + // code: 'type Unwrap = T extends Array ? E : T;', + // options: [{ default: 'generic' }], + // }, + // // nested readonly + // { + // code: 'let a: ReadonlyArray = [[]];', + // options: [{ default: 'array', readonly: 'generic' }], + // }, + // { + // code: 'let a: readonly Array[] = [[]];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + ], + invalid: [ + // // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 { - code: 'let a: number[] = [];', - options: [{ default: 'array' }], - }, - { - code: 'let a: (string | number)[] = [];', - options: [{ default: 'array' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array' }], - }, - { - code: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'array' }], - }, - { - code: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array', readonly: 'array' }], - }, - { - code: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - }, - { - code: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'generic' }], - }, - { - code: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'generic' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array-simple' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'array-simple' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - }, - { - code: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: readonly bigint[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: readonly (string | bigint)[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: readonly bigint[] = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - - // End of base cases - - { - code: 'let a = new Array();', - options: [{ default: 'array' }], - }, - { - code: 'let a: { foo: Bar[] }[] = [];', - options: [{ default: 'array' }], - }, - { - code: 'function foo(a: Array): Array {}', - options: [{ default: 'generic' }], - }, - { - code: 'let yy: number[][] = [[4, 5], [6]];', - options: [{ default: 'array-simple' }], - }, - { - code: ` -function fooFunction(foo: Array>) { - return foo.map(e => e.foo); -} - `, - options: [{ default: 'array-simple' }], - }, - { - code: ` -function bazFunction(baz: Arr>) { - return baz.map(e => e.baz); -} - `, - options: [{ default: 'array-simple' }], - }, - { - code: 'let fooVar: Array<(c: number) => number>;', - options: [{ default: 'array-simple' }], - }, - { - code: 'type fooUnion = Array;', - options: [{ default: 'array-simple' }], - }, - { - code: 'type fooIntersection = Array;', - options: [{ default: 'array-simple' }], - }, - { - code: ` -namespace fooName { - type BarType = { bar: string }; - type BazType = Arr; -} - `, - options: [{ default: 'array-simple' }], - }, - { - code: ` -interface FooInterface { - '.bar': { baz: string[] }; -} - `, - options: [{ default: 'array-simple' }], - }, - { - code: 'let yy: number[][] = [[4, 5], [6]];', - options: [{ default: 'array' }], - }, - { - code: "let ya = [[1, '2']] as [number, string][];", - options: [{ default: 'array' }], - }, - { - code: ` -function barFunction(bar: ArrayClass[]) { - return bar.map(e => e.bar); -} - `, - options: [{ default: 'array' }], - }, - { - code: ` -function bazFunction(baz: Arr>) { - return baz.map(e => e.baz); -} - `, - options: [{ default: 'array' }], - }, - { - code: 'let barVar: ((c: number) => number)[];', - options: [{ default: 'array' }], - }, - { - code: 'type barUnion = (string | number | boolean)[];', - options: [{ default: 'array' }], - }, - { - code: 'type barIntersection = (string & number)[];', - options: [{ default: 'array' }], - }, - { - code: ` -interface FooInterface { - '.bar': { baz: string[] }; -} - `, - options: [{ default: 'array' }], - }, - { - // https://github.com/typescript-eslint/typescript-eslint/issues/172 - code: 'type Unwrap = T extends (infer E)[] ? E : T;', - options: [{ default: 'array' }], - }, - { - code: 'let xx: Array> = [[1, 2], [3]];', - options: [{ default: 'generic' }], - }, - { - code: 'type Arr = Array;', - options: [{ default: 'generic' }], - }, - { - code: ` -function fooFunction(foo: Array>) { - return foo.map(e => e.foo); -} - `, - options: [{ default: 'generic' }], - }, - { - code: ` -function bazFunction(baz: Arr>) { - return baz.map(e => e.baz); -} - `, - options: [{ default: 'generic' }], - }, - { - code: 'let fooVar: Array<(c: number) => number>;', - options: [{ default: 'generic' }], - }, - { - code: 'type fooUnion = Array;', - options: [{ default: 'generic' }], - }, - { - code: 'type fooIntersection = Array;', - options: [{ default: 'generic' }], - }, - { - // https://github.com/typescript-eslint/typescript-eslint/issues/172 - code: 'type Unwrap = T extends Array ? E : T;', - options: [{ default: 'generic' }], - }, - - // nested readonly - { - code: 'let a: ReadonlyArray = [[]];', - options: [{ default: 'array', readonly: 'generic' }], - }, - { - code: 'let a: readonly Array[] = [[]];', - options: [{ default: 'generic', readonly: 'array' }], - }, - ], - invalid: [ - // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: (string | number)[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly number[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly number[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: number[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly number[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: number[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: number[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: number[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly number[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: bigint[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'bigint' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | bigint)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly bigint[] = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'bigint', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | bigint)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly bigint[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'bigint', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | bigint)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - - // End of base cases - - { - code: 'let a: { foo: Array }[] = [];', - output: 'let a: { foo: Bar[] }[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - line: 1, - column: 15, - }, - ], - }, - { - code: 'let a: Array<{ foo: Bar[] }> = [];', - output: 'let a: Array<{ foo: Array }> = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - line: 1, - column: 21, - }, - ], - }, - { - code: 'let a: Array<{ foo: Foo | Bar[] }> = [];', - output: 'let a: Array<{ foo: Foo | Array }> = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - line: 1, - column: 27, - }, - ], - }, - { - code: 'function foo(a: Array): Array {}', - output: 'function foo(a: Bar[]): Bar[] {}', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - line: 1, - column: 17, - }, - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - line: 1, - column: 30, - }, - ], - }, - { - code: 'let x: Array = [undefined] as undefined[];', - output: 'let x: undefined[] = [undefined] as undefined[];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, - line: 1, - column: 8, - }, - ], - }, - { - code: "let y: string[] = >['2'];", - output: "let y: string[] = ['2'];", - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - line: 1, - column: 20, - }, - ], - }, - { - code: "let z: Array = [3, '4'];", - output: "let z: any[] = [3, '4'];", - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - line: 1, - column: 8, - }, - ], - }, - { - code: "let ya = [[1, '2']] as [number, string][];", - output: "let ya = [[1, '2']] as Array<[number, string]>;", - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 24, - }, - ], - }, - { - code: 'type Arr = Array;', - output: 'type Arr = T[];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 15, - }, - ], - }, - { - code: ` -// Ignore user defined aliases -let yyyy: Arr>[]> = [[[['2']]]]; - `, - output: ` -// Ignore user defined aliases -let yyyy: Arr>>> = [[[['2']]]]; - `, - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 3, - column: 15, - }, - ], - }, - { - code: ` -interface ArrayClass { - foo: Array; - bar: T[]; - baz: Arr; - xyz: this[]; -} - `, - output: ` -interface ArrayClass { - foo: T[]; - bar: T[]; - baz: Arr; - xyz: this[]; -} - `, - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 3, - column: 8, - }, - ], - }, - { - code: ` -function barFunction(bar: ArrayClass[]) { - return bar.map(e => e.bar); -} - `, - output: ` -function barFunction(bar: Array>) { - return bar.map(e => e.bar); -} - `, - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 2, - column: 27, - }, - ], - }, - { - code: 'let barVar: ((c: number) => number)[];', - output: 'let barVar: Array<(c: number) => number>;', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 13, - }, - ], - }, - { - code: 'type barUnion = (string | number | boolean)[];', - output: 'type barUnion = Array;', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 17, - }, - ], - }, - { - code: 'type barIntersection = (string & number)[];', - output: 'type barIntersection = Array;', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 24, - }, - ], - }, - { - code: "let v: Array = [{ bar: 'bar' }];", - output: "let v: fooName.BarType[] = [{ bar: 'bar' }];", - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'Array', - readonlyPrefix: '', - type: 'fooName.BarType', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: "let w: fooName.BazType[] = [['baz']];", - output: "let w: Array> = [['baz']];", - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let x: Array = [undefined] as undefined[];', - output: 'let x: undefined[] = [undefined] as undefined[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, - line: 1, - column: 8, - }, - ], - }, - { - code: "let y: string[] = >['2'];", - output: "let y: string[] = ['2'];", - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - line: 1, - column: 20, - }, - ], - }, - { - code: "let z: Array = [3, '4'];", - output: "let z: any[] = [3, '4'];", - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'type Arr = Array;', - output: 'type Arr = T[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 15, - }, - ], - }, - { - code: ` -// Ignore user defined aliases -let yyyy: Arr>[]> = [[[['2']]]]; - `, - output: ` -// Ignore user defined aliases -let yyyy: Arr[][]> = [[[['2']]]]; - `, - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 3, - column: 15, - }, - ], - }, - { - code: ` -interface ArrayClass { - foo: Array; - bar: T[]; - baz: Arr; -} - `, - output: ` -interface ArrayClass { - foo: T[]; - bar: T[]; - baz: Arr; -} - `, - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 3, - column: 8, - }, - ], - }, - { - code: ` -function fooFunction(foo: Array>) { - return foo.map(e => e.foo); -} - `, - output: ` -function fooFunction(foo: ArrayClass[]) { - return foo.map(e => e.foo); -} - `, - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 2, - column: 27, - }, - ], - }, - { - code: 'let fooVar: Array<(c: number) => number>;', - output: 'let fooVar: ((c: number) => number)[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 13, - }, - ], - }, - { - code: 'type fooUnion = Array;', - output: 'type fooUnion = (string | number | boolean)[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 17, - }, - ], - }, - { - code: 'type fooIntersection = Array;', - output: 'type fooIntersection = (string & number)[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 24, - }, - ], - }, - { - code: 'let x: Array;', - output: 'let x: any[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let x: Array<>;', - output: 'let x: any[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let x: Array;', - output: 'let x: any[];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let x: Array<>;', - output: 'let x: any[];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - line: 1, - column: 8, - }, - ], - }, - { - code: 'let x: Array = [1] as number[];', - output: 'let x: Array = [1] as Array;', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 31, - }, - ], - }, - { - code: "let y: string[] = >['2'];", - output: "let y: Array = >['2'];", - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - line: 1, - column: 8, - }, - ], - }, - { - code: "let ya = [[1, '2']] as [number, string][];", - output: "let ya = [[1, '2']] as Array<[number, string]>;", - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 24, - }, - ], - }, - { - code: ` -// Ignore user defined aliases -let yyyy: Arr>[]> = [[[['2']]]]; - `, - output: ` -// Ignore user defined aliases -let yyyy: Arr>>> = [[[['2']]]]; - `, - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 3, - column: 15, - }, - ], - }, - { - code: ` -interface ArrayClass { - foo: Array; - bar: T[]; - baz: Arr; -} - `, - output: ` -interface ArrayClass { - foo: Array; - bar: Array; - baz: Arr; -} - `, - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 4, - column: 8, - }, - ], - }, - { - code: ` -function barFunction(bar: ArrayClass[]) { - return bar.map(e => e.bar); -} - `, - output: ` -function barFunction(bar: Array>) { - return bar.map(e => e.bar); -} - `, - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 2, - column: 27, - }, - ], - }, - { - code: 'let barVar: ((c: number) => number)[];', - output: 'let barVar: Array<(c: number) => number>;', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 13, - }, - ], - }, - { - code: 'type barUnion = (string | number | boolean)[];', - output: 'type barUnion = Array;', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 17, - }, - ], - }, - { - code: 'type barIntersection = (string & number)[];', - output: 'type barIntersection = Array;', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 24, - }, - ], - }, - { - code: ` -interface FooInterface { - '.bar': { baz: string[] }; -} - `, - output: ` -interface FooInterface { - '.bar': { baz: Array }; -} - `, - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - line: 3, - column: 18, - }, - ], - }, - { - // https://github.com/typescript-eslint/typescript-eslint/issues/172 - code: 'type Unwrap = T extends Array ? E : T;', - output: 'type Unwrap = T extends (infer E)[] ? E : T;', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 28, - }, - ], - }, - { - // https://github.com/typescript-eslint/typescript-eslint/issues/172 - code: 'type Unwrap = T extends (infer E)[] ? E : T;', - output: 'type Unwrap = T extends Array ? E : T;', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 28, - }, - ], - }, - { - code: 'type Foo = ReadonlyArray[];', - output: 'type Foo = (readonly object[])[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'object', - }, - line: 1, - column: 12, - }, - ], - }, - { - code: 'const foo: Array void> = [];', - output: 'const foo: (new (...args: any[]) => void)[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 12, - }, - ], - }, - { - code: 'const foo: ReadonlyArray void> = [];', - output: 'const foo: readonly (new (...args: any[]) => void)[] = [];', + code: "const x: Readonly = ['a', 'b'];", + output: "const x: readonly string[] = ['a', 'b'];", options: [{ default: 'array' }], errors: [ { - messageId: 'errorStringArray', + messageId: 'errorStringArrayReadonly', data: { - className: 'ReadonlyArray', + className: 'Readonly', readonlyPrefix: 'readonly ', - type: 'T', + type: 'string[]', }, - line: 1, - column: 12, }, ], }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: (string | number)[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly number[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly number[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: number[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly number[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: number[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: number[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: number[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly number[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: bigint[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'bigint' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | bigint)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly bigint[] = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'bigint', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | bigint)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly bigint[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'bigint', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | bigint)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + + // // End of base cases + + // { + // code: 'let a: { foo: Array }[] = [];', + // output: 'let a: { foo: Bar[] }[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + // line: 1, + // column: 15, + // }, + // ], + // }, + // { + // code: 'let a: Array<{ foo: Bar[] }> = [];', + // output: 'let a: Array<{ foo: Array }> = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + // line: 1, + // column: 21, + // }, + // ], + // }, + // { + // code: 'let a: Array<{ foo: Foo | Bar[] }> = [];', + // output: 'let a: Array<{ foo: Foo | Array }> = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + // line: 1, + // column: 27, + // }, + // ], + // }, + // { + // code: 'function foo(a: Array): Array {}', + // output: 'function foo(a: Bar[]): Bar[] {}', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + // line: 1, + // column: 17, + // }, + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + // line: 1, + // column: 30, + // }, + // ], + // }, + // { + // code: 'let x: Array = [undefined] as undefined[];', + // output: 'let x: undefined[] = [undefined] as undefined[];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: "let y: string[] = >['2'];", + // output: "let y: string[] = ['2'];", + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + // line: 1, + // column: 20, + // }, + // ], + // }, + // { + // code: "let z: Array = [3, '4'];", + // output: "let z: any[] = [3, '4'];", + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: "let ya = [[1, '2']] as [number, string][];", + // output: "let ya = [[1, '2']] as Array<[number, string]>;", + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 24, + // }, + // ], + // }, + // { + // code: 'type Arr = Array;', + // output: 'type Arr = T[];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 15, + // }, + // ], + // }, + // { + // code: ` + // // Ignore user defined aliases + // let yyyy: Arr>[]> = [[[['2']]]]; + // `, + // output: ` + // // Ignore user defined aliases + // let yyyy: Arr>>> = [[[['2']]]]; + // `, + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 3, + // column: 15, + // }, + // ], + // }, + // { + // code: ` + // interface ArrayClass { + // foo: Array; + // bar: T[]; + // baz: Arr; + // xyz: this[]; + // } + // `, + // output: ` + // interface ArrayClass { + // foo: T[]; + // bar: T[]; + // baz: Arr; + // xyz: this[]; + // } + // `, + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 3, + // column: 8, + // }, + // ], + // }, + // { + // code: ` + // function barFunction(bar: ArrayClass[]) { + // return bar.map(e => e.bar); + // } + // `, + // output: ` + // function barFunction(bar: Array>) { + // return bar.map(e => e.bar); + // } + // `, + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 2, + // column: 27, + // }, + // ], + // }, + // { + // code: 'let barVar: ((c: number) => number)[];', + // output: 'let barVar: Array<(c: number) => number>;', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 13, + // }, + // ], + // }, + // { + // code: 'type barUnion = (string | number | boolean)[];', + // output: 'type barUnion = Array;', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 17, + // }, + // ], + // }, + // { + // code: 'type barIntersection = (string & number)[];', + // output: 'type barIntersection = Array;', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 24, + // }, + // ], + // }, + // { + // code: "let v: Array = [{ bar: 'bar' }];", + // output: "let v: fooName.BarType[] = [{ bar: 'bar' }];", + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'Array', + // readonlyPrefix: '', + // type: 'fooName.BarType', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: "let w: fooName.BazType[] = [['baz']];", + // output: "let w: Array> = [['baz']];", + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let x: Array = [undefined] as undefined[];', + // output: 'let x: undefined[] = [undefined] as undefined[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: "let y: string[] = >['2'];", + // output: "let y: string[] = ['2'];", + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + // line: 1, + // column: 20, + // }, + // ], + // }, + // { + // code: "let z: Array = [3, '4'];", + // output: "let z: any[] = [3, '4'];", + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'type Arr = Array;', + // output: 'type Arr = T[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 15, + // }, + // ], + // }, + // { + // code: ` + // // Ignore user defined aliases + // let yyyy: Arr>[]> = [[[['2']]]]; + // `, + // output: ` + // // Ignore user defined aliases + // let yyyy: Arr[][]> = [[[['2']]]]; + // `, + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 3, + // column: 15, + // }, + // ], + // }, + // { + // code: ` + // interface ArrayClass { + // foo: Array; + // bar: T[]; + // baz: Arr; + // } + // `, + // output: ` + // interface ArrayClass { + // foo: T[]; + // bar: T[]; + // baz: Arr; + // } + // `, + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 3, + // column: 8, + // }, + // ], + // }, + // { + // code: ` + // function fooFunction(foo: Array>) { + // return foo.map(e => e.foo); + // } + // `, + // output: ` + // function fooFunction(foo: ArrayClass[]) { + // return foo.map(e => e.foo); + // } + // `, + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 2, + // column: 27, + // }, + // ], + // }, + // { + // code: 'let fooVar: Array<(c: number) => number>;', + // output: 'let fooVar: ((c: number) => number)[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 13, + // }, + // ], + // }, + // { + // code: 'type fooUnion = Array;', + // output: 'type fooUnion = (string | number | boolean)[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 17, + // }, + // ], + // }, + // { + // code: 'type fooIntersection = Array;', + // output: 'type fooIntersection = (string & number)[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 24, + // }, + // ], + // }, + // { + // code: 'let x: Array;', + // output: 'let x: any[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let x: Array<>;', + // output: 'let x: any[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let x: Array;', + // output: 'let x: any[];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let x: Array<>;', + // output: 'let x: any[];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let x: Array = [1] as number[];', + // output: 'let x: Array = [1] as Array;', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 31, + // }, + // ], + // }, + // { + // code: "let y: string[] = >['2'];", + // output: "let y: Array = >['2'];", + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: "let ya = [[1, '2']] as [number, string][];", + // output: "let ya = [[1, '2']] as Array<[number, string]>;", + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 24, + // }, + // ], + // }, + // { + // code: ` + // // Ignore user defined aliases + // let yyyy: Arr>[]> = [[[['2']]]]; + // `, + // output: ` + // // Ignore user defined aliases + // let yyyy: Arr>>> = [[[['2']]]]; + // `, + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 3, + // column: 15, + // }, + // ], + // }, + // { + // code: ` + // interface ArrayClass { + // foo: Array; + // bar: T[]; + // baz: Arr; + // } + // `, + // output: ` + // interface ArrayClass { + // foo: Array; + // bar: Array; + // baz: Arr; + // } + // `, + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 4, + // column: 8, + // }, + // ], + // }, + // { + // code: ` + // function barFunction(bar: ArrayClass[]) { + // return bar.map(e => e.bar); + // } + // `, + // output: ` + // function barFunction(bar: Array>) { + // return bar.map(e => e.bar); + // } + // `, + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 2, + // column: 27, + // }, + // ], + // }, + // { + // code: 'let barVar: ((c: number) => number)[];', + // output: 'let barVar: Array<(c: number) => number>;', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 13, + // }, + // ], + // }, + // { + // code: 'type barUnion = (string | number | boolean)[];', + // output: 'type barUnion = Array;', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 17, + // }, + // ], + // }, + // { + // code: 'type barIntersection = (string & number)[];', + // output: 'type barIntersection = Array;', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 24, + // }, + // ], + // }, + // { + // code: ` + // interface FooInterface { + // '.bar': { baz: string[] }; + // } + // `, + // output: ` + // interface FooInterface { + // '.bar': { baz: Array }; + // } + // `, + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + // line: 3, + // column: 18, + // }, + // ], + // }, + // { + // // https://github.com/typescript-eslint/typescript-eslint/issues/172 + // code: 'type Unwrap = T extends Array ? E : T;', + // output: 'type Unwrap = T extends (infer E)[] ? E : T;', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 28, + // }, + // ], + // }, + // { + // // https://github.com/typescript-eslint/typescript-eslint/issues/172 + // code: 'type Unwrap = T extends (infer E)[] ? E : T;', + // output: 'type Unwrap = T extends Array ? E : T;', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 28, + // }, + // ], + // }, + // { + // code: 'type Foo = ReadonlyArray[];', + // output: 'type Foo = (readonly object[])[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'object', + // }, + // line: 1, + // column: 12, + // }, + // ], + // }, + // { + // code: 'const foo: Array void> = [];', + // output: 'const foo: (new (...args: any[]) => void)[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 12, + // }, + // ], + // }, + // { + // code: 'const foo: ReadonlyArray void> = [];', + // output: 'const foo: readonly (new (...args: any[]) => void)[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 12, + // }, + // ], + // }, ], }); -// -- eslint rule tester is not working with multi-pass -// https://github.com/eslint/eslint/issues/11187 -describe('array-type (nested)', () => { - const linter = new TSESLint.Linter(); - linter.defineRule('array-type', rule); - linter.defineParser('@typescript-eslint/parser', parser); +// // -- eslint rule tester is not working with multi-pass +// // https://github.com/eslint/eslint/issues/11187 +// describe('array-type (nested)', () => { +// const linter = new TSESLint.Linter(); +// linter.defineRule('array-type', rule); +// linter.defineParser('@typescript-eslint/parser', parser); - describe('should deeply fix correctly', () => { - function testOutput( - defaultOption: OptionString, - code: string, - output: string, - readonlyOption?: OptionString, - ): void { - it(code, () => { - const result = linter.verifyAndFix( - code, - { - rules: { - 'array-type': [ - 2, - { default: defaultOption, readonly: readonlyOption }, - ], - }, - parser: '@typescript-eslint/parser', - }, - { - fix: true, - }, - ); +// describe('should deeply fix correctly', () => { +// function testOutput( +// defaultOption: OptionString, +// code: string, +// output: string, +// readonlyOption?: OptionString, +// ): void { +// it(code, () => { +// const result = linter.verifyAndFix( +// code, +// { +// rules: { +// 'array-type': [ +// 2, +// { default: defaultOption, readonly: readonlyOption }, +// ], +// }, +// parser: '@typescript-eslint/parser', +// }, +// { +// fix: true, +// }, +// ); - expect(result.messages).toHaveLength(0); - expect(result.output).toBe(output); - }); - } +// expect(result.messages).toHaveLength(0); +// expect(result.output).toBe(output); +// }); +// } - testOutput( - 'array', - 'let a: ({ foo: Array | Array> })[] = []', - 'let a: ({ foo: (Bar[] | any[])[] })[] = []', - ); - testOutput( - 'array', - ` -class Foo>> extends Bar> implements Baz> { - private s: Array +// testOutput( +// 'array', +// 'let a: ({ foo: Array | Array> })[] = []', +// 'let a: ({ foo: (Bar[] | any[])[] })[] = []', +// ); +// testOutput( +// 'array', +// ` +// class Foo>> extends Bar> implements Baz> { +// private s: Array - constructor (p: Array) { - return new Array() - } -} - `, - ` -class Foo extends Bar implements Baz { - private s: T[] +// constructor (p: Array) { +// return new Array() +// } +// } +// `, +// ` +// class Foo extends Bar implements Baz { +// private s: T[] - constructor (p: T[]) { - return new Array() - } -} - `, - ); - testOutput( - 'array', - ` -interface WorkingArray { - outerProperty: Array< - { innerPropertyOne: string } & { innerPropertyTwo: string } - >; -} +// constructor (p: T[]) { +// return new Array() +// } +// } +// `, +// ); +// testOutput( +// 'array', +// ` +// interface WorkingArray { +// outerProperty: Array< +// { innerPropertyOne: string } & { innerPropertyTwo: string } +// >; +// } -interface BrokenArray { - outerProperty: Array< - ({ innerPropertyOne: string } & { innerPropertyTwo: string }) - >; -} - `, - ` -interface WorkingArray { - outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -} +// interface BrokenArray { +// outerProperty: Array< +// ({ innerPropertyOne: string } & { innerPropertyTwo: string }) +// >; +// } +// `, +// ` +// interface WorkingArray { +// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +// } -interface BrokenArray { - outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -} - `, - ); - testOutput( - 'array', - ` -type WorkingArray = { - outerProperty: Array< - { innerPropertyOne: string } & { innerPropertyTwo: string } - >; -} +// interface BrokenArray { +// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +// } +// `, +// ); +// testOutput( +// 'array', +// ` +// type WorkingArray = { +// outerProperty: Array< +// { innerPropertyOne: string } & { innerPropertyTwo: string } +// >; +// } -type BrokenArray = { - outerProperty: Array< - ({ innerPropertyOne: string } & { innerPropertyTwo: string }) - >; -} - `, - ` -type WorkingArray = { - outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -} +// type BrokenArray = { +// outerProperty: Array< +// ({ innerPropertyOne: string } & { innerPropertyTwo: string }) +// >; +// } +// `, +// ` +// type WorkingArray = { +// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +// } -type BrokenArray = { - outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -} - `, - ); - testOutput( - 'array', - 'const a: Array<(string|number)>;', - 'const a: (string|number)[];', - ); - testOutput( - 'array-simple', - 'let xx: Array> = [[1, 2], [3]];', - 'let xx: number[][] = [[1, 2], [3]];', - ); - testOutput( - 'array', - 'let xx: Array> = [[1, 2], [3]];', - 'let xx: number[][] = [[1, 2], [3]];', - ); - testOutput( - 'generic', - 'let yy: number[][] = [[4, 5], [6]];', - 'let yy: Array> = [[4, 5], [6]];', - ); - testOutput('array', 'let a: Array<>[] = [];', 'let a: any[][] = [];'); - testOutput('array', 'let a: Array = [];', 'let a: any[][] = [];'); - testOutput( - 'array', - 'let a: Array[] = [];', - 'let a: any[][][] = [];', - ); +// type BrokenArray = { +// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +// } +// `, +// ); +// testOutput( +// 'array', +// 'const a: Array<(string|number)>;', +// 'const a: (string|number)[];', +// ); +// testOutput( +// 'array-simple', +// 'let xx: Array> = [[1, 2], [3]];', +// 'let xx: number[][] = [[1, 2], [3]];', +// ); +// testOutput( +// 'array', +// 'let xx: Array> = [[1, 2], [3]];', +// 'let xx: number[][] = [[1, 2], [3]];', +// ); +// testOutput( +// 'generic', +// 'let yy: number[][] = [[4, 5], [6]];', +// 'let yy: Array> = [[4, 5], [6]];', +// ); +// testOutput('array', 'let a: Array<>[] = [];', 'let a: any[][] = [];'); +// testOutput('array', 'let a: Array = [];', 'let a: any[][] = [];'); +// testOutput( +// 'array', +// 'let a: Array[] = [];', +// 'let a: any[][][] = [];', +// ); - testOutput( - 'generic', - 'let a: Array<>[] = [];', - 'let a: Array> = [];', - ); - testOutput( - 'generic', - 'let a: Array = [];', - 'let a: Array> = [];', - ); - testOutput( - 'generic', - 'let a: Array[] = [];', - 'let a: Array>> = [];', - ); - testOutput( - 'generic', - 'let a: Array[] = [];', - 'let a: Array> = [];', - ); - testOutput( - 'generic', - 'let a: Array[] = [];', - 'let a: Array>> = [];', - ); +// testOutput( +// 'generic', +// 'let a: Array<>[] = [];', +// 'let a: Array> = [];', +// ); +// testOutput( +// 'generic', +// 'let a: Array = [];', +// 'let a: Array> = [];', +// ); +// testOutput( +// 'generic', +// 'let a: Array[] = [];', +// 'let a: Array>> = [];', +// ); +// testOutput( +// 'generic', +// 'let a: Array[] = [];', +// 'let a: Array> = [];', +// ); +// testOutput( +// 'generic', +// 'let a: Array[] = [];', +// 'let a: Array>> = [];', +// ); - // readonly - testOutput( - 'generic', - 'let x: readonly number[][]', - 'let x: ReadonlyArray>', - ); - testOutput( - 'generic', - 'let x: readonly (readonly number[])[]', - 'let x: ReadonlyArray>', - ); - testOutput( - 'array', - 'let x: ReadonlyArray>', - 'let x: readonly number[][]', - ); - testOutput( - 'array', - 'let x: ReadonlyArray>', - 'let x: readonly (readonly number[])[]', - ); - testOutput( - 'array', - 'let x: ReadonlyArray', - 'let x: readonly (readonly number[])[]', - ); - testOutput( - 'array', - 'let a: readonly number[][] = []', - 'let a: ReadonlyArray = []', - 'generic', - ); - testOutput( - 'generic', - 'let a: readonly number[][] = []', - 'let a: readonly Array[] = []', - 'array', - ); - testOutput( - 'generic', - 'type T = readonly(string)[]', - 'type T = ReadonlyArray', - 'generic', - ); - testOutput( - 'generic', - 'let a: readonly(readonly string[])[] = []', - 'let a: ReadonlyArray> = []', - 'generic', - ); - testOutput( - 'generic', - 'type T = readonly(readonly string[])[]', - 'type T = ReadonlyArray>', - 'generic', - ); - testOutput( - 'generic', - 'type T = readonly (readonly string[])[]', - 'type T = ReadonlyArray>', - 'generic', - ); - testOutput( - 'generic', - 'type T = readonly (readonly string[])[]', - 'type T = ReadonlyArray>', - 'generic', - ); - }); -}); +// // readonly +// testOutput( +// 'generic', +// 'let x: readonly number[][]', +// 'let x: ReadonlyArray>', +// ); +// testOutput( +// 'generic', +// 'let x: readonly (readonly number[])[]', +// 'let x: ReadonlyArray>', +// ); +// testOutput( +// 'array', +// 'let x: ReadonlyArray>', +// 'let x: readonly number[][]', +// ); +// testOutput( +// 'array', +// 'let x: ReadonlyArray>', +// 'let x: readonly (readonly number[])[]', +// ); +// testOutput( +// 'array', +// 'let x: ReadonlyArray', +// 'let x: readonly (readonly number[])[]', +// ); +// testOutput( +// 'array', +// 'let a: readonly number[][] = []', +// 'let a: ReadonlyArray = []', +// 'generic', +// ); +// testOutput( +// 'generic', +// 'let a: readonly number[][] = []', +// 'let a: readonly Array[] = []', +// 'array', +// ); +// testOutput( +// 'generic', +// 'type T = readonly(string)[]', +// 'type T = ReadonlyArray', +// 'generic', +// ); +// testOutput( +// 'generic', +// 'let a: readonly(readonly string[])[] = []', +// 'let a: ReadonlyArray> = []', +// 'generic', +// ); +// testOutput( +// 'generic', +// 'type T = readonly(readonly string[])[]', +// 'type T = ReadonlyArray>', +// 'generic', +// ); +// testOutput( +// 'generic', +// 'type T = readonly (readonly string[])[]', +// 'type T = ReadonlyArray>', +// 'generic', +// ); +// testOutput( +// 'generic', +// 'type T = readonly (readonly string[])[]', +// 'type T = ReadonlyArray>', +// 'generic', +// ); +// }); +// }); -describe('schema validation', () => { - // https://github.com/typescript-eslint/typescript-eslint/issues/6852 - test("array-type does not accept 'simple-array' option", () => { - if (areOptionsValid(rule, [{ default: 'simple-array' }])) { - throw new Error(`Options succeeded validation for bad options`); - } - }); +// describe('schema validation', () => { +// // https://github.com/typescript-eslint/typescript-eslint/issues/6852 +// test("array-type does not accept 'simple-array' option", () => { +// if (areOptionsValid(rule, [{ default: 'simple-array' }])) { +// throw new Error(`Options succeeded validation for bad options`); +// } +// }); - // https://github.com/typescript-eslint/typescript-eslint/issues/6892 - test('array-type does not accept non object option', () => { - if (areOptionsValid(rule, ['array'])) { - throw new Error(`Options succeeded validation for bad options`); - } - }); -}); +// // https://github.com/typescript-eslint/typescript-eslint/issues/6892 +// test('array-type does not accept non object option', () => { +// if (areOptionsValid(rule, ['array'])) { +// throw new Error(`Options succeeded validation for bad options`); +// } +// }); +// }); From 18fff29cd51e157986dd468549fa28427e9b5b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Fri, 22 Mar 2024 21:43:17 +0900 Subject: [PATCH 02/13] fix: test case --- .../tests/rules/array-type.test.ts | 4276 ++++++++--------- 1 file changed, 2132 insertions(+), 2144 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/array-type.test.ts b/packages/eslint-plugin/tests/rules/array-type.test.ts index 21b1ed92f9f4..44be83ff63db 100644 --- a/packages/eslint-plugin/tests/rules/array-type.test.ts +++ b/packages/eslint-plugin/tests/rules/array-type.test.ts @@ -13,2175 +13,2163 @@ const ruleTester = new RuleTester({ ruleTester.run('array-type', rule, { valid: [ // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly bigint[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly (string | bigint)[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: readonly bigint[] = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // // End of base cases - // { - // code: 'let a = new Array();', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let a: { foo: Bar[] }[] = [];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'function foo(a: Array): Array {}', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let yy: number[][] = [[4, 5], [6]];', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: ` - // function fooFunction(foo: Array>) { - // return foo.map(e => e.foo); - // } - // `, - // options: [{ default: 'array-simple' }], - // }, - // { - // code: ` - // function bazFunction(baz: Arr>) { - // return baz.map(e => e.baz); - // } - // `, - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let fooVar: Array<(c: number) => number>;', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'type fooUnion = Array;', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'type fooIntersection = Array;', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: ` - // namespace fooName { - // type BarType = { bar: string }; - // type BazType = Arr; - // } - // `, - // options: [{ default: 'array-simple' }], - // }, - // { - // code: ` - // interface FooInterface { - // '.bar': { baz: string[] }; - // } - // `, - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let yy: number[][] = [[4, 5], [6]];', - // options: [{ default: 'array' }], - // }, - // { - // code: "let ya = [[1, '2']] as [number, string][];", - // options: [{ default: 'array' }], - // }, - // { - // code: ` - // function barFunction(bar: ArrayClass[]) { - // return bar.map(e => e.bar); - // } - // `, - // options: [{ default: 'array' }], - // }, - // { - // code: ` - // function bazFunction(baz: Arr>) { - // return baz.map(e => e.baz); - // } - // `, - // options: [{ default: 'array' }], - // }, - // { - // code: 'let barVar: ((c: number) => number)[];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'type barUnion = (string | number | boolean)[];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'type barIntersection = (string & number)[];', - // options: [{ default: 'array' }], - // }, - // { - // code: ` - // interface FooInterface { - // '.bar': { baz: string[] }; - // } - // `, - // options: [{ default: 'array' }], - // }, - // { - // // https://github.com/typescript-eslint/typescript-eslint/issues/172 - // code: 'type Unwrap = T extends (infer E)[] ? E : T;', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let xx: Array> = [[1, 2], [3]];', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'type Arr = Array;', - // options: [{ default: 'generic' }], - // }, - // { - // code: ` - // function fooFunction(foo: Array>) { - // return foo.map(e => e.foo); - // } - // `, - // options: [{ default: 'generic' }], - // }, - // { - // code: ` - // function bazFunction(baz: Arr>) { - // return baz.map(e => e.baz); - // } - // `, - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let fooVar: Array<(c: number) => number>;', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'type fooUnion = Array;', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'type fooIntersection = Array;', - // options: [{ default: 'generic' }], - // }, - // { - // // https://github.com/typescript-eslint/typescript-eslint/issues/172 - // code: 'type Unwrap = T extends Array ? E : T;', - // options: [{ default: 'generic' }], - // }, - // // nested readonly - // { - // code: 'let a: ReadonlyArray = [[]];', - // options: [{ default: 'array', readonly: 'generic' }], - // }, - // { - // code: 'let a: readonly Array[] = [[]];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array' }], + }, + { + code: 'let a: (string | number)[] = [];', + options: [{ default: 'array' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array' }], + }, + { + code: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'array' }], + }, + { + code: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array', readonly: 'array' }], + }, + { + code: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + }, + { + code: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'generic' }], + }, + { + code: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'generic' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array-simple' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'array-simple' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + }, + { + code: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: readonly bigint[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: readonly (string | bigint)[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: readonly bigint[] = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + + // End of base cases + + { + code: 'let a = new Array();', + options: [{ default: 'array' }], + }, + { + code: 'let a: { foo: Bar[] }[] = [];', + options: [{ default: 'array' }], + }, + { + code: 'function foo(a: Array): Array {}', + options: [{ default: 'generic' }], + }, + { + code: 'let yy: number[][] = [[4, 5], [6]];', + options: [{ default: 'array-simple' }], + }, + { + code: ` +function fooFunction(foo: Array>) { + return foo.map(e => e.foo); +} + `, + options: [{ default: 'array-simple' }], + }, + { + code: ` +function bazFunction(baz: Arr>) { + return baz.map(e => e.baz); +} + `, + options: [{ default: 'array-simple' }], + }, + { + code: 'let fooVar: Array<(c: number) => number>;', + options: [{ default: 'array-simple' }], + }, + { + code: 'type fooUnion = Array;', + options: [{ default: 'array-simple' }], + }, + { + code: 'type fooIntersection = Array;', + options: [{ default: 'array-simple' }], + }, + { + code: ` +namespace fooName { + type BarType = { bar: string }; + type BazType = Arr; +} + `, + options: [{ default: 'array-simple' }], + }, + { + code: ` +interface FooInterface { + '.bar': { baz: string[] }; +} + `, + options: [{ default: 'array-simple' }], + }, + { + code: 'let yy: number[][] = [[4, 5], [6]];', + options: [{ default: 'array' }], + }, + { + code: "let ya = [[1, '2']] as [number, string][];", + options: [{ default: 'array' }], + }, + { + code: ` +function barFunction(bar: ArrayClass[]) { + return bar.map(e => e.bar); +} + `, + options: [{ default: 'array' }], + }, + { + code: ` +function bazFunction(baz: Arr>) { + return baz.map(e => e.baz); +} + `, + options: [{ default: 'array' }], + }, + { + code: 'let barVar: ((c: number) => number)[];', + options: [{ default: 'array' }], + }, + { + code: 'type barUnion = (string | number | boolean)[];', + options: [{ default: 'array' }], + }, + { + code: 'type barIntersection = (string & number)[];', + options: [{ default: 'array' }], + }, + { + code: ` +interface FooInterface { + '.bar': { baz: string[] }; +} + `, + options: [{ default: 'array' }], + }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends (infer E)[] ? E : T;', + options: [{ default: 'array' }], + }, + { + code: 'let xx: Array> = [[1, 2], [3]];', + options: [{ default: 'generic' }], + }, + { + code: 'type Arr = Array;', + options: [{ default: 'generic' }], + }, + { + code: ` +function fooFunction(foo: Array>) { + return foo.map(e => e.foo); +} + `, + options: [{ default: 'generic' }], + }, + { + code: ` +function bazFunction(baz: Arr>) { + return baz.map(e => e.baz); +} + `, + options: [{ default: 'generic' }], + }, + { + code: 'let fooVar: Array<(c: number) => number>;', + options: [{ default: 'generic' }], + }, + { + code: 'type fooUnion = Array;', + options: [{ default: 'generic' }], + }, + { + code: 'type fooIntersection = Array;', + options: [{ default: 'generic' }], + }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends Array ? E : T;', + options: [{ default: 'generic' }], + }, + + // nested readonly + { + code: 'let a: ReadonlyArray = [[]];', + options: [{ default: 'array', readonly: 'generic' }], + }, + { + code: 'let a: readonly Array[] = [[]];', + options: [{ default: 'generic', readonly: 'array' }], + }, ], invalid: [ - // // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 + // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: (string | number)[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly number[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly number[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: number[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly number[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: number[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: number[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: number[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly number[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: bigint[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'bigint' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | bigint)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly bigint[] = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'bigint', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | bigint)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly bigint[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'bigint', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | bigint)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + + // End of base cases + + { + code: 'let a: { foo: Array }[] = [];', + output: 'let a: { foo: Bar[] }[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + line: 1, + column: 15, + }, + ], + }, + { + code: 'let a: Array<{ foo: Bar[] }> = [];', + output: 'let a: Array<{ foo: Array }> = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + line: 1, + column: 21, + }, + ], + }, + { + code: 'let a: Array<{ foo: Foo | Bar[] }> = [];', + output: 'let a: Array<{ foo: Foo | Array }> = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + line: 1, + column: 27, + }, + ], + }, + { + code: 'function foo(a: Array): Array {}', + output: 'function foo(a: Bar[]): Bar[] {}', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + line: 1, + column: 17, + }, + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + line: 1, + column: 30, + }, + ], + }, + { + code: 'let x: Array = [undefined] as undefined[];', + output: 'let x: undefined[] = [undefined] as undefined[];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, + line: 1, + column: 8, + }, + ], + }, + { + code: "let y: string[] = >['2'];", + output: "let y: string[] = ['2'];", + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + line: 1, + column: 20, + }, + ], + }, + { + code: "let z: Array = [3, '4'];", + output: "let z: any[] = [3, '4'];", + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + line: 1, + column: 8, + }, + ], + }, + { + code: "let ya = [[1, '2']] as [number, string][];", + output: "let ya = [[1, '2']] as Array<[number, string]>;", + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 24, + }, + ], + }, + { + code: 'type Arr = Array;', + output: 'type Arr = T[];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 15, + }, + ], + }, + { + code: ` +// Ignore user defined aliases +let yyyy: Arr>[]> = [[[['2']]]]; + `, + output: ` +// Ignore user defined aliases +let yyyy: Arr>>> = [[[['2']]]]; + `, + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 3, + column: 15, + }, + ], + }, + { + code: ` +interface ArrayClass { + foo: Array; + bar: T[]; + baz: Arr; + xyz: this[]; +} + `, + output: ` +interface ArrayClass { + foo: T[]; + bar: T[]; + baz: Arr; + xyz: this[]; +} + `, + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 3, + column: 8, + }, + ], + }, + { + code: ` +function barFunction(bar: ArrayClass[]) { + return bar.map(e => e.bar); +} + `, + output: ` +function barFunction(bar: Array>) { + return bar.map(e => e.bar); +} + `, + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 2, + column: 27, + }, + ], + }, + { + code: 'let barVar: ((c: number) => number)[];', + output: 'let barVar: Array<(c: number) => number>;', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 13, + }, + ], + }, + { + code: 'type barUnion = (string | number | boolean)[];', + output: 'type barUnion = Array;', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 17, + }, + ], + }, + { + code: 'type barIntersection = (string & number)[];', + output: 'type barIntersection = Array;', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 24, + }, + ], + }, + { + code: "let v: Array = [{ bar: 'bar' }];", + output: "let v: fooName.BarType[] = [{ bar: 'bar' }];", + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'Array', + readonlyPrefix: '', + type: 'fooName.BarType', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: "let w: fooName.BazType[] = [['baz']];", + output: "let w: Array> = [['baz']];", + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let x: Array = [undefined] as undefined[];', + output: 'let x: undefined[] = [undefined] as undefined[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, + line: 1, + column: 8, + }, + ], + }, + { + code: "let y: string[] = >['2'];", + output: "let y: string[] = ['2'];", + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + line: 1, + column: 20, + }, + ], + }, + { + code: "let z: Array = [3, '4'];", + output: "let z: any[] = [3, '4'];", + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'type Arr = Array;', + output: 'type Arr = T[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 15, + }, + ], + }, + { + code: ` +// Ignore user defined aliases +let yyyy: Arr>[]> = [[[['2']]]]; + `, + output: ` +// Ignore user defined aliases +let yyyy: Arr[][]> = [[[['2']]]]; + `, + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 3, + column: 15, + }, + ], + }, + { + code: ` +interface ArrayClass { + foo: Array; + bar: T[]; + baz: Arr; +} + `, + output: ` +interface ArrayClass { + foo: T[]; + bar: T[]; + baz: Arr; +} + `, + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 3, + column: 8, + }, + ], + }, + { + code: ` +function fooFunction(foo: Array>) { + return foo.map(e => e.foo); +} + `, + output: ` +function fooFunction(foo: ArrayClass[]) { + return foo.map(e => e.foo); +} + `, + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 2, + column: 27, + }, + ], + }, + { + code: 'let fooVar: Array<(c: number) => number>;', + output: 'let fooVar: ((c: number) => number)[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 13, + }, + ], + }, + { + code: 'type fooUnion = Array;', + output: 'type fooUnion = (string | number | boolean)[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 17, + }, + ], + }, + { + code: 'type fooIntersection = Array;', + output: 'type fooIntersection = (string & number)[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 24, + }, + ], + }, + { + code: 'let x: Array;', + output: 'let x: any[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let x: Array<>;', + output: 'let x: any[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let x: Array;', + output: 'let x: any[];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let x: Array<>;', + output: 'let x: any[];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + line: 1, + column: 8, + }, + ], + }, + { + code: 'let x: Array = [1] as number[];', + output: 'let x: Array = [1] as Array;', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 31, + }, + ], + }, + { + code: "let y: string[] = >['2'];", + output: "let y: Array = >['2'];", + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + line: 1, + column: 8, + }, + ], + }, + { + code: "let ya = [[1, '2']] as [number, string][];", + output: "let ya = [[1, '2']] as Array<[number, string]>;", + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 24, + }, + ], + }, + { + code: ` +// Ignore user defined aliases +let yyyy: Arr>[]> = [[[['2']]]]; + `, + output: ` +// Ignore user defined aliases +let yyyy: Arr>>> = [[[['2']]]]; + `, + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 3, + column: 15, + }, + ], + }, + { + code: ` +interface ArrayClass { + foo: Array; + bar: T[]; + baz: Arr; +} + `, + output: ` +interface ArrayClass { + foo: Array; + bar: Array; + baz: Arr; +} + `, + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 4, + column: 8, + }, + ], + }, + { + code: ` +function barFunction(bar: ArrayClass[]) { + return bar.map(e => e.bar); +} + `, + output: ` +function barFunction(bar: Array>) { + return bar.map(e => e.bar); +} + `, + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 2, + column: 27, + }, + ], + }, + { + code: 'let barVar: ((c: number) => number)[];', + output: 'let barVar: Array<(c: number) => number>;', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 13, + }, + ], + }, + { + code: 'type barUnion = (string | number | boolean)[];', + output: 'type barUnion = Array;', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 17, + }, + ], + }, + { + code: 'type barIntersection = (string & number)[];', + output: 'type barIntersection = Array;', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 24, + }, + ], + }, + { + code: ` +interface FooInterface { + '.bar': { baz: string[] }; +} + `, + output: ` +interface FooInterface { + '.bar': { baz: Array }; +} + `, + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + line: 3, + column: 18, + }, + ], + }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends Array ? E : T;', + output: 'type Unwrap = T extends (infer E)[] ? E : T;', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 28, + }, + ], + }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends (infer E)[] ? E : T;', + output: 'type Unwrap = T extends Array ? E : T;', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 28, + }, + ], + }, { - code: "const x: Readonly = ['a', 'b'];", - output: "const x: readonly string[] = ['a', 'b'];", + code: 'type Foo = ReadonlyArray[];', + output: 'type Foo = (readonly object[])[];', options: [{ default: 'array' }], errors: [ { - messageId: 'errorStringArrayReadonly', + messageId: 'errorStringArray', data: { - className: 'Readonly', + className: 'ReadonlyArray', readonlyPrefix: 'readonly ', - type: 'string[]', + type: 'object', }, + line: 1, + column: 12, + }, + ], + }, + { + code: 'const foo: Array void> = [];', + output: 'const foo: (new (...args: any[]) => void)[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 12, + }, + ], + }, + { + code: 'const foo: ReadonlyArray void> = [];', + output: 'const foo: readonly (new (...args: any[]) => void)[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 12, }, ], }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: (string | number)[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly number[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly number[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: number[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly number[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: number[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: number[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: number[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly number[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: bigint[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'bigint' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | bigint)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly bigint[] = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'bigint', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | bigint)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly bigint[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'bigint', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | bigint)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - - // // End of base cases - - // { - // code: 'let a: { foo: Array }[] = [];', - // output: 'let a: { foo: Bar[] }[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - // line: 1, - // column: 15, - // }, - // ], - // }, - // { - // code: 'let a: Array<{ foo: Bar[] }> = [];', - // output: 'let a: Array<{ foo: Array }> = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - // line: 1, - // column: 21, - // }, - // ], - // }, - // { - // code: 'let a: Array<{ foo: Foo | Bar[] }> = [];', - // output: 'let a: Array<{ foo: Foo | Array }> = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - // line: 1, - // column: 27, - // }, - // ], - // }, - // { - // code: 'function foo(a: Array): Array {}', - // output: 'function foo(a: Bar[]): Bar[] {}', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - // line: 1, - // column: 17, - // }, - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - // line: 1, - // column: 30, - // }, - // ], - // }, - // { - // code: 'let x: Array = [undefined] as undefined[];', - // output: 'let x: undefined[] = [undefined] as undefined[];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: "let y: string[] = >['2'];", - // output: "let y: string[] = ['2'];", - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - // line: 1, - // column: 20, - // }, - // ], - // }, - // { - // code: "let z: Array = [3, '4'];", - // output: "let z: any[] = [3, '4'];", - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: "let ya = [[1, '2']] as [number, string][];", - // output: "let ya = [[1, '2']] as Array<[number, string]>;", - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 24, - // }, - // ], - // }, - // { - // code: 'type Arr = Array;', - // output: 'type Arr = T[];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 15, - // }, - // ], - // }, - // { - // code: ` - // // Ignore user defined aliases - // let yyyy: Arr>[]> = [[[['2']]]]; - // `, - // output: ` - // // Ignore user defined aliases - // let yyyy: Arr>>> = [[[['2']]]]; - // `, - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 3, - // column: 15, - // }, - // ], - // }, - // { - // code: ` - // interface ArrayClass { - // foo: Array; - // bar: T[]; - // baz: Arr; - // xyz: this[]; - // } - // `, - // output: ` - // interface ArrayClass { - // foo: T[]; - // bar: T[]; - // baz: Arr; - // xyz: this[]; - // } - // `, - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 3, - // column: 8, - // }, - // ], - // }, - // { - // code: ` - // function barFunction(bar: ArrayClass[]) { - // return bar.map(e => e.bar); - // } - // `, - // output: ` - // function barFunction(bar: Array>) { - // return bar.map(e => e.bar); - // } - // `, - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 2, - // column: 27, - // }, - // ], - // }, - // { - // code: 'let barVar: ((c: number) => number)[];', - // output: 'let barVar: Array<(c: number) => number>;', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 13, - // }, - // ], - // }, - // { - // code: 'type barUnion = (string | number | boolean)[];', - // output: 'type barUnion = Array;', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 17, - // }, - // ], - // }, - // { - // code: 'type barIntersection = (string & number)[];', - // output: 'type barIntersection = Array;', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 24, - // }, - // ], - // }, - // { - // code: "let v: Array = [{ bar: 'bar' }];", - // output: "let v: fooName.BarType[] = [{ bar: 'bar' }];", - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'Array', - // readonlyPrefix: '', - // type: 'fooName.BarType', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: "let w: fooName.BazType[] = [['baz']];", - // output: "let w: Array> = [['baz']];", - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let x: Array = [undefined] as undefined[];', - // output: 'let x: undefined[] = [undefined] as undefined[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: "let y: string[] = >['2'];", - // output: "let y: string[] = ['2'];", - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - // line: 1, - // column: 20, - // }, - // ], - // }, - // { - // code: "let z: Array = [3, '4'];", - // output: "let z: any[] = [3, '4'];", - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'type Arr = Array;', - // output: 'type Arr = T[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 15, - // }, - // ], - // }, - // { - // code: ` - // // Ignore user defined aliases - // let yyyy: Arr>[]> = [[[['2']]]]; - // `, - // output: ` - // // Ignore user defined aliases - // let yyyy: Arr[][]> = [[[['2']]]]; - // `, - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 3, - // column: 15, - // }, - // ], - // }, - // { - // code: ` - // interface ArrayClass { - // foo: Array; - // bar: T[]; - // baz: Arr; - // } - // `, - // output: ` - // interface ArrayClass { - // foo: T[]; - // bar: T[]; - // baz: Arr; - // } - // `, - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 3, - // column: 8, - // }, - // ], - // }, - // { - // code: ` - // function fooFunction(foo: Array>) { - // return foo.map(e => e.foo); - // } - // `, - // output: ` - // function fooFunction(foo: ArrayClass[]) { - // return foo.map(e => e.foo); - // } - // `, - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 2, - // column: 27, - // }, - // ], - // }, - // { - // code: 'let fooVar: Array<(c: number) => number>;', - // output: 'let fooVar: ((c: number) => number)[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 13, - // }, - // ], - // }, - // { - // code: 'type fooUnion = Array;', - // output: 'type fooUnion = (string | number | boolean)[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 17, - // }, - // ], - // }, - // { - // code: 'type fooIntersection = Array;', - // output: 'type fooIntersection = (string & number)[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 24, - // }, - // ], - // }, - // { - // code: 'let x: Array;', - // output: 'let x: any[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let x: Array<>;', - // output: 'let x: any[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let x: Array;', - // output: 'let x: any[];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let x: Array<>;', - // output: 'let x: any[];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let x: Array = [1] as number[];', - // output: 'let x: Array = [1] as Array;', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 31, - // }, - // ], - // }, - // { - // code: "let y: string[] = >['2'];", - // output: "let y: Array = >['2'];", - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: "let ya = [[1, '2']] as [number, string][];", - // output: "let ya = [[1, '2']] as Array<[number, string]>;", - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 24, - // }, - // ], - // }, - // { - // code: ` - // // Ignore user defined aliases - // let yyyy: Arr>[]> = [[[['2']]]]; - // `, - // output: ` - // // Ignore user defined aliases - // let yyyy: Arr>>> = [[[['2']]]]; - // `, - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 3, - // column: 15, - // }, - // ], - // }, - // { - // code: ` - // interface ArrayClass { - // foo: Array; - // bar: T[]; - // baz: Arr; - // } - // `, - // output: ` - // interface ArrayClass { - // foo: Array; - // bar: Array; - // baz: Arr; - // } - // `, - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 4, - // column: 8, - // }, - // ], - // }, - // { - // code: ` - // function barFunction(bar: ArrayClass[]) { - // return bar.map(e => e.bar); - // } - // `, - // output: ` - // function barFunction(bar: Array>) { - // return bar.map(e => e.bar); - // } - // `, - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 2, - // column: 27, - // }, - // ], - // }, - // { - // code: 'let barVar: ((c: number) => number)[];', - // output: 'let barVar: Array<(c: number) => number>;', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 13, - // }, - // ], - // }, - // { - // code: 'type barUnion = (string | number | boolean)[];', - // output: 'type barUnion = Array;', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 17, - // }, - // ], - // }, - // { - // code: 'type barIntersection = (string & number)[];', - // output: 'type barIntersection = Array;', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 24, - // }, - // ], - // }, - // { - // code: ` - // interface FooInterface { - // '.bar': { baz: string[] }; - // } - // `, - // output: ` - // interface FooInterface { - // '.bar': { baz: Array }; - // } - // `, - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - // line: 3, - // column: 18, - // }, - // ], - // }, - // { - // // https://github.com/typescript-eslint/typescript-eslint/issues/172 - // code: 'type Unwrap = T extends Array ? E : T;', - // output: 'type Unwrap = T extends (infer E)[] ? E : T;', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 28, - // }, - // ], - // }, - // { - // // https://github.com/typescript-eslint/typescript-eslint/issues/172 - // code: 'type Unwrap = T extends (infer E)[] ? E : T;', - // output: 'type Unwrap = T extends Array ? E : T;', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 28, - // }, - // ], - // }, - // { - // code: 'type Foo = ReadonlyArray[];', - // output: 'type Foo = (readonly object[])[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'object', - // }, - // line: 1, - // column: 12, - // }, - // ], - // }, - // { - // code: 'const foo: Array void> = [];', - // output: 'const foo: (new (...args: any[]) => void)[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 12, - // }, - // ], - // }, - // { - // code: 'const foo: ReadonlyArray void> = [];', - // output: 'const foo: readonly (new (...args: any[]) => void)[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 12, - // }, - // ], - // }, ], }); -// // -- eslint rule tester is not working with multi-pass -// // https://github.com/eslint/eslint/issues/11187 -// describe('array-type (nested)', () => { -// const linter = new TSESLint.Linter(); -// linter.defineRule('array-type', rule); -// linter.defineParser('@typescript-eslint/parser', parser); +// -- eslint rule tester is not working with multi-pass +// https://github.com/eslint/eslint/issues/11187 +describe('array-type (nested)', () => { + const linter = new TSESLint.Linter(); + linter.defineRule('array-type', rule); + linter.defineParser('@typescript-eslint/parser', parser); -// describe('should deeply fix correctly', () => { -// function testOutput( -// defaultOption: OptionString, -// code: string, -// output: string, -// readonlyOption?: OptionString, -// ): void { -// it(code, () => { -// const result = linter.verifyAndFix( -// code, -// { -// rules: { -// 'array-type': [ -// 2, -// { default: defaultOption, readonly: readonlyOption }, -// ], -// }, -// parser: '@typescript-eslint/parser', -// }, -// { -// fix: true, -// }, -// ); + describe('should deeply fix correctly', () => { + function testOutput( + defaultOption: OptionString, + code: string, + output: string, + readonlyOption?: OptionString, + ): void { + it(code, () => { + const result = linter.verifyAndFix( + code, + { + rules: { + 'array-type': [ + 2, + { default: defaultOption, readonly: readonlyOption }, + ], + }, + parser: '@typescript-eslint/parser', + }, + { + fix: true, + }, + ); -// expect(result.messages).toHaveLength(0); -// expect(result.output).toBe(output); -// }); -// } + expect(result.messages).toHaveLength(0); + expect(result.output).toBe(output); + }); + } -// testOutput( -// 'array', -// 'let a: ({ foo: Array | Array> })[] = []', -// 'let a: ({ foo: (Bar[] | any[])[] })[] = []', -// ); -// testOutput( -// 'array', -// ` -// class Foo>> extends Bar> implements Baz> { -// private s: Array + testOutput( + 'array', + 'let a: ({ foo: Array | Array> })[] = []', + 'let a: ({ foo: (Bar[] | any[])[] })[] = []', + ); + testOutput( + 'array', + ` +class Foo>> extends Bar> implements Baz> { + private s: Array -// constructor (p: Array) { -// return new Array() -// } -// } -// `, -// ` -// class Foo extends Bar implements Baz { -// private s: T[] + constructor (p: Array) { + return new Array() + } +} + `, + ` +class Foo extends Bar implements Baz { + private s: T[] -// constructor (p: T[]) { -// return new Array() -// } -// } -// `, -// ); -// testOutput( -// 'array', -// ` -// interface WorkingArray { -// outerProperty: Array< -// { innerPropertyOne: string } & { innerPropertyTwo: string } -// >; -// } + constructor (p: T[]) { + return new Array() + } +} + `, + ); + testOutput( + 'array', + ` +interface WorkingArray { + outerProperty: Array< + { innerPropertyOne: string } & { innerPropertyTwo: string } + >; +} -// interface BrokenArray { -// outerProperty: Array< -// ({ innerPropertyOne: string } & { innerPropertyTwo: string }) -// >; -// } -// `, -// ` -// interface WorkingArray { -// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -// } +interface BrokenArray { + outerProperty: Array< + ({ innerPropertyOne: string } & { innerPropertyTwo: string }) + >; +} + `, + ` +interface WorkingArray { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} -// interface BrokenArray { -// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -// } -// `, -// ); -// testOutput( -// 'array', -// ` -// type WorkingArray = { -// outerProperty: Array< -// { innerPropertyOne: string } & { innerPropertyTwo: string } -// >; -// } +interface BrokenArray { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} + `, + ); + testOutput( + 'array', + ` +type WorkingArray = { + outerProperty: Array< + { innerPropertyOne: string } & { innerPropertyTwo: string } + >; +} -// type BrokenArray = { -// outerProperty: Array< -// ({ innerPropertyOne: string } & { innerPropertyTwo: string }) -// >; -// } -// `, -// ` -// type WorkingArray = { -// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -// } +type BrokenArray = { + outerProperty: Array< + ({ innerPropertyOne: string } & { innerPropertyTwo: string }) + >; +} + `, + ` +type WorkingArray = { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} -// type BrokenArray = { -// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -// } -// `, -// ); -// testOutput( -// 'array', -// 'const a: Array<(string|number)>;', -// 'const a: (string|number)[];', -// ); -// testOutput( -// 'array-simple', -// 'let xx: Array> = [[1, 2], [3]];', -// 'let xx: number[][] = [[1, 2], [3]];', -// ); -// testOutput( -// 'array', -// 'let xx: Array> = [[1, 2], [3]];', -// 'let xx: number[][] = [[1, 2], [3]];', -// ); -// testOutput( -// 'generic', -// 'let yy: number[][] = [[4, 5], [6]];', -// 'let yy: Array> = [[4, 5], [6]];', -// ); -// testOutput('array', 'let a: Array<>[] = [];', 'let a: any[][] = [];'); -// testOutput('array', 'let a: Array = [];', 'let a: any[][] = [];'); -// testOutput( -// 'array', -// 'let a: Array[] = [];', -// 'let a: any[][][] = [];', -// ); +type BrokenArray = { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} + `, + ); + testOutput( + 'array', + 'const a: Array<(string|number)>;', + 'const a: (string|number)[];', + ); + testOutput( + 'array-simple', + 'let xx: Array> = [[1, 2], [3]];', + 'let xx: number[][] = [[1, 2], [3]];', + ); + testOutput( + 'array', + 'let xx: Array> = [[1, 2], [3]];', + 'let xx: number[][] = [[1, 2], [3]];', + ); + testOutput( + 'generic', + 'let yy: number[][] = [[4, 5], [6]];', + 'let yy: Array> = [[4, 5], [6]];', + ); + testOutput('array', 'let a: Array<>[] = [];', 'let a: any[][] = [];'); + testOutput('array', 'let a: Array = [];', 'let a: any[][] = [];'); + testOutput( + 'array', + 'let a: Array[] = [];', + 'let a: any[][][] = [];', + ); -// testOutput( -// 'generic', -// 'let a: Array<>[] = [];', -// 'let a: Array> = [];', -// ); -// testOutput( -// 'generic', -// 'let a: Array = [];', -// 'let a: Array> = [];', -// ); -// testOutput( -// 'generic', -// 'let a: Array[] = [];', -// 'let a: Array>> = [];', -// ); -// testOutput( -// 'generic', -// 'let a: Array[] = [];', -// 'let a: Array> = [];', -// ); -// testOutput( -// 'generic', -// 'let a: Array[] = [];', -// 'let a: Array>> = [];', -// ); + testOutput( + 'generic', + 'let a: Array<>[] = [];', + 'let a: Array> = [];', + ); + testOutput( + 'generic', + 'let a: Array = [];', + 'let a: Array> = [];', + ); + testOutput( + 'generic', + 'let a: Array[] = [];', + 'let a: Array>> = [];', + ); + testOutput( + 'generic', + 'let a: Array[] = [];', + 'let a: Array> = [];', + ); + testOutput( + 'generic', + 'let a: Array[] = [];', + 'let a: Array>> = [];', + ); -// // readonly -// testOutput( -// 'generic', -// 'let x: readonly number[][]', -// 'let x: ReadonlyArray>', -// ); -// testOutput( -// 'generic', -// 'let x: readonly (readonly number[])[]', -// 'let x: ReadonlyArray>', -// ); -// testOutput( -// 'array', -// 'let x: ReadonlyArray>', -// 'let x: readonly number[][]', -// ); -// testOutput( -// 'array', -// 'let x: ReadonlyArray>', -// 'let x: readonly (readonly number[])[]', -// ); -// testOutput( -// 'array', -// 'let x: ReadonlyArray', -// 'let x: readonly (readonly number[])[]', -// ); -// testOutput( -// 'array', -// 'let a: readonly number[][] = []', -// 'let a: ReadonlyArray = []', -// 'generic', -// ); -// testOutput( -// 'generic', -// 'let a: readonly number[][] = []', -// 'let a: readonly Array[] = []', -// 'array', -// ); -// testOutput( -// 'generic', -// 'type T = readonly(string)[]', -// 'type T = ReadonlyArray', -// 'generic', -// ); -// testOutput( -// 'generic', -// 'let a: readonly(readonly string[])[] = []', -// 'let a: ReadonlyArray> = []', -// 'generic', -// ); -// testOutput( -// 'generic', -// 'type T = readonly(readonly string[])[]', -// 'type T = ReadonlyArray>', -// 'generic', -// ); -// testOutput( -// 'generic', -// 'type T = readonly (readonly string[])[]', -// 'type T = ReadonlyArray>', -// 'generic', -// ); -// testOutput( -// 'generic', -// 'type T = readonly (readonly string[])[]', -// 'type T = ReadonlyArray>', -// 'generic', -// ); -// }); -// }); + // readonly + testOutput( + 'generic', + 'let x: readonly number[][]', + 'let x: ReadonlyArray>', + ); + testOutput( + 'generic', + 'let x: readonly (readonly number[])[]', + 'let x: ReadonlyArray>', + ); + testOutput( + 'array', + 'let x: ReadonlyArray>', + 'let x: readonly number[][]', + ); + testOutput( + 'array', + 'let x: ReadonlyArray>', + 'let x: readonly (readonly number[])[]', + ); + testOutput( + 'array', + 'let x: ReadonlyArray', + 'let x: readonly (readonly number[])[]', + ); + testOutput( + 'array', + 'let a: readonly number[][] = []', + 'let a: ReadonlyArray = []', + 'generic', + ); + testOutput( + 'generic', + 'let a: readonly number[][] = []', + 'let a: readonly Array[] = []', + 'array', + ); + testOutput( + 'generic', + 'type T = readonly(string)[]', + 'type T = ReadonlyArray', + 'generic', + ); + testOutput( + 'generic', + 'let a: readonly(readonly string[])[] = []', + 'let a: ReadonlyArray> = []', + 'generic', + ); + testOutput( + 'generic', + 'type T = readonly(readonly string[])[]', + 'type T = ReadonlyArray>', + 'generic', + ); + testOutput( + 'generic', + 'type T = readonly (readonly string[])[]', + 'type T = ReadonlyArray>', + 'generic', + ); + testOutput( + 'generic', + 'type T = readonly (readonly string[])[]', + 'type T = ReadonlyArray>', + 'generic', + ); + }); +}); -// describe('schema validation', () => { -// // https://github.com/typescript-eslint/typescript-eslint/issues/6852 -// test("array-type does not accept 'simple-array' option", () => { -// if (areOptionsValid(rule, [{ default: 'simple-array' }])) { -// throw new Error(`Options succeeded validation for bad options`); -// } -// }); +describe('schema validation', () => { + // https://github.com/typescript-eslint/typescript-eslint/issues/6852 + test("array-type does not accept 'simple-array' option", () => { + if (areOptionsValid(rule, [{ default: 'simple-array' }])) { + throw new Error(`Options succeeded validation for bad options`); + } + }); -// // https://github.com/typescript-eslint/typescript-eslint/issues/6892 -// test('array-type does not accept non object option', () => { -// if (areOptionsValid(rule, ['array'])) { -// throw new Error(`Options succeeded validation for bad options`); -// } -// }); -// }); + // https://github.com/typescript-eslint/typescript-eslint/issues/6892 + test('array-type does not accept non object option', () => { + if (areOptionsValid(rule, ['array'])) { + throw new Error(`Options succeeded validation for bad options`); + } + }); +}); From 2471ff293fa1c4f548cc503351301cef99e56dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Fri, 22 Mar 2024 21:48:53 +0900 Subject: [PATCH 03/13] test: add test case --- .../eslint-plugin/tests/rules/array-type.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/array-type.test.ts b/packages/eslint-plugin/tests/rules/array-type.test.ts index 44be83ff63db..0ae5fc5bce91 100644 --- a/packages/eslint-plugin/tests/rules/array-type.test.ts +++ b/packages/eslint-plugin/tests/rules/array-type.test.ts @@ -1918,6 +1918,21 @@ interface FooInterface { }, ], }, + { + code: "const x: Readonly = ['a', 'b'];", + output: "const x: readonly string[] = ['a', 'b'];", + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArrayReadonly', + data: { + className: 'Readonly', + readonlyPrefix: 'readonly ', + type: 'string[]', + }, + }, + ], + }, ], }); From 2ce79569806f4d0bfd2444b9daf2b0c4f9c45e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Fri, 22 Mar 2024 22:02:47 +0900 Subject: [PATCH 04/13] docs: add `ReadonlyArray` description --- packages/eslint-plugin/docs/rules/array-type.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/docs/rules/array-type.mdx b/packages/eslint-plugin/docs/rules/array-type.mdx index 3985ccc7e2ac..ad51dca3dca6 100644 --- a/packages/eslint-plugin/docs/rules/array-type.mdx +++ b/packages/eslint-plugin/docs/rules/array-type.mdx @@ -42,7 +42,8 @@ const y: readonly string[] = ['a', 'b']; ### `"generic"` -Always use `Array` or `ReadonlyArray` for all array types. +Always use `Array` or `ReadonlyArray` or `Readonly` for all array types. +However, `readonly T[]` is modified to `ReadonlyArray`. @@ -58,6 +59,7 @@ const y: readonly string[] = ['a', 'b']; ```ts option='{ "default": "generic" }' const x: Array = ['a', 'b']; const y: ReadonlyArray = ['a', 'b']; +const z: Readonly = ['a', 'b']; ``` From 76d9f36a495b0769d9831c288d7dfbffd11f77e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Sat, 23 Mar 2024 18:47:44 +0900 Subject: [PATCH 05/13] test: add droped test case --- .../tests/rules/array-type.test.ts | 4290 +++++++++-------- 1 file changed, 2147 insertions(+), 2143 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/array-type.test.ts b/packages/eslint-plugin/tests/rules/array-type.test.ts index 0ae5fc5bce91..8373191898ee 100644 --- a/packages/eslint-plugin/tests/rules/array-type.test.ts +++ b/packages/eslint-plugin/tests/rules/array-type.test.ts @@ -13,1911 +13,1915 @@ const ruleTester = new RuleTester({ ruleTester.run('array-type', rule, { valid: [ // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 - { - code: 'let a: number[] = [];', - options: [{ default: 'array' }], - }, - { - code: 'let a: (string | number)[] = [];', - options: [{ default: 'array' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array' }], - }, - { - code: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'array' }], - }, - { - code: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array', readonly: 'array' }], - }, - { - code: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - }, - { - code: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'generic' }], - }, - { - code: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'generic' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array-simple' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'array-simple' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - }, - { - code: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - }, - { - code: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: readonly number[] = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: readonly bigint[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: readonly (string | bigint)[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: readonly bigint[] = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - { - code: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - }, - - // End of base cases - - { - code: 'let a = new Array();', - options: [{ default: 'array' }], - }, - { - code: 'let a: { foo: Bar[] }[] = [];', - options: [{ default: 'array' }], - }, - { - code: 'function foo(a: Array): Array {}', - options: [{ default: 'generic' }], - }, - { - code: 'let yy: number[][] = [[4, 5], [6]];', - options: [{ default: 'array-simple' }], - }, - { - code: ` -function fooFunction(foo: Array>) { - return foo.map(e => e.foo); -} - `, - options: [{ default: 'array-simple' }], - }, - { - code: ` -function bazFunction(baz: Arr>) { - return baz.map(e => e.baz); -} - `, - options: [{ default: 'array-simple' }], - }, - { - code: 'let fooVar: Array<(c: number) => number>;', - options: [{ default: 'array-simple' }], - }, - { - code: 'type fooUnion = Array;', - options: [{ default: 'array-simple' }], - }, - { - code: 'type fooIntersection = Array;', - options: [{ default: 'array-simple' }], - }, - { - code: ` -namespace fooName { - type BarType = { bar: string }; - type BazType = Arr; -} - `, - options: [{ default: 'array-simple' }], - }, - { - code: ` -interface FooInterface { - '.bar': { baz: string[] }; -} - `, - options: [{ default: 'array-simple' }], - }, - { - code: 'let yy: number[][] = [[4, 5], [6]];', - options: [{ default: 'array' }], - }, - { - code: "let ya = [[1, '2']] as [number, string][];", - options: [{ default: 'array' }], - }, - { - code: ` -function barFunction(bar: ArrayClass[]) { - return bar.map(e => e.bar); -} - `, - options: [{ default: 'array' }], - }, - { - code: ` -function bazFunction(baz: Arr>) { - return baz.map(e => e.baz); -} - `, - options: [{ default: 'array' }], - }, - { - code: 'let barVar: ((c: number) => number)[];', - options: [{ default: 'array' }], - }, - { - code: 'type barUnion = (string | number | boolean)[];', - options: [{ default: 'array' }], - }, - { - code: 'type barIntersection = (string & number)[];', - options: [{ default: 'array' }], - }, - { - code: ` -interface FooInterface { - '.bar': { baz: string[] }; -} - `, - options: [{ default: 'array' }], - }, - { - // https://github.com/typescript-eslint/typescript-eslint/issues/172 - code: 'type Unwrap = T extends (infer E)[] ? E : T;', - options: [{ default: 'array' }], - }, - { - code: 'let xx: Array> = [[1, 2], [3]];', - options: [{ default: 'generic' }], - }, - { - code: 'type Arr = Array;', - options: [{ default: 'generic' }], - }, - { - code: ` -function fooFunction(foo: Array>) { - return foo.map(e => e.foo); -} - `, - options: [{ default: 'generic' }], - }, - { - code: ` -function bazFunction(baz: Arr>) { - return baz.map(e => e.baz); -} - `, - options: [{ default: 'generic' }], - }, - { - code: 'let fooVar: Array<(c: number) => number>;', - options: [{ default: 'generic' }], - }, - { - code: 'type fooUnion = Array;', - options: [{ default: 'generic' }], - }, - { - code: 'type fooIntersection = Array;', - options: [{ default: 'generic' }], - }, - { - // https://github.com/typescript-eslint/typescript-eslint/issues/172 - code: 'type Unwrap = T extends Array ? E : T;', - options: [{ default: 'generic' }], - }, - - // nested readonly - { - code: 'let a: ReadonlyArray = [[]];', - options: [{ default: 'array', readonly: 'generic' }], - }, - { - code: 'let a: readonly Array[] = [[]];', - options: [{ default: 'generic', readonly: 'array' }], - }, - ], - invalid: [ - // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: (string | number)[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: (string | number)[] = [];', - options: [{ default: 'array', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly number[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'array-simple', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: Array = [];', - output: 'let a: number[] = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly number[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'array-simple', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: number[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly number[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: number[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly (string | number)[] = [];', - options: [{ default: 'generic', readonly: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: number[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly number[] = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: number[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | number)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly number[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'number', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | number)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: bigint[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'bigint' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | bigint)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: ReadonlyArray = [];', - output: 'let a: readonly bigint[] = [];', - options: [{ default: 'generic', readonly: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'bigint', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: (string | bigint)[] = [];', - output: 'let a: Array = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly bigint[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'bigint', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let a: readonly (string | bigint)[] = [];', - output: 'let a: ReadonlyArray = [];', - options: [{ default: 'generic', readonly: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 8, - }, - ], - }, - - // End of base cases - - { - code: 'let a: { foo: Array }[] = [];', - output: 'let a: { foo: Bar[] }[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - line: 1, - column: 15, - }, - ], - }, - { - code: 'let a: Array<{ foo: Bar[] }> = [];', - output: 'let a: Array<{ foo: Array }> = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - line: 1, - column: 21, - }, - ], - }, - { - code: 'let a: Array<{ foo: Foo | Bar[] }> = [];', - output: 'let a: Array<{ foo: Foo | Array }> = [];', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - line: 1, - column: 27, - }, - ], - }, - { - code: 'function foo(a: Array): Array {}', - output: 'function foo(a: Bar[]): Bar[] {}', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - line: 1, - column: 17, - }, - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - line: 1, - column: 30, - }, - ], - }, - { - code: 'let x: Array = [undefined] as undefined[];', - output: 'let x: undefined[] = [undefined] as undefined[];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, - line: 1, - column: 8, - }, - ], - }, - { - code: "let y: string[] = >['2'];", - output: "let y: string[] = ['2'];", - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - line: 1, - column: 20, - }, - ], - }, - { - code: "let z: Array = [3, '4'];", - output: "let z: any[] = [3, '4'];", - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - line: 1, - column: 8, - }, - ], - }, - { - code: "let ya = [[1, '2']] as [number, string][];", - output: "let ya = [[1, '2']] as Array<[number, string]>;", - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 24, - }, - ], - }, - { - code: 'type Arr = Array;', - output: 'type Arr = T[];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 15, - }, - ], - }, - { - code: ` -// Ignore user defined aliases -let yyyy: Arr>[]> = [[[['2']]]]; - `, - output: ` -// Ignore user defined aliases -let yyyy: Arr>>> = [[[['2']]]]; - `, - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 3, - column: 15, - }, - ], - }, - { - code: ` -interface ArrayClass { - foo: Array; - bar: T[]; - baz: Arr; - xyz: this[]; -} - `, - output: ` -interface ArrayClass { - foo: T[]; - bar: T[]; - baz: Arr; - xyz: this[]; -} - `, - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 3, - column: 8, - }, - ], - }, - { - code: ` -function barFunction(bar: ArrayClass[]) { - return bar.map(e => e.bar); -} - `, - output: ` -function barFunction(bar: Array>) { - return bar.map(e => e.bar); -} - `, - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 2, - column: 27, - }, - ], - }, - { - code: 'let barVar: ((c: number) => number)[];', - output: 'let barVar: Array<(c: number) => number>;', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 13, - }, - ], - }, - { - code: 'type barUnion = (string | number | boolean)[];', - output: 'type barUnion = Array;', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 17, - }, - ], - }, - { - code: 'type barIntersection = (string & number)[];', - output: 'type barIntersection = Array;', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 24, - }, - ], - }, - { - code: "let v: Array = [{ bar: 'bar' }];", - output: "let v: fooName.BarType[] = [{ bar: 'bar' }];", - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { - className: 'Array', - readonlyPrefix: '', - type: 'fooName.BarType', - }, - line: 1, - column: 8, - }, - ], - }, - { - code: "let w: fooName.BazType[] = [['baz']];", - output: "let w: Array> = [['baz']];", - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringGenericSimple', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let x: Array = [undefined] as undefined[];', - output: 'let x: undefined[] = [undefined] as undefined[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, - line: 1, - column: 8, - }, - ], - }, - { - code: "let y: string[] = >['2'];", - output: "let y: string[] = ['2'];", - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - line: 1, - column: 20, - }, - ], - }, - { - code: "let z: Array = [3, '4'];", - output: "let z: any[] = [3, '4'];", - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'type Arr = Array;', - output: 'type Arr = T[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 15, - }, - ], - }, - { - code: ` -// Ignore user defined aliases -let yyyy: Arr>[]> = [[[['2']]]]; - `, - output: ` -// Ignore user defined aliases -let yyyy: Arr[][]> = [[[['2']]]]; - `, - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 3, - column: 15, - }, - ], - }, - { - code: ` -interface ArrayClass { - foo: Array; - bar: T[]; - baz: Arr; -} - `, - output: ` -interface ArrayClass { - foo: T[]; - bar: T[]; - baz: Arr; -} - `, - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 3, - column: 8, - }, - ], - }, - { - code: ` -function fooFunction(foo: Array>) { - return foo.map(e => e.foo); -} - `, - output: ` -function fooFunction(foo: ArrayClass[]) { - return foo.map(e => e.foo); -} - `, - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 2, - column: 27, - }, - ], - }, - { - code: 'let fooVar: Array<(c: number) => number>;', - output: 'let fooVar: ((c: number) => number)[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 13, - }, - ], - }, - { - code: 'type fooUnion = Array;', - output: 'type fooUnion = (string | number | boolean)[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 17, - }, - ], - }, - { - code: 'type fooIntersection = Array;', - output: 'type fooIntersection = (string & number)[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 24, - }, - ], - }, - { - code: 'let x: Array;', - output: 'let x: any[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let x: Array<>;', - output: 'let x: any[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let x: Array;', - output: 'let x: any[];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - line: 1, - column: 8, - }, - ], - }, - { - code: 'let x: Array<>;', - output: 'let x: any[];', - options: [{ default: 'array-simple' }], - errors: [ - { - messageId: 'errorStringArraySimple', - line: 1, - column: 8, - }, - ], - }, - { - code: 'let x: Array = [1] as number[];', - output: 'let x: Array = [1] as Array;', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - line: 1, - column: 31, - }, - ], - }, - { - code: "let y: string[] = >['2'];", - output: "let y: Array = >['2'];", - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - line: 1, - column: 8, - }, - ], - }, - { - code: "let ya = [[1, '2']] as [number, string][];", - output: "let ya = [[1, '2']] as Array<[number, string]>;", - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 24, - }, - ], - }, - { - code: ` -// Ignore user defined aliases -let yyyy: Arr>[]> = [[[['2']]]]; - `, - output: ` -// Ignore user defined aliases -let yyyy: Arr>>> = [[[['2']]]]; - `, - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 3, - column: 15, - }, - ], - }, - { - code: ` -interface ArrayClass { - foo: Array; - bar: T[]; - baz: Arr; -} - `, - output: ` -interface ArrayClass { - foo: Array; - bar: Array; - baz: Arr; -} - `, - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 4, - column: 8, - }, - ], - }, - { - code: ` -function barFunction(bar: ArrayClass[]) { - return bar.map(e => e.bar); -} - `, - output: ` -function barFunction(bar: Array>) { - return bar.map(e => e.bar); -} - `, - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 2, - column: 27, - }, - ], - }, - { - code: 'let barVar: ((c: number) => number)[];', - output: 'let barVar: Array<(c: number) => number>;', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 13, - }, - ], - }, - { - code: 'type barUnion = (string | number | boolean)[];', - output: 'type barUnion = Array;', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 17, - }, - ], - }, - { - code: 'type barIntersection = (string & number)[];', - output: 'type barIntersection = Array;', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 24, - }, - ], - }, - { - code: ` -interface FooInterface { - '.bar': { baz: string[] }; -} - `, - output: ` -interface FooInterface { - '.bar': { baz: Array }; -} - `, - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - line: 3, - column: 18, - }, - ], - }, - { - // https://github.com/typescript-eslint/typescript-eslint/issues/172 - code: 'type Unwrap = T extends Array ? E : T;', - output: 'type Unwrap = T extends (infer E)[] ? E : T;', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 28, - }, - ], - }, - { - // https://github.com/typescript-eslint/typescript-eslint/issues/172 - code: 'type Unwrap = T extends (infer E)[] ? E : T;', - output: 'type Unwrap = T extends Array ? E : T;', - options: [{ default: 'generic' }], - errors: [ - { - messageId: 'errorStringGeneric', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 28, - }, - ], - }, - { - code: 'type Foo = ReadonlyArray[];', - output: 'type Foo = (readonly object[])[];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'object', - }, - line: 1, - column: 12, - }, - ], - }, - { - code: 'const foo: Array void> = [];', - output: 'const foo: (new (...args: any[]) => void)[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - line: 1, - column: 12, - }, - ], - }, - { - code: 'const foo: ReadonlyArray void> = [];', - output: 'const foo: readonly (new (...args: any[]) => void)[] = [];', - options: [{ default: 'array' }], - errors: [ - { - messageId: 'errorStringArray', - data: { - className: 'ReadonlyArray', - readonlyPrefix: 'readonly ', - type: 'T', - }, - line: 1, - column: 12, - }, - ], + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: readonly number[] = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly bigint[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: readonly (string | bigint)[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: readonly bigint[] = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // }, + + // // End of base cases + + // { + // code: 'let a = new Array();', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let a: { foo: Bar[] }[] = [];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'function foo(a: Array): Array {}', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let yy: number[][] = [[4, 5], [6]];', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: ` + // function fooFunction(foo: Array>) { + // return foo.map(e => e.foo); + // } + // `, + // options: [{ default: 'array-simple' }], + // }, + // { + // code: ` + // function bazFunction(baz: Arr>) { + // return baz.map(e => e.baz); + // } + // `, + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let fooVar: Array<(c: number) => number>;', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'type fooUnion = Array;', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'type fooIntersection = Array;', + // options: [{ default: 'array-simple' }], + // }, + // { + // code: ` + // namespace fooName { + // type BarType = { bar: string }; + // type BazType = Arr; + // } + // `, + // options: [{ default: 'array-simple' }], + // }, + // { + // code: ` + // interface FooInterface { + // '.bar': { baz: string[] }; + // } + // `, + // options: [{ default: 'array-simple' }], + // }, + // { + // code: 'let yy: number[][] = [[4, 5], [6]];', + // options: [{ default: 'array' }], + // }, + // { + // code: "let ya = [[1, '2']] as [number, string][];", + // options: [{ default: 'array' }], + // }, + // { + // code: ` + // function barFunction(bar: ArrayClass[]) { + // return bar.map(e => e.bar); + // } + // `, + // options: [{ default: 'array' }], + // }, + // { + // code: ` + // function bazFunction(baz: Arr>) { + // return baz.map(e => e.baz); + // } + // `, + // options: [{ default: 'array' }], + // }, + // { + // code: 'let barVar: ((c: number) => number)[];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'type barUnion = (string | number | boolean)[];', + // options: [{ default: 'array' }], + // }, + // { + // code: 'type barIntersection = (string & number)[];', + // options: [{ default: 'array' }], + // }, + // { + // code: ` + // interface FooInterface { + // '.bar': { baz: string[] }; + // } + // `, + // options: [{ default: 'array' }], + // }, + // { + // // https://github.com/typescript-eslint/typescript-eslint/issues/172 + // code: 'type Unwrap = T extends (infer E)[] ? E : T;', + // options: [{ default: 'array' }], + // }, + // { + // code: 'let xx: Array> = [[1, 2], [3]];', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'type Arr = Array;', + // options: [{ default: 'generic' }], + // }, + // { + // code: ` + // function fooFunction(foo: Array>) { + // return foo.map(e => e.foo); + // } + // `, + // options: [{ default: 'generic' }], + // }, + // { + // code: ` + // function bazFunction(baz: Arr>) { + // return baz.map(e => e.baz); + // } + // `, + // options: [{ default: 'generic' }], + // }, + // { + // code: 'let fooVar: Array<(c: number) => number>;', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'type fooUnion = Array;', + // options: [{ default: 'generic' }], + // }, + // { + // code: 'type fooIntersection = Array;', + // options: [{ default: 'generic' }], + // }, + // { + // // https://github.com/typescript-eslint/typescript-eslint/issues/172 + // code: 'type Unwrap = T extends Array ? E : T;', + // options: [{ default: 'generic' }], + // }, + + // // nested readonly + // { + // code: 'let a: ReadonlyArray = [[]];', + // options: [{ default: 'array', readonly: 'generic' }], + // }, + // { + // code: 'let a: readonly Array[] = [[]];', + // options: [{ default: 'generic', readonly: 'array' }], + // }, + { + code: 'let a: Readonly = [];', + options: [{ default: 'generic', readonly: 'array' }], }, + ], + invalid: [ + // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: (string | number)[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: (string | number)[] = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly number[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'array-simple', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: Array = [];', + // output: 'let a: number[] = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly number[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'array-simple', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: number[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly number[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: number[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly (string | number)[] = [];', + // options: [{ default: 'generic', readonly: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: number[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly number[] = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: number[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | number)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly number[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'number', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | number)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: bigint[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'bigint' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | bigint)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: ReadonlyArray = [];', + // output: 'let a: readonly bigint[] = [];', + // options: [{ default: 'generic', readonly: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'bigint', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: (string | bigint)[] = [];', + // output: 'let a: Array = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly bigint[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'bigint', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let a: readonly (string | bigint)[] = [];', + // output: 'let a: ReadonlyArray = [];', + // options: [{ default: 'generic', readonly: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + + // // End of base cases + + // { + // code: 'let a: { foo: Array }[] = [];', + // output: 'let a: { foo: Bar[] }[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + // line: 1, + // column: 15, + // }, + // ], + // }, + // { + // code: 'let a: Array<{ foo: Bar[] }> = [];', + // output: 'let a: Array<{ foo: Array }> = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + // line: 1, + // column: 21, + // }, + // ], + // }, + // { + // code: 'let a: Array<{ foo: Foo | Bar[] }> = [];', + // output: 'let a: Array<{ foo: Foo | Array }> = [];', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + // line: 1, + // column: 27, + // }, + // ], + // }, + // { + // code: 'function foo(a: Array): Array {}', + // output: 'function foo(a: Bar[]): Bar[] {}', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + // line: 1, + // column: 17, + // }, + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + // line: 1, + // column: 30, + // }, + // ], + // }, + // { + // code: 'let x: Array = [undefined] as undefined[];', + // output: 'let x: undefined[] = [undefined] as undefined[];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: "let y: string[] = >['2'];", + // output: "let y: string[] = ['2'];", + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + // line: 1, + // column: 20, + // }, + // ], + // }, + // { + // code: "let z: Array = [3, '4'];", + // output: "let z: any[] = [3, '4'];", + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: "let ya = [[1, '2']] as [number, string][];", + // output: "let ya = [[1, '2']] as Array<[number, string]>;", + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 24, + // }, + // ], + // }, + // { + // code: 'type Arr = Array;', + // output: 'type Arr = T[];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 15, + // }, + // ], + // }, + // { + // code: ` + // // Ignore user defined aliases + // let yyyy: Arr>[]> = [[[['2']]]]; + // `, + // output: ` + // // Ignore user defined aliases + // let yyyy: Arr>>> = [[[['2']]]]; + // `, + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 3, + // column: 15, + // }, + // ], + // }, + // { + // code: ` + // interface ArrayClass { + // foo: Array; + // bar: T[]; + // baz: Arr; + // xyz: this[]; + // } + // `, + // output: ` + // interface ArrayClass { + // foo: T[]; + // bar: T[]; + // baz: Arr; + // xyz: this[]; + // } + // `, + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 3, + // column: 8, + // }, + // ], + // }, + // { + // code: ` + // function barFunction(bar: ArrayClass[]) { + // return bar.map(e => e.bar); + // } + // `, + // output: ` + // function barFunction(bar: Array>) { + // return bar.map(e => e.bar); + // } + // `, + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 2, + // column: 27, + // }, + // ], + // }, + // { + // code: 'let barVar: ((c: number) => number)[];', + // output: 'let barVar: Array<(c: number) => number>;', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 13, + // }, + // ], + // }, + // { + // code: 'type barUnion = (string | number | boolean)[];', + // output: 'type barUnion = Array;', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 17, + // }, + // ], + // }, + // { + // code: 'type barIntersection = (string & number)[];', + // output: 'type barIntersection = Array;', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 24, + // }, + // ], + // }, + // { + // code: "let v: Array = [{ bar: 'bar' }];", + // output: "let v: fooName.BarType[] = [{ bar: 'bar' }];", + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { + // className: 'Array', + // readonlyPrefix: '', + // type: 'fooName.BarType', + // }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: "let w: fooName.BazType[] = [['baz']];", + // output: "let w: Array> = [['baz']];", + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringGenericSimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let x: Array = [undefined] as undefined[];', + // output: 'let x: undefined[] = [undefined] as undefined[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: "let y: string[] = >['2'];", + // output: "let y: string[] = ['2'];", + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + // line: 1, + // column: 20, + // }, + // ], + // }, + // { + // code: "let z: Array = [3, '4'];", + // output: "let z: any[] = [3, '4'];", + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'type Arr = Array;', + // output: 'type Arr = T[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 15, + // }, + // ], + // }, + // { + // code: ` + // // Ignore user defined aliases + // let yyyy: Arr>[]> = [[[['2']]]]; + // `, + // output: ` + // // Ignore user defined aliases + // let yyyy: Arr[][]> = [[[['2']]]]; + // `, + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 3, + // column: 15, + // }, + // ], + // }, + // { + // code: ` + // interface ArrayClass { + // foo: Array; + // bar: T[]; + // baz: Arr; + // } + // `, + // output: ` + // interface ArrayClass { + // foo: T[]; + // bar: T[]; + // baz: Arr; + // } + // `, + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 3, + // column: 8, + // }, + // ], + // }, + // { + // code: ` + // function fooFunction(foo: Array>) { + // return foo.map(e => e.foo); + // } + // `, + // output: ` + // function fooFunction(foo: ArrayClass[]) { + // return foo.map(e => e.foo); + // } + // `, + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 2, + // column: 27, + // }, + // ], + // }, + // { + // code: 'let fooVar: Array<(c: number) => number>;', + // output: 'let fooVar: ((c: number) => number)[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 13, + // }, + // ], + // }, + // { + // code: 'type fooUnion = Array;', + // output: 'type fooUnion = (string | number | boolean)[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 17, + // }, + // ], + // }, + // { + // code: 'type fooIntersection = Array;', + // output: 'type fooIntersection = (string & number)[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 24, + // }, + // ], + // }, + // { + // code: 'let x: Array;', + // output: 'let x: any[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let x: Array<>;', + // output: 'let x: any[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let x: Array;', + // output: 'let x: any[];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let x: Array<>;', + // output: 'let x: any[];', + // options: [{ default: 'array-simple' }], + // errors: [ + // { + // messageId: 'errorStringArraySimple', + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: 'let x: Array = [1] as number[];', + // output: 'let x: Array = [1] as Array;', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + // line: 1, + // column: 31, + // }, + // ], + // }, + // { + // code: "let y: string[] = >['2'];", + // output: "let y: Array = >['2'];", + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + // line: 1, + // column: 8, + // }, + // ], + // }, + // { + // code: "let ya = [[1, '2']] as [number, string][];", + // output: "let ya = [[1, '2']] as Array<[number, string]>;", + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 24, + // }, + // ], + // }, + // { + // code: ` + // // Ignore user defined aliases + // let yyyy: Arr>[]> = [[[['2']]]]; + // `, + // output: ` + // // Ignore user defined aliases + // let yyyy: Arr>>> = [[[['2']]]]; + // `, + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 3, + // column: 15, + // }, + // ], + // }, + // { + // code: ` + // interface ArrayClass { + // foo: Array; + // bar: T[]; + // baz: Arr; + // } + // `, + // output: ` + // interface ArrayClass { + // foo: Array; + // bar: Array; + // baz: Arr; + // } + // `, + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 4, + // column: 8, + // }, + // ], + // }, + // { + // code: ` + // function barFunction(bar: ArrayClass[]) { + // return bar.map(e => e.bar); + // } + // `, + // output: ` + // function barFunction(bar: Array>) { + // return bar.map(e => e.bar); + // } + // `, + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 2, + // column: 27, + // }, + // ], + // }, + // { + // code: 'let barVar: ((c: number) => number)[];', + // output: 'let barVar: Array<(c: number) => number>;', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 13, + // }, + // ], + // }, + // { + // code: 'type barUnion = (string | number | boolean)[];', + // output: 'type barUnion = Array;', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 17, + // }, + // ], + // }, + // { + // code: 'type barIntersection = (string & number)[];', + // output: 'type barIntersection = Array;', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 24, + // }, + // ], + // }, + // { + // code: ` + // interface FooInterface { + // '.bar': { baz: string[] }; + // } + // `, + // output: ` + // interface FooInterface { + // '.bar': { baz: Array }; + // } + // `, + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + // line: 3, + // column: 18, + // }, + // ], + // }, + // { + // // https://github.com/typescript-eslint/typescript-eslint/issues/172 + // code: 'type Unwrap = T extends Array ? E : T;', + // output: 'type Unwrap = T extends (infer E)[] ? E : T;', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 28, + // }, + // ], + // }, + // { + // // https://github.com/typescript-eslint/typescript-eslint/issues/172 + // code: 'type Unwrap = T extends (infer E)[] ? E : T;', + // output: 'type Unwrap = T extends Array ? E : T;', + // options: [{ default: 'generic' }], + // errors: [ + // { + // messageId: 'errorStringGeneric', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 28, + // }, + // ], + // }, + // { + // code: 'type Foo = ReadonlyArray[];', + // output: 'type Foo = (readonly object[])[];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'object', + // }, + // line: 1, + // column: 12, + // }, + // ], + // }, + // { + // code: 'const foo: Array void> = [];', + // output: 'const foo: (new (...args: any[]) => void)[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + // line: 1, + // column: 12, + // }, + // ], + // }, + // { + // code: 'const foo: ReadonlyArray void> = [];', + // output: 'const foo: readonly (new (...args: any[]) => void)[] = [];', + // options: [{ default: 'array' }], + // errors: [ + // { + // messageId: 'errorStringArray', + // data: { + // className: 'ReadonlyArray', + // readonlyPrefix: 'readonly ', + // type: 'T', + // }, + // line: 1, + // column: 12, + // }, + // ], + // }, { code: "const x: Readonly = ['a', 'b'];", output: "const x: readonly string[] = ['a', 'b'];", @@ -1936,255 +1940,255 @@ interface FooInterface { ], }); -// -- eslint rule tester is not working with multi-pass -// https://github.com/eslint/eslint/issues/11187 -describe('array-type (nested)', () => { - const linter = new TSESLint.Linter(); - linter.defineRule('array-type', rule); - linter.defineParser('@typescript-eslint/parser', parser); +// // -- eslint rule tester is not working with multi-pass +// // https://github.com/eslint/eslint/issues/11187 +// describe('array-type (nested)', () => { +// const linter = new TSESLint.Linter(); +// linter.defineRule('array-type', rule); +// linter.defineParser('@typescript-eslint/parser', parser); - describe('should deeply fix correctly', () => { - function testOutput( - defaultOption: OptionString, - code: string, - output: string, - readonlyOption?: OptionString, - ): void { - it(code, () => { - const result = linter.verifyAndFix( - code, - { - rules: { - 'array-type': [ - 2, - { default: defaultOption, readonly: readonlyOption }, - ], - }, - parser: '@typescript-eslint/parser', - }, - { - fix: true, - }, - ); +// describe('should deeply fix correctly', () => { +// function testOutput( +// defaultOption: OptionString, +// code: string, +// output: string, +// readonlyOption?: OptionString, +// ): void { +// it(code, () => { +// const result = linter.verifyAndFix( +// code, +// { +// rules: { +// 'array-type': [ +// 2, +// { default: defaultOption, readonly: readonlyOption }, +// ], +// }, +// parser: '@typescript-eslint/parser', +// }, +// { +// fix: true, +// }, +// ); - expect(result.messages).toHaveLength(0); - expect(result.output).toBe(output); - }); - } +// expect(result.messages).toHaveLength(0); +// expect(result.output).toBe(output); +// }); +// } - testOutput( - 'array', - 'let a: ({ foo: Array | Array> })[] = []', - 'let a: ({ foo: (Bar[] | any[])[] })[] = []', - ); - testOutput( - 'array', - ` -class Foo>> extends Bar> implements Baz> { - private s: Array +// testOutput( +// 'array', +// 'let a: ({ foo: Array | Array> })[] = []', +// 'let a: ({ foo: (Bar[] | any[])[] })[] = []', +// ); +// testOutput( +// 'array', +// ` +// class Foo>> extends Bar> implements Baz> { +// private s: Array - constructor (p: Array) { - return new Array() - } -} - `, - ` -class Foo extends Bar implements Baz { - private s: T[] +// constructor (p: Array) { +// return new Array() +// } +// } +// `, +// ` +// class Foo extends Bar implements Baz { +// private s: T[] - constructor (p: T[]) { - return new Array() - } -} - `, - ); - testOutput( - 'array', - ` -interface WorkingArray { - outerProperty: Array< - { innerPropertyOne: string } & { innerPropertyTwo: string } - >; -} +// constructor (p: T[]) { +// return new Array() +// } +// } +// `, +// ); +// testOutput( +// 'array', +// ` +// interface WorkingArray { +// outerProperty: Array< +// { innerPropertyOne: string } & { innerPropertyTwo: string } +// >; +// } -interface BrokenArray { - outerProperty: Array< - ({ innerPropertyOne: string } & { innerPropertyTwo: string }) - >; -} - `, - ` -interface WorkingArray { - outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -} +// interface BrokenArray { +// outerProperty: Array< +// ({ innerPropertyOne: string } & { innerPropertyTwo: string }) +// >; +// } +// `, +// ` +// interface WorkingArray { +// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +// } -interface BrokenArray { - outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -} - `, - ); - testOutput( - 'array', - ` -type WorkingArray = { - outerProperty: Array< - { innerPropertyOne: string } & { innerPropertyTwo: string } - >; -} +// interface BrokenArray { +// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +// } +// `, +// ); +// testOutput( +// 'array', +// ` +// type WorkingArray = { +// outerProperty: Array< +// { innerPropertyOne: string } & { innerPropertyTwo: string } +// >; +// } -type BrokenArray = { - outerProperty: Array< - ({ innerPropertyOne: string } & { innerPropertyTwo: string }) - >; -} - `, - ` -type WorkingArray = { - outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -} +// type BrokenArray = { +// outerProperty: Array< +// ({ innerPropertyOne: string } & { innerPropertyTwo: string }) +// >; +// } +// `, +// ` +// type WorkingArray = { +// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +// } -type BrokenArray = { - outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -} - `, - ); - testOutput( - 'array', - 'const a: Array<(string|number)>;', - 'const a: (string|number)[];', - ); - testOutput( - 'array-simple', - 'let xx: Array> = [[1, 2], [3]];', - 'let xx: number[][] = [[1, 2], [3]];', - ); - testOutput( - 'array', - 'let xx: Array> = [[1, 2], [3]];', - 'let xx: number[][] = [[1, 2], [3]];', - ); - testOutput( - 'generic', - 'let yy: number[][] = [[4, 5], [6]];', - 'let yy: Array> = [[4, 5], [6]];', - ); - testOutput('array', 'let a: Array<>[] = [];', 'let a: any[][] = [];'); - testOutput('array', 'let a: Array = [];', 'let a: any[][] = [];'); - testOutput( - 'array', - 'let a: Array[] = [];', - 'let a: any[][][] = [];', - ); +// type BrokenArray = { +// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +// } +// `, +// ); +// testOutput( +// 'array', +// 'const a: Array<(string|number)>;', +// 'const a: (string|number)[];', +// ); +// testOutput( +// 'array-simple', +// 'let xx: Array> = [[1, 2], [3]];', +// 'let xx: number[][] = [[1, 2], [3]];', +// ); +// testOutput( +// 'array', +// 'let xx: Array> = [[1, 2], [3]];', +// 'let xx: number[][] = [[1, 2], [3]];', +// ); +// testOutput( +// 'generic', +// 'let yy: number[][] = [[4, 5], [6]];', +// 'let yy: Array> = [[4, 5], [6]];', +// ); +// testOutput('array', 'let a: Array<>[] = [];', 'let a: any[][] = [];'); +// testOutput('array', 'let a: Array = [];', 'let a: any[][] = [];'); +// testOutput( +// 'array', +// 'let a: Array[] = [];', +// 'let a: any[][][] = [];', +// ); - testOutput( - 'generic', - 'let a: Array<>[] = [];', - 'let a: Array> = [];', - ); - testOutput( - 'generic', - 'let a: Array = [];', - 'let a: Array> = [];', - ); - testOutput( - 'generic', - 'let a: Array[] = [];', - 'let a: Array>> = [];', - ); - testOutput( - 'generic', - 'let a: Array[] = [];', - 'let a: Array> = [];', - ); - testOutput( - 'generic', - 'let a: Array[] = [];', - 'let a: Array>> = [];', - ); +// testOutput( +// 'generic', +// 'let a: Array<>[] = [];', +// 'let a: Array> = [];', +// ); +// testOutput( +// 'generic', +// 'let a: Array = [];', +// 'let a: Array> = [];', +// ); +// testOutput( +// 'generic', +// 'let a: Array[] = [];', +// 'let a: Array>> = [];', +// ); +// testOutput( +// 'generic', +// 'let a: Array[] = [];', +// 'let a: Array> = [];', +// ); +// testOutput( +// 'generic', +// 'let a: Array[] = [];', +// 'let a: Array>> = [];', +// ); - // readonly - testOutput( - 'generic', - 'let x: readonly number[][]', - 'let x: ReadonlyArray>', - ); - testOutput( - 'generic', - 'let x: readonly (readonly number[])[]', - 'let x: ReadonlyArray>', - ); - testOutput( - 'array', - 'let x: ReadonlyArray>', - 'let x: readonly number[][]', - ); - testOutput( - 'array', - 'let x: ReadonlyArray>', - 'let x: readonly (readonly number[])[]', - ); - testOutput( - 'array', - 'let x: ReadonlyArray', - 'let x: readonly (readonly number[])[]', - ); - testOutput( - 'array', - 'let a: readonly number[][] = []', - 'let a: ReadonlyArray = []', - 'generic', - ); - testOutput( - 'generic', - 'let a: readonly number[][] = []', - 'let a: readonly Array[] = []', - 'array', - ); - testOutput( - 'generic', - 'type T = readonly(string)[]', - 'type T = ReadonlyArray', - 'generic', - ); - testOutput( - 'generic', - 'let a: readonly(readonly string[])[] = []', - 'let a: ReadonlyArray> = []', - 'generic', - ); - testOutput( - 'generic', - 'type T = readonly(readonly string[])[]', - 'type T = ReadonlyArray>', - 'generic', - ); - testOutput( - 'generic', - 'type T = readonly (readonly string[])[]', - 'type T = ReadonlyArray>', - 'generic', - ); - testOutput( - 'generic', - 'type T = readonly (readonly string[])[]', - 'type T = ReadonlyArray>', - 'generic', - ); - }); -}); +// // readonly +// testOutput( +// 'generic', +// 'let x: readonly number[][]', +// 'let x: ReadonlyArray>', +// ); +// testOutput( +// 'generic', +// 'let x: readonly (readonly number[])[]', +// 'let x: ReadonlyArray>', +// ); +// testOutput( +// 'array', +// 'let x: ReadonlyArray>', +// 'let x: readonly number[][]', +// ); +// testOutput( +// 'array', +// 'let x: ReadonlyArray>', +// 'let x: readonly (readonly number[])[]', +// ); +// testOutput( +// 'array', +// 'let x: ReadonlyArray', +// 'let x: readonly (readonly number[])[]', +// ); +// testOutput( +// 'array', +// 'let a: readonly number[][] = []', +// 'let a: ReadonlyArray = []', +// 'generic', +// ); +// testOutput( +// 'generic', +// 'let a: readonly number[][] = []', +// 'let a: readonly Array[] = []', +// 'array', +// ); +// testOutput( +// 'generic', +// 'type T = readonly(string)[]', +// 'type T = ReadonlyArray', +// 'generic', +// ); +// testOutput( +// 'generic', +// 'let a: readonly(readonly string[])[] = []', +// 'let a: ReadonlyArray> = []', +// 'generic', +// ); +// testOutput( +// 'generic', +// 'type T = readonly(readonly string[])[]', +// 'type T = ReadonlyArray>', +// 'generic', +// ); +// testOutput( +// 'generic', +// 'type T = readonly (readonly string[])[]', +// 'type T = ReadonlyArray>', +// 'generic', +// ); +// testOutput( +// 'generic', +// 'type T = readonly (readonly string[])[]', +// 'type T = ReadonlyArray>', +// 'generic', +// ); +// }); +// }); -describe('schema validation', () => { - // https://github.com/typescript-eslint/typescript-eslint/issues/6852 - test("array-type does not accept 'simple-array' option", () => { - if (areOptionsValid(rule, [{ default: 'simple-array' }])) { - throw new Error(`Options succeeded validation for bad options`); - } - }); +// describe('schema validation', () => { +// // https://github.com/typescript-eslint/typescript-eslint/issues/6852 +// test("array-type does not accept 'simple-array' option", () => { +// if (areOptionsValid(rule, [{ default: 'simple-array' }])) { +// throw new Error(`Options succeeded validation for bad options`); +// } +// }); - // https://github.com/typescript-eslint/typescript-eslint/issues/6892 - test('array-type does not accept non object option', () => { - if (areOptionsValid(rule, ['array'])) { - throw new Error(`Options succeeded validation for bad options`); - } - }); -}); +// // https://github.com/typescript-eslint/typescript-eslint/issues/6892 +// test('array-type does not accept non object option', () => { +// if (areOptionsValid(rule, ['array'])) { +// throw new Error(`Options succeeded validation for bad options`); +// } +// }); +// }); From dbcd788aaa43eda78edeb30b12677af93371b3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Sun, 7 Apr 2024 12:30:39 +0900 Subject: [PATCH 06/13] fix: revert comment line and fix error position --- .../tests/rules/array-type.test.ts | 4286 ++++++++--------- 1 file changed, 2143 insertions(+), 2143 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/array-type.test.ts b/packages/eslint-plugin/tests/rules/array-type.test.ts index 8373191898ee..479ef5fcbc7e 100644 --- a/packages/eslint-plugin/tests/rules/array-type.test.ts +++ b/packages/eslint-plugin/tests/rules/array-type.test.ts @@ -13,1915 +13,1915 @@ const ruleTester = new RuleTester({ ruleTester.run('array-type', rule, { valid: [ // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: readonly number[] = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly bigint[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: readonly (string | bigint)[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: readonly bigint[] = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array' }], + }, + { + code: 'let a: (string | number)[] = [];', + options: [{ default: 'array' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array' }], + }, + { + code: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'array' }], + }, + { + code: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array', readonly: 'array' }], + }, + { + code: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + }, + { + code: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'generic' }], + }, + { + code: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'generic' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array-simple' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'array-simple' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + }, + { + code: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + }, + { + code: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: readonly number[] = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: readonly bigint[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: readonly (string | bigint)[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: readonly bigint[] = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, + { + code: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + }, - // // End of base cases + // End of base cases - // { - // code: 'let a = new Array();', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let a: { foo: Bar[] }[] = [];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'function foo(a: Array): Array {}', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let yy: number[][] = [[4, 5], [6]];', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: ` - // function fooFunction(foo: Array>) { - // return foo.map(e => e.foo); - // } - // `, - // options: [{ default: 'array-simple' }], - // }, - // { - // code: ` - // function bazFunction(baz: Arr>) { - // return baz.map(e => e.baz); - // } - // `, - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let fooVar: Array<(c: number) => number>;', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'type fooUnion = Array;', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'type fooIntersection = Array;', - // options: [{ default: 'array-simple' }], - // }, - // { - // code: ` - // namespace fooName { - // type BarType = { bar: string }; - // type BazType = Arr; - // } - // `, - // options: [{ default: 'array-simple' }], - // }, - // { - // code: ` - // interface FooInterface { - // '.bar': { baz: string[] }; - // } - // `, - // options: [{ default: 'array-simple' }], - // }, - // { - // code: 'let yy: number[][] = [[4, 5], [6]];', - // options: [{ default: 'array' }], - // }, - // { - // code: "let ya = [[1, '2']] as [number, string][];", - // options: [{ default: 'array' }], - // }, - // { - // code: ` - // function barFunction(bar: ArrayClass[]) { - // return bar.map(e => e.bar); - // } - // `, - // options: [{ default: 'array' }], - // }, - // { - // code: ` - // function bazFunction(baz: Arr>) { - // return baz.map(e => e.baz); - // } - // `, - // options: [{ default: 'array' }], - // }, - // { - // code: 'let barVar: ((c: number) => number)[];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'type barUnion = (string | number | boolean)[];', - // options: [{ default: 'array' }], - // }, - // { - // code: 'type barIntersection = (string & number)[];', - // options: [{ default: 'array' }], - // }, - // { - // code: ` - // interface FooInterface { - // '.bar': { baz: string[] }; - // } - // `, - // options: [{ default: 'array' }], - // }, - // { - // // https://github.com/typescript-eslint/typescript-eslint/issues/172 - // code: 'type Unwrap = T extends (infer E)[] ? E : T;', - // options: [{ default: 'array' }], - // }, - // { - // code: 'let xx: Array> = [[1, 2], [3]];', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'type Arr = Array;', - // options: [{ default: 'generic' }], - // }, - // { - // code: ` - // function fooFunction(foo: Array>) { - // return foo.map(e => e.foo); - // } - // `, - // options: [{ default: 'generic' }], - // }, - // { - // code: ` - // function bazFunction(baz: Arr>) { - // return baz.map(e => e.baz); - // } - // `, - // options: [{ default: 'generic' }], - // }, - // { - // code: 'let fooVar: Array<(c: number) => number>;', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'type fooUnion = Array;', - // options: [{ default: 'generic' }], - // }, - // { - // code: 'type fooIntersection = Array;', - // options: [{ default: 'generic' }], - // }, - // { - // // https://github.com/typescript-eslint/typescript-eslint/issues/172 - // code: 'type Unwrap = T extends Array ? E : T;', - // options: [{ default: 'generic' }], - // }, + { + code: 'let a = new Array();', + options: [{ default: 'array' }], + }, + { + code: 'let a: { foo: Bar[] }[] = [];', + options: [{ default: 'array' }], + }, + { + code: 'function foo(a: Array): Array {}', + options: [{ default: 'generic' }], + }, + { + code: 'let yy: number[][] = [[4, 5], [6]];', + options: [{ default: 'array-simple' }], + }, + { + code: ` + function fooFunction(foo: Array>) { + return foo.map(e => e.foo); + } + `, + options: [{ default: 'array-simple' }], + }, + { + code: ` + function bazFunction(baz: Arr>) { + return baz.map(e => e.baz); + } + `, + options: [{ default: 'array-simple' }], + }, + { + code: 'let fooVar: Array<(c: number) => number>;', + options: [{ default: 'array-simple' }], + }, + { + code: 'type fooUnion = Array;', + options: [{ default: 'array-simple' }], + }, + { + code: 'type fooIntersection = Array;', + options: [{ default: 'array-simple' }], + }, + { + code: ` + namespace fooName { + type BarType = { bar: string }; + type BazType = Arr; + } + `, + options: [{ default: 'array-simple' }], + }, + { + code: ` + interface FooInterface { + '.bar': { baz: string[] }; + } + `, + options: [{ default: 'array-simple' }], + }, + { + code: 'let yy: number[][] = [[4, 5], [6]];', + options: [{ default: 'array' }], + }, + { + code: "let ya = [[1, '2']] as [number, string][];", + options: [{ default: 'array' }], + }, + { + code: ` + function barFunction(bar: ArrayClass[]) { + return bar.map(e => e.bar); + } + `, + options: [{ default: 'array' }], + }, + { + code: ` + function bazFunction(baz: Arr>) { + return baz.map(e => e.baz); + } + `, + options: [{ default: 'array' }], + }, + { + code: 'let barVar: ((c: number) => number)[];', + options: [{ default: 'array' }], + }, + { + code: 'type barUnion = (string | number | boolean)[];', + options: [{ default: 'array' }], + }, + { + code: 'type barIntersection = (string & number)[];', + options: [{ default: 'array' }], + }, + { + code: ` + interface FooInterface { + '.bar': { baz: string[] }; + } + `, + options: [{ default: 'array' }], + }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends (infer E)[] ? E : T;', + options: [{ default: 'array' }], + }, + { + code: 'let xx: Array> = [[1, 2], [3]];', + options: [{ default: 'generic' }], + }, + { + code: 'type Arr = Array;', + options: [{ default: 'generic' }], + }, + { + code: ` + function fooFunction(foo: Array>) { + return foo.map(e => e.foo); + } + `, + options: [{ default: 'generic' }], + }, + { + code: ` + function bazFunction(baz: Arr>) { + return baz.map(e => e.baz); + } + `, + options: [{ default: 'generic' }], + }, + { + code: 'let fooVar: Array<(c: number) => number>;', + options: [{ default: 'generic' }], + }, + { + code: 'type fooUnion = Array;', + options: [{ default: 'generic' }], + }, + { + code: 'type fooIntersection = Array;', + options: [{ default: 'generic' }], + }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends Array ? E : T;', + options: [{ default: 'generic' }], + }, - // // nested readonly - // { - // code: 'let a: ReadonlyArray = [[]];', - // options: [{ default: 'array', readonly: 'generic' }], - // }, - // { - // code: 'let a: readonly Array[] = [[]];', - // options: [{ default: 'generic', readonly: 'array' }], - // }, + // nested readonly + { + code: 'let a: ReadonlyArray = [[]];', + options: [{ default: 'array', readonly: 'generic' }], + }, + { + code: 'let a: readonly Array[] = [[]];', + options: [{ default: 'generic', readonly: 'array' }], + }, + { + code: 'let a: Readonly = [];', + options: [{ default: 'generic', readonly: 'array' }], + }, + ], + invalid: [ + // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: (string | number)[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: (string | number)[] = [];', + options: [{ default: 'array', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly number[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'array-simple', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: Array = [];', + output: 'let a: number[] = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly number[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'array-simple', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: number[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly number[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: number[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly (string | number)[] = [];', + options: [{ default: 'generic', readonly: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: number[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly number[] = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: number[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | number)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly number[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'number', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | number)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: bigint[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'bigint' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | bigint)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: ReadonlyArray = [];', + output: 'let a: readonly bigint[] = [];', + options: [{ default: 'generic', readonly: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'bigint', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: (string | bigint)[] = [];', + output: 'let a: Array = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly bigint[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'bigint', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let a: readonly (string | bigint)[] = [];', + output: 'let a: ReadonlyArray = [];', + options: [{ default: 'generic', readonly: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 8, + }, + ], + }, + + // End of base cases + + { + code: 'let a: { foo: Array }[] = [];', + output: 'let a: { foo: Bar[] }[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + line: 1, + column: 15, + }, + ], + }, + { + code: 'let a: Array<{ foo: Bar[] }> = [];', + output: 'let a: Array<{ foo: Array }> = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + line: 1, + column: 21, + }, + ], + }, + { + code: 'let a: Array<{ foo: Foo | Bar[] }> = [];', + output: 'let a: Array<{ foo: Foo | Array }> = [];', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + line: 1, + column: 27, + }, + ], + }, + { + code: 'function foo(a: Array): Array {}', + output: 'function foo(a: Bar[]): Bar[] {}', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + line: 1, + column: 17, + }, + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, + line: 1, + column: 30, + }, + ], + }, + { + code: 'let x: Array = [undefined] as undefined[];', + output: 'let x: undefined[] = [undefined] as undefined[];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, + line: 1, + column: 8, + }, + ], + }, + { + code: "let y: string[] = >['2'];", + output: "let y: string[] = ['2'];", + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + line: 1, + column: 20, + }, + ], + }, + { + code: "let z: Array = [3, '4'];", + output: "let z: any[] = [3, '4'];", + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + line: 1, + column: 8, + }, + ], + }, + { + code: "let ya = [[1, '2']] as [number, string][];", + output: "let ya = [[1, '2']] as Array<[number, string]>;", + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 24, + }, + ], + }, + { + code: 'type Arr = Array;', + output: 'type Arr = T[];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 15, + }, + ], + }, { - code: 'let a: Readonly = [];', - options: [{ default: 'generic', readonly: 'array' }], + code: ` + // Ignore user defined aliases + let yyyy: Arr>[]> = [[[['2']]]]; + `, + output: ` + // Ignore user defined aliases + let yyyy: Arr>>> = [[[['2']]]]; + `, + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 3, + column: 19, + }, + ], + }, + { + code: ` + interface ArrayClass { + foo: Array; + bar: T[]; + baz: Arr; + xyz: this[]; + } + `, + output: ` + interface ArrayClass { + foo: T[]; + bar: T[]; + baz: Arr; + xyz: this[]; + } + `, + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 3, + column: 12, + }, + ], + }, + { + code: ` + function barFunction(bar: ArrayClass[]) { + return bar.map(e => e.bar); + } + `, + output: ` + function barFunction(bar: Array>) { + return bar.map(e => e.bar); + } + `, + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 2, + column: 31, + }, + ], + }, + { + code: 'let barVar: ((c: number) => number)[];', + output: 'let barVar: Array<(c: number) => number>;', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 13, + }, + ], + }, + { + code: 'type barUnion = (string | number | boolean)[];', + output: 'type barUnion = Array;', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 17, + }, + ], + }, + { + code: 'type barIntersection = (string & number)[];', + output: 'type barIntersection = Array;', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 24, + }, + ], + }, + { + code: "let v: Array = [{ bar: 'bar' }];", + output: "let v: fooName.BarType[] = [{ bar: 'bar' }];", + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { + className: 'Array', + readonlyPrefix: '', + type: 'fooName.BarType', + }, + line: 1, + column: 8, + }, + ], + }, + { + code: "let w: fooName.BazType[] = [['baz']];", + output: "let w: Array> = [['baz']];", + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringGenericSimple', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let x: Array = [undefined] as undefined[];', + output: 'let x: undefined[] = [undefined] as undefined[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, + line: 1, + column: 8, + }, + ], + }, + { + code: "let y: string[] = >['2'];", + output: "let y: string[] = ['2'];", + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + line: 1, + column: 20, + }, + ], + }, + { + code: "let z: Array = [3, '4'];", + output: "let z: any[] = [3, '4'];", + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'type Arr = Array;', + output: 'type Arr = T[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 15, + }, + ], + }, + { + code: ` + // Ignore user defined aliases + let yyyy: Arr>[]> = [[[['2']]]]; + `, + output: ` + // Ignore user defined aliases + let yyyy: Arr[][]> = [[[['2']]]]; + `, + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 3, + column: 19, + }, + ], + }, + { + code: ` + interface ArrayClass { + foo: Array; + bar: T[]; + baz: Arr; + } + `, + output: ` + interface ArrayClass { + foo: T[]; + bar: T[]; + baz: Arr; + } + `, + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 3, + column: 12, + }, + ], + }, + { + code: ` + function fooFunction(foo: Array>) { + return foo.map(e => e.foo); + } + `, + output: ` + function fooFunction(foo: ArrayClass[]) { + return foo.map(e => e.foo); + } + `, + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 2, + column: 31, + }, + ], + }, + { + code: 'let fooVar: Array<(c: number) => number>;', + output: 'let fooVar: ((c: number) => number)[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 13, + }, + ], + }, + { + code: 'type fooUnion = Array;', + output: 'type fooUnion = (string | number | boolean)[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 17, + }, + ], + }, + { + code: 'type fooIntersection = Array;', + output: 'type fooIntersection = (string & number)[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 24, + }, + ], + }, + { + code: 'let x: Array;', + output: 'let x: any[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let x: Array<>;', + output: 'let x: any[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let x: Array;', + output: 'let x: any[];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + data: { className: 'Array', readonlyPrefix: '', type: 'any' }, + line: 1, + column: 8, + }, + ], + }, + { + code: 'let x: Array<>;', + output: 'let x: any[];', + options: [{ default: 'array-simple' }], + errors: [ + { + messageId: 'errorStringArraySimple', + line: 1, + column: 8, + }, + ], + }, + { + code: 'let x: Array = [1] as number[];', + output: 'let x: Array = [1] as Array;', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'number' }, + line: 1, + column: 31, + }, + ], + }, + { + code: "let y: string[] = >['2'];", + output: "let y: Array = >['2'];", + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + line: 1, + column: 8, + }, + ], + }, + { + code: "let ya = [[1, '2']] as [number, string][];", + output: "let ya = [[1, '2']] as Array<[number, string]>;", + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 24, + }, + ], + }, + { + code: ` + // Ignore user defined aliases + let yyyy: Arr>[]> = [[[['2']]]]; + `, + output: ` + // Ignore user defined aliases + let yyyy: Arr>>> = [[[['2']]]]; + `, + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 3, + column: 19, + }, + ], + }, + { + code: ` + interface ArrayClass { + foo: Array; + bar: T[]; + baz: Arr; + } + `, + output: ` + interface ArrayClass { + foo: Array; + bar: Array; + baz: Arr; + } + `, + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 4, + column: 12, + }, + ], + }, + { + code: ` + function barFunction(bar: ArrayClass[]) { + return bar.map(e => e.bar); + } + `, + output: ` + function barFunction(bar: Array>) { + return bar.map(e => e.bar); + } + `, + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 2, + column: 31, + }, + ], + }, + { + code: 'let barVar: ((c: number) => number)[];', + output: 'let barVar: Array<(c: number) => number>;', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 13, + }, + ], + }, + { + code: 'type barUnion = (string | number | boolean)[];', + output: 'type barUnion = Array;', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 17, + }, + ], + }, + { + code: 'type barIntersection = (string & number)[];', + output: 'type barIntersection = Array;', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 24, + }, + ], + }, + { + code: ` + interface FooInterface { + '.bar': { baz: string[] }; + } + `, + output: ` + interface FooInterface { + '.bar': { baz: Array }; + } + `, + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'string' }, + line: 3, + column: 22, + }, + ], + }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends Array ? E : T;', + output: 'type Unwrap = T extends (infer E)[] ? E : T;', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 28, + }, + ], + }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends (infer E)[] ? E : T;', + output: 'type Unwrap = T extends Array ? E : T;', + options: [{ default: 'generic' }], + errors: [ + { + messageId: 'errorStringGeneric', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 28, + }, + ], + }, + { + code: 'type Foo = ReadonlyArray[];', + output: 'type Foo = (readonly object[])[];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'object', + }, + line: 1, + column: 12, + }, + ], + }, + { + code: 'const foo: Array void> = [];', + output: 'const foo: (new (...args: any[]) => void)[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { className: 'Array', readonlyPrefix: '', type: 'T' }, + line: 1, + column: 12, + }, + ], + }, + { + code: 'const foo: ReadonlyArray void> = [];', + output: 'const foo: readonly (new (...args: any[]) => void)[] = [];', + options: [{ default: 'array' }], + errors: [ + { + messageId: 'errorStringArray', + data: { + className: 'ReadonlyArray', + readonlyPrefix: 'readonly ', + type: 'T', + }, + line: 1, + column: 12, + }, + ], }, - ], - invalid: [ - // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: (string | number)[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: (string | number)[] = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly number[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'array-simple', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: Array = [];', - // output: 'let a: number[] = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly number[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'array-simple', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: number[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly number[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: number[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly (string | number)[] = [];', - // options: [{ default: 'generic', readonly: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: number[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly number[] = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: number[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | number)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly number[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'number', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | number)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: bigint[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'bigint' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | bigint)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: ReadonlyArray = [];', - // output: 'let a: readonly bigint[] = [];', - // options: [{ default: 'generic', readonly: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'bigint', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: (string | bigint)[] = [];', - // output: 'let a: Array = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly bigint[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'bigint', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let a: readonly (string | bigint)[] = [];', - // output: 'let a: ReadonlyArray = [];', - // options: [{ default: 'generic', readonly: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - - // // End of base cases - - // { - // code: 'let a: { foo: Array }[] = [];', - // output: 'let a: { foo: Bar[] }[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - // line: 1, - // column: 15, - // }, - // ], - // }, - // { - // code: 'let a: Array<{ foo: Bar[] }> = [];', - // output: 'let a: Array<{ foo: Array }> = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - // line: 1, - // column: 21, - // }, - // ], - // }, - // { - // code: 'let a: Array<{ foo: Foo | Bar[] }> = [];', - // output: 'let a: Array<{ foo: Foo | Array }> = [];', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - // line: 1, - // column: 27, - // }, - // ], - // }, - // { - // code: 'function foo(a: Array): Array {}', - // output: 'function foo(a: Bar[]): Bar[] {}', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - // line: 1, - // column: 17, - // }, - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'Bar' }, - // line: 1, - // column: 30, - // }, - // ], - // }, - // { - // code: 'let x: Array = [undefined] as undefined[];', - // output: 'let x: undefined[] = [undefined] as undefined[];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: "let y: string[] = >['2'];", - // output: "let y: string[] = ['2'];", - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - // line: 1, - // column: 20, - // }, - // ], - // }, - // { - // code: "let z: Array = [3, '4'];", - // output: "let z: any[] = [3, '4'];", - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: "let ya = [[1, '2']] as [number, string][];", - // output: "let ya = [[1, '2']] as Array<[number, string]>;", - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 24, - // }, - // ], - // }, - // { - // code: 'type Arr = Array;', - // output: 'type Arr = T[];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 15, - // }, - // ], - // }, - // { - // code: ` - // // Ignore user defined aliases - // let yyyy: Arr>[]> = [[[['2']]]]; - // `, - // output: ` - // // Ignore user defined aliases - // let yyyy: Arr>>> = [[[['2']]]]; - // `, - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 3, - // column: 15, - // }, - // ], - // }, - // { - // code: ` - // interface ArrayClass { - // foo: Array; - // bar: T[]; - // baz: Arr; - // xyz: this[]; - // } - // `, - // output: ` - // interface ArrayClass { - // foo: T[]; - // bar: T[]; - // baz: Arr; - // xyz: this[]; - // } - // `, - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 3, - // column: 8, - // }, - // ], - // }, - // { - // code: ` - // function barFunction(bar: ArrayClass[]) { - // return bar.map(e => e.bar); - // } - // `, - // output: ` - // function barFunction(bar: Array>) { - // return bar.map(e => e.bar); - // } - // `, - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 2, - // column: 27, - // }, - // ], - // }, - // { - // code: 'let barVar: ((c: number) => number)[];', - // output: 'let barVar: Array<(c: number) => number>;', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 13, - // }, - // ], - // }, - // { - // code: 'type barUnion = (string | number | boolean)[];', - // output: 'type barUnion = Array;', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 17, - // }, - // ], - // }, - // { - // code: 'type barIntersection = (string & number)[];', - // output: 'type barIntersection = Array;', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 24, - // }, - // ], - // }, - // { - // code: "let v: Array = [{ bar: 'bar' }];", - // output: "let v: fooName.BarType[] = [{ bar: 'bar' }];", - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { - // className: 'Array', - // readonlyPrefix: '', - // type: 'fooName.BarType', - // }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: "let w: fooName.BazType[] = [['baz']];", - // output: "let w: Array> = [['baz']];", - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringGenericSimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let x: Array = [undefined] as undefined[];', - // output: 'let x: undefined[] = [undefined] as undefined[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'undefined' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: "let y: string[] = >['2'];", - // output: "let y: string[] = ['2'];", - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - // line: 1, - // column: 20, - // }, - // ], - // }, - // { - // code: "let z: Array = [3, '4'];", - // output: "let z: any[] = [3, '4'];", - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'type Arr = Array;', - // output: 'type Arr = T[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 15, - // }, - // ], - // }, - // { - // code: ` - // // Ignore user defined aliases - // let yyyy: Arr>[]> = [[[['2']]]]; - // `, - // output: ` - // // Ignore user defined aliases - // let yyyy: Arr[][]> = [[[['2']]]]; - // `, - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 3, - // column: 15, - // }, - // ], - // }, - // { - // code: ` - // interface ArrayClass { - // foo: Array; - // bar: T[]; - // baz: Arr; - // } - // `, - // output: ` - // interface ArrayClass { - // foo: T[]; - // bar: T[]; - // baz: Arr; - // } - // `, - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 3, - // column: 8, - // }, - // ], - // }, - // { - // code: ` - // function fooFunction(foo: Array>) { - // return foo.map(e => e.foo); - // } - // `, - // output: ` - // function fooFunction(foo: ArrayClass[]) { - // return foo.map(e => e.foo); - // } - // `, - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 2, - // column: 27, - // }, - // ], - // }, - // { - // code: 'let fooVar: Array<(c: number) => number>;', - // output: 'let fooVar: ((c: number) => number)[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 13, - // }, - // ], - // }, - // { - // code: 'type fooUnion = Array;', - // output: 'type fooUnion = (string | number | boolean)[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 17, - // }, - // ], - // }, - // { - // code: 'type fooIntersection = Array;', - // output: 'type fooIntersection = (string & number)[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 24, - // }, - // ], - // }, - // { - // code: 'let x: Array;', - // output: 'let x: any[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let x: Array<>;', - // output: 'let x: any[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let x: Array;', - // output: 'let x: any[];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // data: { className: 'Array', readonlyPrefix: '', type: 'any' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let x: Array<>;', - // output: 'let x: any[];', - // options: [{ default: 'array-simple' }], - // errors: [ - // { - // messageId: 'errorStringArraySimple', - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: 'let x: Array = [1] as number[];', - // output: 'let x: Array = [1] as Array;', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'number' }, - // line: 1, - // column: 31, - // }, - // ], - // }, - // { - // code: "let y: string[] = >['2'];", - // output: "let y: Array = >['2'];", - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - // line: 1, - // column: 8, - // }, - // ], - // }, - // { - // code: "let ya = [[1, '2']] as [number, string][];", - // output: "let ya = [[1, '2']] as Array<[number, string]>;", - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 24, - // }, - // ], - // }, - // { - // code: ` - // // Ignore user defined aliases - // let yyyy: Arr>[]> = [[[['2']]]]; - // `, - // output: ` - // // Ignore user defined aliases - // let yyyy: Arr>>> = [[[['2']]]]; - // `, - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 3, - // column: 15, - // }, - // ], - // }, - // { - // code: ` - // interface ArrayClass { - // foo: Array; - // bar: T[]; - // baz: Arr; - // } - // `, - // output: ` - // interface ArrayClass { - // foo: Array; - // bar: Array; - // baz: Arr; - // } - // `, - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 4, - // column: 8, - // }, - // ], - // }, - // { - // code: ` - // function barFunction(bar: ArrayClass[]) { - // return bar.map(e => e.bar); - // } - // `, - // output: ` - // function barFunction(bar: Array>) { - // return bar.map(e => e.bar); - // } - // `, - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 2, - // column: 27, - // }, - // ], - // }, - // { - // code: 'let barVar: ((c: number) => number)[];', - // output: 'let barVar: Array<(c: number) => number>;', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 13, - // }, - // ], - // }, - // { - // code: 'type barUnion = (string | number | boolean)[];', - // output: 'type barUnion = Array;', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 17, - // }, - // ], - // }, - // { - // code: 'type barIntersection = (string & number)[];', - // output: 'type barIntersection = Array;', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 24, - // }, - // ], - // }, - // { - // code: ` - // interface FooInterface { - // '.bar': { baz: string[] }; - // } - // `, - // output: ` - // interface FooInterface { - // '.bar': { baz: Array }; - // } - // `, - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'string' }, - // line: 3, - // column: 18, - // }, - // ], - // }, - // { - // // https://github.com/typescript-eslint/typescript-eslint/issues/172 - // code: 'type Unwrap = T extends Array ? E : T;', - // output: 'type Unwrap = T extends (infer E)[] ? E : T;', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 28, - // }, - // ], - // }, - // { - // // https://github.com/typescript-eslint/typescript-eslint/issues/172 - // code: 'type Unwrap = T extends (infer E)[] ? E : T;', - // output: 'type Unwrap = T extends Array ? E : T;', - // options: [{ default: 'generic' }], - // errors: [ - // { - // messageId: 'errorStringGeneric', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 28, - // }, - // ], - // }, - // { - // code: 'type Foo = ReadonlyArray[];', - // output: 'type Foo = (readonly object[])[];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'object', - // }, - // line: 1, - // column: 12, - // }, - // ], - // }, - // { - // code: 'const foo: Array void> = [];', - // output: 'const foo: (new (...args: any[]) => void)[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { className: 'Array', readonlyPrefix: '', type: 'T' }, - // line: 1, - // column: 12, - // }, - // ], - // }, - // { - // code: 'const foo: ReadonlyArray void> = [];', - // output: 'const foo: readonly (new (...args: any[]) => void)[] = [];', - // options: [{ default: 'array' }], - // errors: [ - // { - // messageId: 'errorStringArray', - // data: { - // className: 'ReadonlyArray', - // readonlyPrefix: 'readonly ', - // type: 'T', - // }, - // line: 1, - // column: 12, - // }, - // ], - // }, { code: "const x: Readonly = ['a', 'b'];", output: "const x: readonly string[] = ['a', 'b'];", @@ -1940,255 +1940,255 @@ ruleTester.run('array-type', rule, { ], }); -// // -- eslint rule tester is not working with multi-pass -// // https://github.com/eslint/eslint/issues/11187 -// describe('array-type (nested)', () => { -// const linter = new TSESLint.Linter(); -// linter.defineRule('array-type', rule); -// linter.defineParser('@typescript-eslint/parser', parser); +// -- eslint rule tester is not working with multi-pass +// https://github.com/eslint/eslint/issues/11187 +describe('array-type (nested)', () => { + const linter = new TSESLint.Linter(); + linter.defineRule('array-type', rule); + linter.defineParser('@typescript-eslint/parser', parser); -// describe('should deeply fix correctly', () => { -// function testOutput( -// defaultOption: OptionString, -// code: string, -// output: string, -// readonlyOption?: OptionString, -// ): void { -// it(code, () => { -// const result = linter.verifyAndFix( -// code, -// { -// rules: { -// 'array-type': [ -// 2, -// { default: defaultOption, readonly: readonlyOption }, -// ], -// }, -// parser: '@typescript-eslint/parser', -// }, -// { -// fix: true, -// }, -// ); + describe('should deeply fix correctly', () => { + function testOutput( + defaultOption: OptionString, + code: string, + output: string, + readonlyOption?: OptionString, + ): void { + it(code, () => { + const result = linter.verifyAndFix( + code, + { + rules: { + 'array-type': [ + 2, + { default: defaultOption, readonly: readonlyOption }, + ], + }, + parser: '@typescript-eslint/parser', + }, + { + fix: true, + }, + ); -// expect(result.messages).toHaveLength(0); -// expect(result.output).toBe(output); -// }); -// } + expect(result.messages).toHaveLength(0); + expect(result.output).toBe(output); + }); + } -// testOutput( -// 'array', -// 'let a: ({ foo: Array | Array> })[] = []', -// 'let a: ({ foo: (Bar[] | any[])[] })[] = []', -// ); -// testOutput( -// 'array', -// ` -// class Foo>> extends Bar> implements Baz> { -// private s: Array + testOutput( + 'array', + 'let a: ({ foo: Array | Array> })[] = []', + 'let a: ({ foo: (Bar[] | any[])[] })[] = []', + ); + testOutput( + 'array', + ` +class Foo>> extends Bar> implements Baz> { + private s: Array -// constructor (p: Array) { -// return new Array() -// } -// } -// `, -// ` -// class Foo extends Bar implements Baz { -// private s: T[] + constructor (p: Array) { + return new Array() + } +} + `, + ` +class Foo extends Bar implements Baz { + private s: T[] -// constructor (p: T[]) { -// return new Array() -// } -// } -// `, -// ); -// testOutput( -// 'array', -// ` -// interface WorkingArray { -// outerProperty: Array< -// { innerPropertyOne: string } & { innerPropertyTwo: string } -// >; -// } + constructor (p: T[]) { + return new Array() + } +} + `, + ); + testOutput( + 'array', + ` +interface WorkingArray { + outerProperty: Array< + { innerPropertyOne: string } & { innerPropertyTwo: string } + >; +} -// interface BrokenArray { -// outerProperty: Array< -// ({ innerPropertyOne: string } & { innerPropertyTwo: string }) -// >; -// } -// `, -// ` -// interface WorkingArray { -// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -// } +interface BrokenArray { + outerProperty: Array< + ({ innerPropertyOne: string } & { innerPropertyTwo: string }) + >; +} + `, + ` +interface WorkingArray { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} -// interface BrokenArray { -// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -// } -// `, -// ); -// testOutput( -// 'array', -// ` -// type WorkingArray = { -// outerProperty: Array< -// { innerPropertyOne: string } & { innerPropertyTwo: string } -// >; -// } +interface BrokenArray { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} + `, + ); + testOutput( + 'array', + ` +type WorkingArray = { + outerProperty: Array< + { innerPropertyOne: string } & { innerPropertyTwo: string } + >; +} -// type BrokenArray = { -// outerProperty: Array< -// ({ innerPropertyOne: string } & { innerPropertyTwo: string }) -// >; -// } -// `, -// ` -// type WorkingArray = { -// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -// } +type BrokenArray = { + outerProperty: Array< + ({ innerPropertyOne: string } & { innerPropertyTwo: string }) + >; +} + `, + ` +type WorkingArray = { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} -// type BrokenArray = { -// outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; -// } -// `, -// ); -// testOutput( -// 'array', -// 'const a: Array<(string|number)>;', -// 'const a: (string|number)[];', -// ); -// testOutput( -// 'array-simple', -// 'let xx: Array> = [[1, 2], [3]];', -// 'let xx: number[][] = [[1, 2], [3]];', -// ); -// testOutput( -// 'array', -// 'let xx: Array> = [[1, 2], [3]];', -// 'let xx: number[][] = [[1, 2], [3]];', -// ); -// testOutput( -// 'generic', -// 'let yy: number[][] = [[4, 5], [6]];', -// 'let yy: Array> = [[4, 5], [6]];', -// ); -// testOutput('array', 'let a: Array<>[] = [];', 'let a: any[][] = [];'); -// testOutput('array', 'let a: Array = [];', 'let a: any[][] = [];'); -// testOutput( -// 'array', -// 'let a: Array[] = [];', -// 'let a: any[][][] = [];', -// ); +type BrokenArray = { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} + `, + ); + testOutput( + 'array', + 'const a: Array<(string|number)>;', + 'const a: (string|number)[];', + ); + testOutput( + 'array-simple', + 'let xx: Array> = [[1, 2], [3]];', + 'let xx: number[][] = [[1, 2], [3]];', + ); + testOutput( + 'array', + 'let xx: Array> = [[1, 2], [3]];', + 'let xx: number[][] = [[1, 2], [3]];', + ); + testOutput( + 'generic', + 'let yy: number[][] = [[4, 5], [6]];', + 'let yy: Array> = [[4, 5], [6]];', + ); + testOutput('array', 'let a: Array<>[] = [];', 'let a: any[][] = [];'); + testOutput('array', 'let a: Array = [];', 'let a: any[][] = [];'); + testOutput( + 'array', + 'let a: Array[] = [];', + 'let a: any[][][] = [];', + ); -// testOutput( -// 'generic', -// 'let a: Array<>[] = [];', -// 'let a: Array> = [];', -// ); -// testOutput( -// 'generic', -// 'let a: Array = [];', -// 'let a: Array> = [];', -// ); -// testOutput( -// 'generic', -// 'let a: Array[] = [];', -// 'let a: Array>> = [];', -// ); -// testOutput( -// 'generic', -// 'let a: Array[] = [];', -// 'let a: Array> = [];', -// ); -// testOutput( -// 'generic', -// 'let a: Array[] = [];', -// 'let a: Array>> = [];', -// ); + testOutput( + 'generic', + 'let a: Array<>[] = [];', + 'let a: Array> = [];', + ); + testOutput( + 'generic', + 'let a: Array = [];', + 'let a: Array> = [];', + ); + testOutput( + 'generic', + 'let a: Array[] = [];', + 'let a: Array>> = [];', + ); + testOutput( + 'generic', + 'let a: Array[] = [];', + 'let a: Array> = [];', + ); + testOutput( + 'generic', + 'let a: Array[] = [];', + 'let a: Array>> = [];', + ); -// // readonly -// testOutput( -// 'generic', -// 'let x: readonly number[][]', -// 'let x: ReadonlyArray>', -// ); -// testOutput( -// 'generic', -// 'let x: readonly (readonly number[])[]', -// 'let x: ReadonlyArray>', -// ); -// testOutput( -// 'array', -// 'let x: ReadonlyArray>', -// 'let x: readonly number[][]', -// ); -// testOutput( -// 'array', -// 'let x: ReadonlyArray>', -// 'let x: readonly (readonly number[])[]', -// ); -// testOutput( -// 'array', -// 'let x: ReadonlyArray', -// 'let x: readonly (readonly number[])[]', -// ); -// testOutput( -// 'array', -// 'let a: readonly number[][] = []', -// 'let a: ReadonlyArray = []', -// 'generic', -// ); -// testOutput( -// 'generic', -// 'let a: readonly number[][] = []', -// 'let a: readonly Array[] = []', -// 'array', -// ); -// testOutput( -// 'generic', -// 'type T = readonly(string)[]', -// 'type T = ReadonlyArray', -// 'generic', -// ); -// testOutput( -// 'generic', -// 'let a: readonly(readonly string[])[] = []', -// 'let a: ReadonlyArray> = []', -// 'generic', -// ); -// testOutput( -// 'generic', -// 'type T = readonly(readonly string[])[]', -// 'type T = ReadonlyArray>', -// 'generic', -// ); -// testOutput( -// 'generic', -// 'type T = readonly (readonly string[])[]', -// 'type T = ReadonlyArray>', -// 'generic', -// ); -// testOutput( -// 'generic', -// 'type T = readonly (readonly string[])[]', -// 'type T = ReadonlyArray>', -// 'generic', -// ); -// }); -// }); + // readonly + testOutput( + 'generic', + 'let x: readonly number[][]', + 'let x: ReadonlyArray>', + ); + testOutput( + 'generic', + 'let x: readonly (readonly number[])[]', + 'let x: ReadonlyArray>', + ); + testOutput( + 'array', + 'let x: ReadonlyArray>', + 'let x: readonly number[][]', + ); + testOutput( + 'array', + 'let x: ReadonlyArray>', + 'let x: readonly (readonly number[])[]', + ); + testOutput( + 'array', + 'let x: ReadonlyArray', + 'let x: readonly (readonly number[])[]', + ); + testOutput( + 'array', + 'let a: readonly number[][] = []', + 'let a: ReadonlyArray = []', + 'generic', + ); + testOutput( + 'generic', + 'let a: readonly number[][] = []', + 'let a: readonly Array[] = []', + 'array', + ); + testOutput( + 'generic', + 'type T = readonly(string)[]', + 'type T = ReadonlyArray', + 'generic', + ); + testOutput( + 'generic', + 'let a: readonly(readonly string[])[] = []', + 'let a: ReadonlyArray> = []', + 'generic', + ); + testOutput( + 'generic', + 'type T = readonly(readonly string[])[]', + 'type T = ReadonlyArray>', + 'generic', + ); + testOutput( + 'generic', + 'type T = readonly (readonly string[])[]', + 'type T = ReadonlyArray>', + 'generic', + ); + testOutput( + 'generic', + 'type T = readonly (readonly string[])[]', + 'type T = ReadonlyArray>', + 'generic', + ); + }); +}); -// describe('schema validation', () => { -// // https://github.com/typescript-eslint/typescript-eslint/issues/6852 -// test("array-type does not accept 'simple-array' option", () => { -// if (areOptionsValid(rule, [{ default: 'simple-array' }])) { -// throw new Error(`Options succeeded validation for bad options`); -// } -// }); +describe('schema validation', () => { + // https://github.com/typescript-eslint/typescript-eslint/issues/6852 + test("array-type does not accept 'simple-array' option", () => { + if (areOptionsValid(rule, [{ default: 'simple-array' }])) { + throw new Error(`Options succeeded validation for bad options`); + } + }); -// // https://github.com/typescript-eslint/typescript-eslint/issues/6892 -// test('array-type does not accept non object option', () => { -// if (areOptionsValid(rule, ['array'])) { -// throw new Error(`Options succeeded validation for bad options`); -// } -// }); -// }); + // https://github.com/typescript-eslint/typescript-eslint/issues/6892 + test('array-type does not accept non object option', () => { + if (areOptionsValid(rule, ['array'])) { + throw new Error(`Options succeeded validation for bad options`); + } + }); +}); From 8a361fe28fbd0a732431034b9c9efd2de4a67651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Sun, 28 Apr 2024 16:11:18 +0900 Subject: [PATCH 07/13] fix: fix indent, docs description --- .../eslint-plugin/docs/rules/array-type.mdx | 4 +- .../tests/rules/array-type.test.ts | 214 +++++++++--------- 2 files changed, 109 insertions(+), 109 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/array-type.mdx b/packages/eslint-plugin/docs/rules/array-type.mdx index ad51dca3dca6..cbfb35f44d1d 100644 --- a/packages/eslint-plugin/docs/rules/array-type.mdx +++ b/packages/eslint-plugin/docs/rules/array-type.mdx @@ -42,8 +42,8 @@ const y: readonly string[] = ['a', 'b']; ### `"generic"` -Always use `Array` or `ReadonlyArray` or `Readonly` for all array types. -However, `readonly T[]` is modified to `ReadonlyArray`. +Always use `Array`, `ReadonlyArray`, or `Readonly` for all array types. +`readonly T[]` will be modified to `ReadonlyArray`. diff --git a/packages/eslint-plugin/tests/rules/array-type.test.ts b/packages/eslint-plugin/tests/rules/array-type.test.ts index 479ef5fcbc7e..4855e9b7175e 100644 --- a/packages/eslint-plugin/tests/rules/array-type.test.ts +++ b/packages/eslint-plugin/tests/rules/array-type.test.ts @@ -254,18 +254,18 @@ ruleTester.run('array-type', rule, { }, { code: ` - function fooFunction(foo: Array>) { - return foo.map(e => e.foo); - } - `, +function fooFunction(foo: Array>) { + return foo.map(e => e.foo); +} + `, options: [{ default: 'array-simple' }], }, { code: ` - function bazFunction(baz: Arr>) { - return baz.map(e => e.baz); - } - `, +function bazFunction(baz: Arr>) { + return baz.map(e => e.baz); +} + `, options: [{ default: 'array-simple' }], }, { @@ -282,19 +282,19 @@ ruleTester.run('array-type', rule, { }, { code: ` - namespace fooName { - type BarType = { bar: string }; - type BazType = Arr; - } - `, +namespace fooName { + type BarType = { bar: string }; + type BazType = Arr; +} + `, options: [{ default: 'array-simple' }], }, { code: ` - interface FooInterface { - '.bar': { baz: string[] }; - } - `, +interface FooInterface { + '.bar': { baz: string[] }; +} + `, options: [{ default: 'array-simple' }], }, { @@ -307,18 +307,18 @@ ruleTester.run('array-type', rule, { }, { code: ` - function barFunction(bar: ArrayClass[]) { - return bar.map(e => e.bar); - } - `, +function barFunction(bar: ArrayClass[]) { + return bar.map(e => e.bar); +} + `, options: [{ default: 'array' }], }, { code: ` - function bazFunction(baz: Arr>) { - return baz.map(e => e.baz); - } - `, +function bazFunction(baz: Arr>) { + return baz.map(e => e.baz); +} + `, options: [{ default: 'array' }], }, { @@ -335,10 +335,10 @@ ruleTester.run('array-type', rule, { }, { code: ` - interface FooInterface { - '.bar': { baz: string[] }; - } - `, +interface FooInterface { + '.bar': { baz: string[] }; +} + `, options: [{ default: 'array' }], }, { @@ -356,18 +356,18 @@ ruleTester.run('array-type', rule, { }, { code: ` - function fooFunction(foo: Array>) { - return foo.map(e => e.foo); - } - `, +function fooFunction(foo: Array>) { + return foo.map(e => e.foo); +} + `, options: [{ default: 'generic' }], }, { code: ` - function bazFunction(baz: Arr>) { - return baz.map(e => e.baz); - } - `, +function bazFunction(baz: Arr>) { + return baz.map(e => e.baz); +} + `, options: [{ default: 'generic' }], }, { @@ -1342,12 +1342,12 @@ ruleTester.run('array-type', rule, { }, { code: ` - // Ignore user defined aliases - let yyyy: Arr>[]> = [[[['2']]]]; - `, +// Ignore user defined aliases +let yyyy: Arr>[]> = [[[['2']]]]; + `, output: ` - // Ignore user defined aliases - let yyyy: Arr>>> = [[[['2']]]]; +// Ignore user defined aliases +let yyyy: Arr>>> = [[[['2']]]]; `, options: [{ default: 'array-simple' }], errors: [ @@ -1361,20 +1361,20 @@ ruleTester.run('array-type', rule, { }, { code: ` - interface ArrayClass { - foo: Array; - bar: T[]; - baz: Arr; - xyz: this[]; - } - `, +interface ArrayClass { + foo: Array; + bar: T[]; + baz: Arr; + xyz: this[]; +} + `, output: ` - interface ArrayClass { - foo: T[]; - bar: T[]; - baz: Arr; - xyz: this[]; - } +interface ArrayClass { + foo: T[]; + bar: T[]; + baz: Arr; + xyz: this[]; +} `, options: [{ default: 'array-simple' }], errors: [ @@ -1388,14 +1388,14 @@ ruleTester.run('array-type', rule, { }, { code: ` - function barFunction(bar: ArrayClass[]) { - return bar.map(e => e.bar); - } - `, +function barFunction(bar: ArrayClass[]) { + return bar.map(e => e.bar); +} + `, output: ` - function barFunction(bar: Array>) { - return bar.map(e => e.bar); - } +function barFunction(bar: Array>) { + return bar.map(e => e.bar); +} `, options: [{ default: 'array-simple' }], errors: [ @@ -1530,12 +1530,12 @@ ruleTester.run('array-type', rule, { }, { code: ` - // Ignore user defined aliases - let yyyy: Arr>[]> = [[[['2']]]]; - `, +// Ignore user defined aliases +let yyyy: Arr>[]> = [[[['2']]]]; + `, output: ` - // Ignore user defined aliases - let yyyy: Arr[][]> = [[[['2']]]]; +// Ignore user defined aliases +let yyyy: Arr[][]> = [[[['2']]]]; `, options: [{ default: 'array' }], errors: [ @@ -1549,12 +1549,12 @@ ruleTester.run('array-type', rule, { }, { code: ` - interface ArrayClass { - foo: Array; - bar: T[]; - baz: Arr; - } - `, +interface ArrayClass { + foo: Array; + bar: T[]; + baz: Arr; +} + `, output: ` interface ArrayClass { foo: T[]; @@ -1574,10 +1574,10 @@ ruleTester.run('array-type', rule, { }, { code: ` - function fooFunction(foo: Array>) { - return foo.map(e => e.foo); - } - `, +function fooFunction(foo: Array>) { + return foo.map(e => e.foo); +} + `, output: ` function fooFunction(foo: ArrayClass[]) { return foo.map(e => e.foo); @@ -1724,12 +1724,12 @@ ruleTester.run('array-type', rule, { }, { code: ` - // Ignore user defined aliases - let yyyy: Arr>[]> = [[[['2']]]]; - `, +// Ignore user defined aliases +let yyyy: Arr>[]> = [[[['2']]]]; + `, output: ` - // Ignore user defined aliases - let yyyy: Arr>>> = [[[['2']]]]; +// Ignore user defined aliases +let yyyy: Arr>>> = [[[['2']]]]; `, options: [{ default: 'generic' }], errors: [ @@ -1743,18 +1743,18 @@ ruleTester.run('array-type', rule, { }, { code: ` - interface ArrayClass { - foo: Array; - bar: T[]; - baz: Arr; - } - `, +interface ArrayClass { + foo: Array; + bar: T[]; + baz: Arr; +} + `, output: ` - interface ArrayClass { - foo: Array; - bar: Array; - baz: Arr; - } +interface ArrayClass { + foo: Array; + bar: Array; + baz: Arr; +} `, options: [{ default: 'generic' }], errors: [ @@ -1768,14 +1768,14 @@ ruleTester.run('array-type', rule, { }, { code: ` - function barFunction(bar: ArrayClass[]) { - return bar.map(e => e.bar); - } - `, +function barFunction(bar: ArrayClass[]) { + return bar.map(e => e.bar); +} + `, output: ` - function barFunction(bar: Array>) { - return bar.map(e => e.bar); - } +function barFunction(bar: Array>) { + return bar.map(e => e.bar); +} `, options: [{ default: 'generic' }], errors: [ @@ -1828,14 +1828,14 @@ ruleTester.run('array-type', rule, { }, { code: ` - interface FooInterface { - '.bar': { baz: string[] }; - } - `, +interface FooInterface { + '.bar': { baz: string[] }; +} + `, output: ` - interface FooInterface { - '.bar': { baz: Array }; - } +interface FooInterface { + '.bar': { baz: Array }; +} `, options: [{ default: 'generic' }], errors: [ From 1a59bd02e8f505e4c659df41f1f2cb00d4c726e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Sun, 28 Apr 2024 16:30:11 +0900 Subject: [PATCH 08/13] fix: revert indent --- .../tests/rules/array-type.test.ts | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/array-type.test.ts b/packages/eslint-plugin/tests/rules/array-type.test.ts index 4855e9b7175e..d5b2f93f3153 100644 --- a/packages/eslint-plugin/tests/rules/array-type.test.ts +++ b/packages/eslint-plugin/tests/rules/array-type.test.ts @@ -1348,7 +1348,7 @@ let yyyy: Arr>[]> = [[[['2']]]]; output: ` // Ignore user defined aliases let yyyy: Arr>>> = [[[['2']]]]; - `, + `, options: [{ default: 'array-simple' }], errors: [ { @@ -1375,7 +1375,7 @@ interface ArrayClass { baz: Arr; xyz: this[]; } - `, + `, options: [{ default: 'array-simple' }], errors: [ { @@ -1396,7 +1396,7 @@ function barFunction(bar: ArrayClass[]) { function barFunction(bar: Array>) { return bar.map(e => e.bar); } - `, + `, options: [{ default: 'array-simple' }], errors: [ { @@ -1536,7 +1536,7 @@ let yyyy: Arr>[]> = [[[['2']]]]; output: ` // Ignore user defined aliases let yyyy: Arr[][]> = [[[['2']]]]; - `, + `, options: [{ default: 'array' }], errors: [ { @@ -1556,12 +1556,12 @@ interface ArrayClass { } `, output: ` - interface ArrayClass { - foo: T[]; - bar: T[]; - baz: Arr; - } - `, +interface ArrayClass { + foo: T[]; + bar: T[]; + baz: Arr; +} + `, options: [{ default: 'array' }], errors: [ { @@ -1579,10 +1579,10 @@ function fooFunction(foo: Array>) { } `, output: ` - function fooFunction(foo: ArrayClass[]) { - return foo.map(e => e.foo); - } - `, +function fooFunction(foo: ArrayClass[]) { + return foo.map(e => e.foo); +} + `, options: [{ default: 'array' }], errors: [ { @@ -1730,7 +1730,7 @@ let yyyy: Arr>[]> = [[[['2']]]]; output: ` // Ignore user defined aliases let yyyy: Arr>>> = [[[['2']]]]; - `, + `, options: [{ default: 'generic' }], errors: [ { @@ -1755,7 +1755,7 @@ interface ArrayClass { bar: Array; baz: Arr; } - `, + `, options: [{ default: 'generic' }], errors: [ { @@ -1776,7 +1776,7 @@ function barFunction(bar: ArrayClass[]) { function barFunction(bar: Array>) { return bar.map(e => e.bar); } - `, + `, options: [{ default: 'generic' }], errors: [ { @@ -1836,7 +1836,7 @@ interface FooInterface { interface FooInterface { '.bar': { baz: Array }; } - `, + `, options: [{ default: 'generic' }], errors: [ { From 8fc0b82f4867efb70ba03a10155fd1a5407939fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Fri, 3 May 2024 22:51:55 +0900 Subject: [PATCH 09/13] fix: add exception and delete not related PR --- .../eslint-plugin/src/rules/array-type.ts | 4 +++- .../tests/rules/array-type.test.ts | 24 +++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index 4da45554bfcc..26b5c270914e 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -204,7 +204,9 @@ export default createRule({ node.typeName.name === 'Array' || node.typeName.name === 'ReadonlyArray' || node.typeName.name === 'Readonly' - ) + ) || + (node.typeName.name === 'Readonly' && + node.typeArguments?.params[0].type !== AST_NODE_TYPES.TSArrayType) ) { return; } diff --git a/packages/eslint-plugin/tests/rules/array-type.test.ts b/packages/eslint-plugin/tests/rules/array-type.test.ts index d5b2f93f3153..3ee5720d32c9 100644 --- a/packages/eslint-plugin/tests/rules/array-type.test.ts +++ b/packages/eslint-plugin/tests/rules/array-type.test.ts @@ -401,6 +401,10 @@ function bazFunction(baz: Arr>) { code: 'let a: Readonly = [];', options: [{ default: 'generic', readonly: 'array' }], }, + { + code: "const x: Readonly = 'a';", + options: [{ default: 'array' }], + }, ], invalid: [ // Base cases from https://github.com/typescript-eslint/typescript-eslint/issues/2323#issuecomment-663977655 @@ -1355,7 +1359,7 @@ let yyyy: Arr>>> = [[[['2']]]]; messageId: 'errorStringGenericSimple', data: { className: 'Array', readonlyPrefix: '', type: 'T' }, line: 3, - column: 19, + column: 15, }, ], }, @@ -1382,7 +1386,7 @@ interface ArrayClass { messageId: 'errorStringArraySimple', data: { className: 'Array', readonlyPrefix: '', type: 'T' }, line: 3, - column: 12, + column: 8, }, ], }, @@ -1403,7 +1407,7 @@ function barFunction(bar: Array>) { messageId: 'errorStringGenericSimple', data: { className: 'Array', readonlyPrefix: '', type: 'T' }, line: 2, - column: 31, + column: 27, }, ], }, @@ -1543,7 +1547,7 @@ let yyyy: Arr[][]> = [[[['2']]]]; messageId: 'errorStringArray', data: { className: 'Array', readonlyPrefix: '', type: 'T' }, line: 3, - column: 19, + column: 15, }, ], }, @@ -1568,7 +1572,7 @@ interface ArrayClass { messageId: 'errorStringArray', data: { className: 'Array', readonlyPrefix: '', type: 'T' }, line: 3, - column: 12, + column: 8, }, ], }, @@ -1589,7 +1593,7 @@ function fooFunction(foo: ArrayClass[]) { messageId: 'errorStringArray', data: { className: 'Array', readonlyPrefix: '', type: 'T' }, line: 2, - column: 31, + column: 27, }, ], }, @@ -1737,7 +1741,7 @@ let yyyy: Arr>>> = [[[['2']]]]; messageId: 'errorStringGeneric', data: { className: 'Array', readonlyPrefix: '', type: 'T' }, line: 3, - column: 19, + column: 15, }, ], }, @@ -1762,7 +1766,7 @@ interface ArrayClass { messageId: 'errorStringGeneric', data: { className: 'Array', readonlyPrefix: '', type: 'T' }, line: 4, - column: 12, + column: 8, }, ], }, @@ -1783,7 +1787,7 @@ function barFunction(bar: Array>) { messageId: 'errorStringGeneric', data: { className: 'Array', readonlyPrefix: '', type: 'T' }, line: 2, - column: 31, + column: 27, }, ], }, @@ -1843,7 +1847,7 @@ interface FooInterface { messageId: 'errorStringGeneric', data: { className: 'Array', readonlyPrefix: '', type: 'string' }, line: 3, - column: 22, + column: 18, }, ], }, From f3e3cff768693dd4558788f1faa95dfa7fa018bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Sat, 11 May 2024 23:10:42 +0900 Subject: [PATCH 10/13] docs: move no correct example to incorrect example --- packages/eslint-plugin/docs/rules/array-type.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/docs/rules/array-type.mdx b/packages/eslint-plugin/docs/rules/array-type.mdx index cbfb35f44d1d..da6b39a29637 100644 --- a/packages/eslint-plugin/docs/rules/array-type.mdx +++ b/packages/eslint-plugin/docs/rules/array-type.mdx @@ -51,6 +51,7 @@ Always use `Array`, `ReadonlyArray`, or `Readonly` for all array type ```ts option='{ "default": "generic" }' const x: string[] = ['a', 'b']; const y: readonly string[] = ['a', 'b']; +const z: Readonly = ['a', 'b']; ``` @@ -59,7 +60,7 @@ const y: readonly string[] = ['a', 'b']; ```ts option='{ "default": "generic" }' const x: Array = ['a', 'b']; const y: ReadonlyArray = ['a', 'b']; -const z: Readonly = ['a', 'b']; +const z: Readonly> = ['a', 'b']; ``` From ae91e9448fc23e05aa344b8ca6726904e17b8338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Sat, 11 May 2024 23:48:32 +0900 Subject: [PATCH 11/13] docs: fix example document --- packages/eslint-plugin/docs/rules/array-type.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/array-type.mdx b/packages/eslint-plugin/docs/rules/array-type.mdx index da6b39a29637..d3238025e47d 100644 --- a/packages/eslint-plugin/docs/rules/array-type.mdx +++ b/packages/eslint-plugin/docs/rules/array-type.mdx @@ -42,8 +42,8 @@ const y: readonly string[] = ['a', 'b']; ### `"generic"` -Always use `Array`, `ReadonlyArray`, or `Readonly` for all array types. -`readonly T[]` will be modified to `ReadonlyArray`. +Always use `Array`, `ReadonlyArray`, or `Readonly>` for all array types. +`readonly T[]` will be modified to `ReadonlyArray` and `Readonly` will be modified to `Readonly`. From ce7960b45b3d501295f958bc41dc0dadee7a5736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Sat, 22 Jun 2024 10:02:48 +0900 Subject: [PATCH 12/13] fix: lint error because of array-type --- packages/rule-tester/src/RuleTester.ts | 6 +++--- packages/rule-tester/src/types/InvalidTestCase.ts | 2 +- packages/rule-tester/src/types/ValidTestCase.ts | 2 +- packages/rule-tester/src/types/index.ts | 4 ++-- packages/utils/src/ts-eslint/RuleTester.ts | 10 +++++----- .../plugins/generated-rule-docs/RuleDocsPage.ts | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/rule-tester/src/RuleTester.ts b/packages/rule-tester/src/RuleTester.ts index 324700fa264a..b5c2a9ff8b35 100644 --- a/packages/rule-tester/src/RuleTester.ts +++ b/packages/rule-tester/src/RuleTester.ts @@ -146,16 +146,16 @@ export class RuleTester extends TestFramework { /** * Adds the `only` property to a test to run it in isolation. */ - static only>( + static only( item: ValidTestCase | string, ): ValidTestCase; /** * Adds the `only` property to a test to run it in isolation. */ - static only>( + static only( item: InvalidTestCase, ): InvalidTestCase; - static only>( + static only( item: | InvalidTestCase | ValidTestCase diff --git a/packages/rule-tester/src/types/InvalidTestCase.ts b/packages/rule-tester/src/types/InvalidTestCase.ts index 96754682cc4b..fb10e85b0f4d 100644 --- a/packages/rule-tester/src/types/InvalidTestCase.ts +++ b/packages/rule-tester/src/types/InvalidTestCase.ts @@ -63,7 +63,7 @@ export interface TestCaseError { export interface InvalidTestCase< MessageIds extends string, - Options extends Readonly, + Options extends readonly unknown[], > extends ValidTestCase { /** * Expected errors. diff --git a/packages/rule-tester/src/types/ValidTestCase.ts b/packages/rule-tester/src/types/ValidTestCase.ts index c65b416917ca..c4aa40456a6a 100644 --- a/packages/rule-tester/src/types/ValidTestCase.ts +++ b/packages/rule-tester/src/types/ValidTestCase.ts @@ -6,7 +6,7 @@ import type { import type { DependencyConstraint } from './DependencyConstraint'; -export interface ValidTestCase> { +export interface ValidTestCase { /** * Name for the test case. */ diff --git a/packages/rule-tester/src/types/index.ts b/packages/rule-tester/src/types/index.ts index 7169810b11e2..93dad319d936 100644 --- a/packages/rule-tester/src/types/index.ts +++ b/packages/rule-tester/src/types/index.ts @@ -12,7 +12,7 @@ export type TesterConfigWithDefaults = Mutable< export interface RunTests< MessageIds extends string, - Options extends Readonly, + Options extends readonly unknown[], > { // RuleTester.run also accepts strings for valid cases readonly valid: readonly (ValidTestCase | string)[]; @@ -21,7 +21,7 @@ export interface RunTests< export interface NormalizedRunTests< MessageIds extends string, - Options extends Readonly, + Options extends readonly unknown[], > { readonly valid: readonly ValidTestCase[]; readonly invalid: readonly InvalidTestCase[]; diff --git a/packages/utils/src/ts-eslint/RuleTester.ts b/packages/utils/src/ts-eslint/RuleTester.ts index 11696716222f..76e1a2bfad73 100644 --- a/packages/utils/src/ts-eslint/RuleTester.ts +++ b/packages/utils/src/ts-eslint/RuleTester.ts @@ -11,7 +11,7 @@ import type { SharedConfigurationSettings, } from './Rule'; -interface ValidTestCase> { +interface ValidTestCase { /** * Name for the test case. */ @@ -75,7 +75,7 @@ interface SuggestionOutput { interface InvalidTestCase< MessageIds extends string, - Options extends Readonly, + Options extends readonly unknown[], > extends ValidTestCase { /** * Expected errors. @@ -135,7 +135,7 @@ type RuleTesterTestFrameworkFunction = ( interface RunTests< MessageIds extends string, - Options extends Readonly, + Options extends readonly unknown[], > { // RuleTester.run also accepts strings for valid cases readonly valid: readonly (ValidTestCase | string)[]; @@ -160,7 +160,7 @@ declare class RuleTesterBase { * @param rule The rule to test. * @param test The collection of tests to run. */ - run>( + run( ruleName: string, rule: RuleModule, tests: RunTests, @@ -190,7 +190,7 @@ declare class RuleTesterBase { /** * Define a rule for one particular run of tests. */ - defineRule>( + defineRule( name: string, rule: | RuleCreateFunction diff --git a/packages/website/plugins/generated-rule-docs/RuleDocsPage.ts b/packages/website/plugins/generated-rule-docs/RuleDocsPage.ts index 8c1d317bdc9d..d59938e5f6a0 100644 --- a/packages/website/plugins/generated-rule-docs/RuleDocsPage.ts +++ b/packages/website/plugins/generated-rule-docs/RuleDocsPage.ts @@ -26,7 +26,7 @@ export class RuleDocsPage { #headingIndices: RequiredHeadingIndices; #rule: Readonly; - get children(): Readonly { + get children(): readonly unist.Node[] { return this.#children; } From 07963b7feaf5d5654e140e22ccf31ee67a6accc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Sat, 22 Jun 2024 10:29:19 +0900 Subject: [PATCH 13/13] fix: snapshot update --- .../tests/docs-eslint-output-snapshots/array-type.shot | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/array-type.shot b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/array-type.shot index 0241304b22e8..09bfe8fd3d19 100644 --- a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/array-type.shot +++ b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/array-type.shot @@ -28,6 +28,8 @@ const x: string[] = ['a', 'b']; ~~~~~~~~ Array type using 'string[]' is forbidden. Use 'Array' instead. const y: readonly string[] = ['a', 'b']; ~~~~~~~~~~~~~~~~~ Array type using 'readonly string[]' is forbidden. Use 'ReadonlyArray' instead. +const z: Readonly = ['a', 'b']; + ~~~~~~~~ Array type using 'string[]' is forbidden. Use 'Array' instead. " `; @@ -37,6 +39,7 @@ Options: { "default": "generic" } const x: Array = ['a', 'b']; const y: ReadonlyArray = ['a', 'b']; +const z: Readonly> = ['a', 'b']; " `;