Skip to content

Commit

Permalink
fix(eslint-plugin): [sort-type-constituents] fixed behavior change (#…
Browse files Browse the repository at this point in the history
…6384)

fix(sort-type-constituents): Fixed behavior change when sorting TSConditionalType (#6339)
  • Loading branch information
sviat9440 committed Jan 31, 2023
1 parent 056e9f0 commit 5bf7f7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/util/misc.ts
Expand Up @@ -210,6 +210,7 @@ function typeNodeRequiresParentheses(
return (
node.type === AST_NODE_TYPES.TSFunctionType ||
node.type === AST_NODE_TYPES.TSConstructorType ||
node.type === AST_NODE_TYPES.TSConditionalType ||
(node.type === AST_NODE_TYPES.TSUnionType && text.startsWith('|')) ||
(node.type === AST_NODE_TYPES.TSIntersectionType && text.startsWith('&'))
);
Expand Down
14 changes: 14 additions & 0 deletions packages/eslint-plugin/tests/rules/sort-type-constituents.test.ts
Expand Up @@ -359,6 +359,7 @@ type T = 1 | string | {} | A;
},
],
},
"type A<T> = string | (T extends number ? 'hi' : 'there');",
],
invalid: [
...invalid('|'),
Expand All @@ -376,5 +377,18 @@ type T = 1 | string | {} | A;
},
],
},
{
output: "type A<T> = string | (T extends number ? 'hi' : 'there');",
code: "type A<T> = (T extends number ? 'hi' : 'there') | string;",
errors: [
{
messageId: 'notSortedNamed',
data: {
type: 'Union',
name: 'A',
},
},
],
},
],
});

0 comments on commit 5bf7f7f

Please sign in to comment.