Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
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]);
}
}
}
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;
}
function isCallExpressionBody(body: ts.Node) {
while (tsutils.isParenthesizedExpression(body)) {
body = body.expression;
}
return tsutils.isCallExpression(body);
}
function isFunctionCallOrNewExpression(node: ts.Node): node is CallOrNewExpression {
if (isCallExpression(node) || isNewExpression(node)) {
return isIdentifier(node.expression) && node.expression.text === "Function";
}
return false;
}
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);
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);
};
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);
}
});
}
}
}
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);
}
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);
}
}