eslint-plugin-unicorn
Version:
More than 300 powerful ESLint rules
14 lines (12 loc) • 530 B
JavaScript
import {getParenthesizedText, isParenthesized} from './parentheses/parentheses.js';
/**
Get the right comparison operand text, grouping TypeScript assertions when a relational operator would otherwise capture them.
*/
export default function getComparisonOperandText(node, context, operator) {
const text = getParenthesizedText(node, context);
return !isParenthesized(node, context)
&& ['<', '<=', '>', '>='].includes(operator)
&& ['TSAsExpression', 'TSSatisfiesExpression'].includes(node.type)
? `(${text})`
: text;
}