From 74e544e487328e56fcb7aef048a78beaad593ea0 Mon Sep 17 00:00:00 2001 From: Jonah Snider Date: Tue, 14 Dec 2021 23:01:41 -0800 Subject: [PATCH] fix(eslint-plugin): `array-type` mark `AST_NODE_TYPES.TSBigIntKeyword` as simple (#4274) --- .../eslint-plugin/src/rules/array-type.ts | 1 + .../tests/rules/array-type.test.ts | 120 ++++++++++++++++++ 2 files changed, 121 insertions(+) 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: 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 {