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

Commit

Permalink
Fix parenthesized simple array types with array-simple (#4844) (#4846)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeKjaer authored and Josh Goldberg committed Aug 31, 2019
1 parent abd83b5 commit 89d731f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
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

0 comments on commit 89d731f

Please sign in to comment.