How to use the tsutils.isCallExpression function in tsutils

To help you get started, we’ve selected a few tsutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / tslint-microsoft-contrib / src / noBackboneGetSetOutsideModelRule.ts View on Github external
function cb(node: ts.Node): void {
        if (tsutils.isCallExpression(node)) {
            if (AstUtils.getFunctionTarget(node) !== 'this') {
                const functionName: string = AstUtils.getFunctionName(node);

                if (functionName === 'get' && node.arguments.length === 1 && tsutils.isStringLiteral(node.arguments[0])) {
                    const msg: string = Rule.GET_FAILURE_STRING + node.getText();
                    ctx.addFailureAt(node.getStart(), node.getWidth(), msg);
                }

                if (functionName === 'set' && node.arguments.length === 2 && tsutils.isStringLiteral(node.arguments[0])) {
                    const msg: string = Rule.SET_FAILURE_STRING + node.getText();
                    ctx.addFailureAt(node.getStart(), node.getWidth(), msg);
                }
            }
        }
        return ts.forEachChild(node, cb);
    }
github microsoft / tslint-microsoft-contrib / nonLiteralRequireRule.js View on Github external
function cb(node) {
        if (tsutils.isCallExpression(node)) {
            if (AstUtils_1.AstUtils.getFunctionName(node) === 'require' &&
                AstUtils_1.AstUtils.getFunctionTarget(node) === undefined &&
                node.arguments.length > 0) {
                if (tsutils.isArrayLiteralExpression(node.arguments[0])) {
                    var arrayExp = node.arguments[0];
                    arrayExp.elements.forEach(function (initExpression) {
                        if (!tsutils.isStringLiteral(initExpression)) {
                            fail(initExpression);
                        }
                    });
                }
                else if (!tsutils.isStringLiteral(node.arguments[0])) {
                    fail(node.arguments[0]);
                }
            }
        }
github cartant / tslint-etc / source / rules / noUnsafeCallbackScopeRule.ts View on Github external
const declaration = findDeclaration(node, typeChecker);
    if (!declaration) {
      return undefined;
    }

    if (isWithinClosure(declaration, callback)) {
      return undefined;
    }

    if (this.allowParameters && isWithinParameterDeclaration(declaration)) {
      return undefined;
    }

    if (
      tsutils.isCallExpression(node.parent) &&
      node === node.parent.expression
    ) {
      return undefined;
    }

    if (
      tsutils.isTaggedTemplateExpression(node.parent) &&
      node === node.parent.tag
    ) {
      return undefined;
    }

    if (tsutils.isNewExpression(node.parent)) {
      return undefined;
    }
github palantir / tslint / src / rules / promiseFunctionAsyncRule.ts View on Github external
function isCallExpressionBody(body: ts.Node) {
    while (tsutils.isParenthesizedExpression(body)) {
        body = body.expression;
    }

    return tsutils.isCallExpression(body);
}
github palantir / tslint / src / rules / functionConstructorRule.ts View on Github external
function isFunctionCallOrNewExpression(node: ts.Node): node is CallOrNewExpression {
    if (isCallExpression(node) || isNewExpression(node)) {
        return isIdentifier(node.expression) && node.expression.text === "Function";
    }

    return false;
}
github nativescript-rtl / ui / node_modules / tslint / lib / rules / banRule.js View on Github external
var cb = function (node) {
            if (tsutils_1.isCallExpression(node)) {
                if (tsutils_1.isIdentifier(node.expression)) {
                    _this.checkFunctionBan(node.expression);
                }
                else if (tsutils_1.isPropertyAccessExpression(node.expression)) {
                    _this.checkForObjectMethodBan(node.expression);
                }
            }
            return ts.forEachChild(node, cb);
        };
        return ts.forEachChild(sourceFile, cb);
github nativescript-rtl / ui / node_modules / tslint / lib / rules / noMagicNumbersRule.js View on Github external
var cb = function (node) {
            if (tsutils_1.isCallExpression(node)) {
                if (tsutils_1.isIdentifier(node.expression) && node.expression.text === "parseInt") {
                    return node.arguments.length === 0 ? undefined : cb(node.arguments[0]);
                }
                if (tsutils_1.isPropertyAccessExpression(node.expression) &&
                    NUMBER_METHODS.has(node.expression.name.text)) {
                    return;
                }
            }
            if (node.kind === ts.SyntaxKind.NumericLiteral) {
                return _this.checkNumericLiteral(node, node.text);
            }
            if (utils_1.isNegativeNumberLiteral(node)) {
                return _this.checkNumericLiteral(node, "-" + node.operand.text);
            }
            return ts.forEachChild(node, cb);
        };
github microsoft / tslint-microsoft-contrib / src / nonLiteralFsPathRule.ts View on Github external
function cb(node: ts.Node): void {
        if (tsutils.isCallExpression(node)) {
            if (AstUtils.getFunctionTarget(node) === 'fs' && node.arguments.length > 0) {
                const functionName = AstUtils.getFunctionName(node);
                const positions = PATH_PARAMETER_POSITIONS[functionName];

                if (positions && node.arguments.length >= positions.length) {
                    positions.forEach(position => {
                        const argument = node.arguments[position];

                        if (!tsutils.isStringLiteral(argument)) {
                            fail(AstUtils.getFunctionName(node), argument);
                        }
                    });
                }
            }
        }
github microsoft / tslint-microsoft-contrib / src / noDisableAutoSanitizationRule.ts View on Github external
function cb(node: ts.Node): void {
        if (tsutils.isCallExpression(node)) {
            const functionName: string = AstUtils.getFunctionName(node);
            if (functionName === 'execUnsafeLocalFunction' || functionName === 'setInnerHTMLUnsafe') {
                ctx.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING + functionName);
            }
        }

        return ts.forEachChild(node, cb);
    }
github fimbullinter / wotan / packages / mimir / src / rules / await-async-result.ts View on Github external
private visitStatement(node: ts.Statement) {
        if (isExpressionStatement(node)) {
            if (isCallExpression(node.expression) && isThenableType(this.checker, node.expression))
                this.addFindingAtNode(node, "Return value of async function call was discarded. Did you mean to 'await' its result?");
            return;
        }
        for (const statement of childStatements(node))
            this.visitStatement(statement);
    }
}