Skip to content

Commit

Permalink
fix(eslint-plugin): [space-infix-ops] regression fix for conditional …
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 authored Jun 1, 2022
1 parent f0fb2e5 commit e5238c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/eslint-plugin/src/rules/space-infix-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,13 @@ export default util.createRule<Options, MessageIds>({
}

function checkForTypeConditional(node: TSESTree.TSConditionalType): void {
const extendsTypeNode = sourceCode.getTokenByRangeStart(
node.extendsType.range[0],
)!;
const trueTypeNode = sourceCode.getTokenByRangeStart(
node.trueType.range[0],
)!;
const falseTypeNode = sourceCode.getTokenByRangeStart(
node.falseType.range[0],
);
const extendsLastToken = sourceCode.getLastToken(node.extendsType)!;
const trueFirstToken = sourceCode.getFirstToken(node.trueType)!;
const trueLastToken = sourceCode.getLastToken(node.trueType)!;
const falseFirstToken = sourceCode.getFirstToken(node.falseType)!;

checkAndReportAssignmentSpace(node, extendsTypeNode, trueTypeNode);
checkAndReportAssignmentSpace(node, trueTypeNode, falseTypeNode);
checkAndReportAssignmentSpace(node, extendsLastToken, trueFirstToken);
checkAndReportAssignmentSpace(node, trueLastToken, falseFirstToken);
}

return {
Expand Down
9 changes: 9 additions & 0 deletions packages/eslint-plugin/tests/rules/space-infix-ops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ ruleTester.run('space-infix-ops', rule, {
& (((() => void)));
`,
},
{
code: 'type Baz<T> = T extends (bar: string) => void ? string : number',
},
{
code: 'type Foo<T> = T extends { bar: string } ? string : number',
},
{
code: 'type Baz<T> = T extends (bar: string) => void ? { x: string } : { y: string }',
},
{
code: `
interface Test {
Expand Down

0 comments on commit e5238c8

Please sign in to comment.