Skip to content

Commit

Permalink
fix(eslint-plugin): [array-type] --fix flag removes parentheses from …
Browse files Browse the repository at this point in the history
…type (#5997)
  • Loading branch information
mhnaeem authored and bradzacher committed Nov 23, 2022
1 parent 6de4a9a commit 42b33af
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/eslint-plugin/src/rules/array-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ export default util.createRule<Options, MessageIds>({
}

const type = typeParams[0];
const typeParens =
!util.isParenthesized(type, sourceCode) && typeNeedsParentheses(type);
const typeParens = typeNeedsParentheses(type);
const parentParens =
readonlyPrefix &&
node.parent?.type === AST_NODE_TYPES.TSArrayType &&
Expand Down
55 changes: 55 additions & 0 deletions packages/eslint-plugin/tests/rules/array-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,61 @@ class Foo<T = Bar[][]> extends Bar<T, T[]> implements Baz<T[]> {
}
`,
);
testOutput(
'array',
`
interface WorkingArray {
outerProperty: Array<
{ innerPropertyOne: string } & { innerPropertyTwo: string }
>;
}
interface BrokenArray {
outerProperty: Array<
({ innerPropertyOne: string } & { innerPropertyTwo: string })
>;
}
`,
`
interface WorkingArray {
outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];
}
interface BrokenArray {
outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];
}
`,
);
testOutput(
'array',
`
type WorkingArray = {
outerProperty: Array<
{ innerPropertyOne: string } & { innerPropertyTwo: string }
>;
}
type BrokenArray = {
outerProperty: Array<
({ innerPropertyOne: string } & { innerPropertyTwo: string })
>;
}
`,
`
type WorkingArray = {
outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];
}
type BrokenArray = {
outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];
}
`,
);
testOutput(
'array',
'const a: Array<(string|number)>;',
'const a: (string|number)[];',
);
testOutput(
'array-simple',
'let xx: Array<Array<number>> = [[1, 2], [3]];',
Expand Down

0 comments on commit 42b33af

Please sign in to comment.