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.isPropertyAccessExpression(node)) {
if (ChaiUtils.isExpectInvocation(node)) {
if (/ok|true|false|undefined|null/.test(node.name.getText())) {
const expectInvocation = ChaiUtils.getExpectInvocation(node);
if (!expectInvocation || expectInvocation.arguments.length !== 2) {
ctx.addFailureAt(node.getStart(), node.getWidth(), FAILURE_STRING);
}
}
}
}
if (tsutils.isCallExpression(node)) {
if (ChaiUtils.isExpectInvocation(node)) {
if (tsutils.isPropertyAccessExpression(node.expression)) {
if (ChaiUtils.isEqualsInvocation(node.expression)) {
if (node.arguments.length === 1) {
if (/true|false|null|undefined/.test(node.arguments[0].getText())) {
function getPropertyAccessExpressionRoot(
node: ts.PropertyAccessExpression
): ts.Node | undefined {
let { expression } = node;
while (tsutils.isPropertyAccessExpression(expression)) {
expression = expression.expression;
}
return isThis(expression) || tsutils.isIdentifier(expression)
? expression
: undefined;
}
function isPropertyAccessOfProperty(expression, identifers) {
return (tsutils_1.isPropertyAccessExpression(expression) &&
tsutils_1.isPropertyAccessExpression(expression.expression) &&
identifers.some(function (identifer) {
return expression.expression.name.text === identifer;
}));
}
function walk(ctx) {
function hasChildCall(node: ts.PropertyAccessExpression): boolean {
let { expression } = node;
while (isPropertyAccessExpression(expression) || isElementAccessExpression(expression)) {
({ expression } = expression);
}
return expression.kind === ts.SyntaxKind.CallExpression;
}
function isPropertyAccessParseInt(expression) {
return tsutils_1.isPropertyAccessExpression(expression) && expression.name.text === "parseInt";
}
function isPropertyAccessOfIdentifier(expression, identifiers) {
function cb(node) {
if (tsutils.isPropertyAccessExpression(node)) {
var propertyName = node.name.text;
if (propertyName === 'cookie') {
var leftSide = node.expression;
try {
var leftSideType = typeChecker.getTypeAtLocation(leftSide);
var typeAsString = typeChecker.typeToString(leftSideType);
if (leftSideType.flags === ts.TypeFlags.Any || typeAsString === 'Document') {
ctx.addFailureAt(leftSide.getStart(), leftSide.getWidth(), Rule.FAILURE_STRING);
}
}
catch (e) {
if (leftSide.getFullText().trim() === 'document') {
ctx.addFailureAt(leftSide.getStart(), leftSide.getWidth(), Rule.FAILURE_STRING);
}
}
}
const cb = (node: ts.Node): void => {
if (tsutils.isBinaryExpression(node) && isRelationalOrLogicalOperator(node.operatorToken)) {
if (
(tsutils.isStringLiteral(node.left) && tsutils.isStringLiteral(node.right)) ||
(tsutils.isNumericLiteral(node.left) && tsutils.isNumericLiteral(node.right))
) {
if (node.left.text === node.right.text) {
context.addFailureAtNode(node, TAUTOLOGY_DISCOVERED_ERROR_STRING);
}
} else if (tsutils.isIdentifier(node.left) && tsutils.isIdentifier(node.right)) {
if (node.left.text === node.right.text) {
context.addFailureAtNode(node, TAUTOLOGY_DISCOVERED_ERROR_STRING);
}
} else if (
tsutils.isPropertyAccessExpression(node.left) &&
tsutils.isPropertyAccessExpression(node.right)
) {
if (node.left.expression.getText() === node.right.expression.getText()) {
if (node.left.name.text === node.right.name.text) {
context.addFailureAtNode(node, TAUTOLOGY_DISCOVERED_ERROR_STRING);
}
}
} else if (
(isBooleanLiteral(node.left) && isBooleanLiteral(node.right)) ||
(isNullLiteral(node.left) && isNullLiteral(node.right))
) {
context.addFailureAtNode(node, TAUTOLOGY_DISCOVERED_ERROR_STRING);
}
}
return ts.forEachChild(node, cb);
};
return ts.forEachChild(context.sourceFile, cb);
function getCallExpresion(node) {
var parent = node.parent;
if (tsutils_1.isPropertyAccessExpression(parent) && parent.name === node) {
node = parent;
parent = node.parent;
}
return tsutils_1.isTaggedTemplateExpression(parent) ||
((tsutils_1.isCallExpression(parent) || tsutils_1.isNewExpression(parent)) && parent.expression === node)
? parent
: undefined;
}
function getDeprecation(node, tc) {
private isUnsafe(node: ts.Node): ts.Node | undefined {
const { callbackMap, callbackStack } = this;
const leafCallback = callbackStack[callbackStack.length - 1];
const leafOperator = callbackMap.get(leafCallback);
const rootCallback = callbackStack[0];
const typeChecker = this.getTypeChecker();
if (tsutils.isPropertyAccessExpression(node.parent)) {
if (!isPropertyAccessExpressionLeaf(node)) {
return undefined;
}
const declaration = findDeclaration(node, typeChecker);
if (!declaration) {
return undefined;
}
if (
tsutils.hasModifier(
declaration.modifiers,
ts.SyntaxKind.ReadonlyKeyword
)
) {
return undefined;
}
const cb = (node: ts.Node): void => {
if (isCallExpression(node)) {
if (isIdentifier(node.expression)) {
this.checkFunctionBan(node.expression);
} else if (isPropertyAccessExpression(node.expression)) {
this.checkForObjectMethodBan(node.expression);
}
}
return ts.forEachChild(node, cb);
};
return ts.forEachChild(sourceFile, cb);