Skip to content

Commit

Permalink
chore: replace internal method
Browse files Browse the repository at this point in the history
  • Loading branch information
holazz committed May 23, 2022
1 parent e8c7d91 commit 45432cd
Showing 1 changed file with 16 additions and 31 deletions.
47 changes: 16 additions & 31 deletions packages/eslint-plugin/src/rules/space-infix-ops.ts
@@ -1,10 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment */

import {
AST_NODE_TYPES,
AST_TOKEN_TYPES,
TSESTree,
} from '@typescript-eslint/utils';
import { AST_TOKEN_TYPES, TSESTree } from '@typescript-eslint/utils';
import { getESLintCoreRule } from '../util/getESLintCoreRule';
import * as util from '../util';

Expand Down Expand Up @@ -75,7 +69,10 @@ export default util.createRule<Options, MessageIds>({
};

function isSpaceChar(token: TSESTree.Token): boolean {
return token.type === AST_TOKEN_TYPES.Punctuator && token.value === '=';
return (
token.type === AST_TOKEN_TYPES.Punctuator &&
/^[=|?|:]$/.test(token.value)
);
}

function checkAndReportAssignmentSpace(
Expand Down Expand Up @@ -187,30 +184,18 @@ export default util.createRule<Options, MessageIds>({
}

function checkForTypeConditional(node: TSESTree.TSConditionalType): void {
// transform it to a ConditionalExpression
return rules.ConditionalExpression({
type: AST_NODE_TYPES.ConditionalExpression,
test: {
type: AST_NODE_TYPES.BinaryExpression,
operator: 'extends',
left: node.checkType as any,
right: node.extendsType as any,

// location data
range: [node.checkType.range[0], node.extendsType.range[1]],
loc: {
start: node.checkType.loc.start,
end: node.extendsType.loc.end,
},
},
consequent: node.trueType as any,
alternate: node.falseType as any,
const extendsTypeNode = sourceCode.getTokenByRangeStart(
node.extendsType.range[0],
)!;
const trueTypeNode = sourceCode.getTokenByRangeStart(
node.trueType.range[0],
)!;
const falseTypeNode = sourceCode.getTokenByRangeStart(
node.falseType.range[0],
);

// location data
parent: node.parent,
range: node.range,
loc: node.loc,
});
checkAndReportAssignmentSpace(node, extendsTypeNode, trueTypeNode);
checkAndReportAssignmentSpace(node, trueTypeNode, falseTypeNode);
}

return {
Expand Down

0 comments on commit 45432cd

Please sign in to comment.