Skip to content

Commit

Permalink
fix(eslint-plugin): [array-type] in fixer add missing parens for cons…
Browse files Browse the repository at this point in the history
…tructor types #4756 (#4971)

fix(eslint-plugin): add missing parens in array-type for constructor types #4756
  • Loading branch information
armano2 committed May 14, 2022
1 parent 74c67ba commit 0377070
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/array-type.ts
Expand Up @@ -61,6 +61,7 @@ function typeNeedsParentheses(node: TSESTree.Node): boolean {
case AST_NODE_TYPES.TSIntersectionType:
case AST_NODE_TYPES.TSTypeOperator:
case AST_NODE_TYPES.TSInferType:
case AST_NODE_TYPES.TSConstructorType:
return true;
case AST_NODE_TYPES.Identifier:
return node.name === 'ReadonlyArray';
Expand Down
30 changes: 30 additions & 0 deletions packages/eslint-plugin/tests/rules/array-type.test.ts
Expand Up @@ -1885,6 +1885,36 @@ interface FooInterface {
},
],
},
{
code: 'const foo: Array<new (...args: any[]) => 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<new (...args: any[]) => 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,
},
],
},
],
});

Expand Down

0 comments on commit 0377070

Please sign in to comment.