From fd3211888c9353ef4fbcae882337397d9ef8c527 Mon Sep 17 00:00:00 2001 From: Jonah Snider Date: Tue, 7 Dec 2021 20:04:26 -0800 Subject: [PATCH 1/2] fix(eslint-plugin): `array-type` mark `AST_NODE_TYPES.TSBigIntKeyword` as simple --- packages/eslint-plugin/src/rules/array-type.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index 35045fdd985..f6e601225ce 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -15,6 +15,7 @@ function isSimpleType(node: TSESTree.Node): boolean { case AST_NODE_TYPES.TSBooleanKeyword: case AST_NODE_TYPES.TSNeverKeyword: case AST_NODE_TYPES.TSNumberKeyword: + case AST_NODE_TYPES.TSBigIntKeyword: case AST_NODE_TYPES.TSObjectKeyword: case AST_NODE_TYPES.TSStringKeyword: case AST_NODE_TYPES.TSSymbolKeyword: From f8899b440f6845ceff8aac9b670d590f109cea5d Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 15 Dec 2021 01:29:41 +0100 Subject: [PATCH 2/2] test(eslint-plugin): add missing test cases --- .../tests/rules/array-type.test.ts | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/array-type.test.ts b/packages/eslint-plugin/tests/rules/array-type.test.ts index eafd9a912cf..cfdfb80ec1a 100644 --- a/packages/eslint-plugin/tests/rules/array-type.test.ts +++ b/packages/eslint-plugin/tests/rules/array-type.test.ts @@ -202,6 +202,35 @@ ruleTester.run('array-type', rule, { 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 { @@ -1088,6 +1117,97 @@ function bazFunction(baz: Arr>) { }, ], }, + { + 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 {