Skip to content

Commit 0377070

Browse files
authored
fix(eslint-plugin): [array-type] in fixer add missing parens for constructor types typescript-eslint#4756 (typescript-eslint#4971)
fix(eslint-plugin): add missing parens in array-type for constructor types typescript-eslint#4756
1 parent 74c67ba commit 0377070

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

packages/eslint-plugin/src/rules/array-type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function typeNeedsParentheses(node: TSESTree.Node): boolean {
6161
case AST_NODE_TYPES.TSIntersectionType:
6262
case AST_NODE_TYPES.TSTypeOperator:
6363
case AST_NODE_TYPES.TSInferType:
64+
case AST_NODE_TYPES.TSConstructorType:
6465
return true;
6566
case AST_NODE_TYPES.Identifier:
6667
return node.name === 'ReadonlyArray';

packages/eslint-plugin/tests/rules/array-type.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,36 @@ interface FooInterface {
18851885
},
18861886
],
18871887
},
1888+
{
1889+
code: 'const foo: Array<new (...args: any[]) => void> = [];',
1890+
output: 'const foo: (new (...args: any[]) => void)[] = [];',
1891+
options: [{ default: 'array' }],
1892+
errors: [
1893+
{
1894+
messageId: 'errorStringArray',
1895+
data: { className: 'Array', readonlyPrefix: '', type: 'T' },
1896+
line: 1,
1897+
column: 12,
1898+
},
1899+
],
1900+
},
1901+
{
1902+
code: 'const foo: ReadonlyArray<new (...args: any[]) => void> = [];',
1903+
output: 'const foo: readonly (new (...args: any[]) => void)[] = [];',
1904+
options: [{ default: 'array' }],
1905+
errors: [
1906+
{
1907+
messageId: 'errorStringArray',
1908+
data: {
1909+
className: 'ReadonlyArray',
1910+
readonlyPrefix: 'readonly ',
1911+
type: 'T',
1912+
},
1913+
line: 1,
1914+
column: 12,
1915+
},
1916+
],
1917+
},
18881918
],
18891919
});
18901920

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy