Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Fix false positive for simple parenthesized array types with array-simple (#4844) #4846

Merged
merged 1 commit into from Aug 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/rules/arrayTypeRule.ts
Expand Up @@ -164,6 +164,8 @@ function isSimpleType(nodeType: ts.TypeNode): boolean {
case ts.SyntaxKind.ThisType:
case ts.SyntaxKind.UnknownKeyword:
return true;
case ts.SyntaxKind.ParenthesizedType:
return isSimpleType((nodeType as ts.ParenthesizedTypeNode).type);
case ts.SyntaxKind.TypeReference:
// TypeReferences must be non-generic or be another Array with a simple type
const { typeName, typeArguments } = nodeType as ts.TypeReferenceNode;
Expand Down
4 changes: 4 additions & 0 deletions test/rules/array-type/array-simple/test.ts.fix
Expand Up @@ -10,6 +10,8 @@ let yy: number[][] = [[4, 5], [6]];
let ya = [[1, "2"]] as Array<[number, string]>;

type Arr<T> = T[];
type ParenthesisArr<T> = (T)[];
type DoubleParenthesisArr<T> = ((T))[];

// Ignore user defined aliases
let yyyy: Arr<Array<Array<Arr<string>>>> = [[[["2"]]]];
Expand Down Expand Up @@ -38,9 +40,11 @@ let barVar: Array<(c: number) => number>;

type fooUnion = Array<string|number|boolean>;
type barUnion = Array<string|number|boolean>;
type bazUnion = Array<(string|number|boolean)>;

type fooIntersection = Array<string & number>;
type barIntersection = Array<string & number>;
type bazIntersection = Array<(string & number)>;

namespace fooName {
type BarType = { bar: string };
Expand Down
6 changes: 6 additions & 0 deletions test/rules/array-type/array-simple/test.ts.lint
Expand Up @@ -19,6 +19,8 @@ let ya = [[1, "2"]] as[number, string][];

type Arr<T> = Array<T>;
~~~~~~~~ [0]
type ParenthesisArr<T> = (T)[];
type DoubleParenthesisArr<T> = ((T))[];

// Ignore user defined aliases
let yyyy: Arr<Array<Arr<string>>[]> = [[[["2"]]]];
Expand Down Expand Up @@ -52,10 +54,14 @@ let barVar: ((c: number) => number)[];
type fooUnion = Array<string|number|boolean>;
type barUnion = (string|number|boolean)[];
~~~~~~~~~~~~~~~~~~~~~~~~~ [Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.]
type bazUnion = ((string|number|boolean))[];
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.]

type fooIntersection = Array<string & number>;
type barIntersection = (string & number)[];
~~~~~~~~~~~~~~~~~~~ [Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.]
type bazIntersection = ((string & number))[];
~~~~~~~~~~~~~~~~~~~~~ [Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.]

namespace fooName {
type BarType = { bar: string };
Expand Down