in packages/concatjs/internal/tsetse/rules/check_return_value_rule.ts [84:146]
function isBlackListed(node: ts.CallExpression, tc: ts.TypeChecker): boolean {
type AccessExpression =
ts.PropertyAccessExpression|ts.ElementAccessExpression;
switch (node.expression.kind) {
case ts.SyntaxKind.PropertyAccessExpression:
case ts.SyntaxKind.ElementAccessExpression:
// Example: foo.bar() or foo[bar]()
// expressionNode is foo
const nodeExpression = (node.expression as AccessExpression).expression;
const nodeExpressionString = nodeExpression.getText();
const nodeType = tc.getTypeAtLocation(nodeExpression);
// nodeTypeString is the string representation of the type of foo
let nodeTypeString = tc.typeToString(nodeType);
if (nodeTypeString.endsWith('[]')) {
nodeTypeString = 'Array';
}
if (nodeTypeString === 'ObjectConstructor') {
nodeTypeString = 'Object';
}
if (tsutils.isTypeFlagSet(nodeType, ts.TypeFlags.StringLiteral)) {
nodeTypeString = 'string';
}
// nodeFunction is bar
let nodeFunction = '';
if (tsutils.isPropertyAccessExpression(node.expression)) {
nodeFunction = node.expression.name.getText();
}
if (tsutils.isElementAccessExpression(node.expression)) {
const argument = node.expression.argumentExpression;
if (argument !== undefined) {
nodeFunction = argument.getText();
}
}
// Check if 'foo#bar' or `${typeof foo}#bar` is in the blacklist.
if (METHODS_TO_CHECK.has(`${nodeTypeString}#${nodeFunction}`) ||
METHODS_TO_CHECK.has(`${nodeExpressionString}#${nodeFunction}`)) {
return true;
}
// For 'str.replace(regexp|substr, newSubstr|function)' only check when
// the second parameter is 'newSubstr'.
if ((`${nodeTypeString}#${nodeFunction}` === 'string#replace') ||
(`${nodeExpressionString}#${nodeFunction}` === 'string#replace')) {
return node.arguments.length === 2 &&
!tsutils.isFunctionWithBody(node.arguments[1]);
}
break;
case ts.SyntaxKind.Identifier:
// Example: foo()
// We currently don't have functions of this kind in blacklist.
const identifier = node.expression as ts.Identifier;
if (METHODS_TO_CHECK.has(identifier.text)) {
return true;
}
break;
default:
break;
}
return false;
}