Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getTypePredicateOneWay(left, right, isStrictEquals) {
switch (right.kind) {
case ts.SyntaxKind.TypeOfExpression:
var expression = right.expression;
if (!tsutils_1.isLiteralExpression(left)) {
if ((tsutils_1.isIdentifier(left) && left.text === "undefined") ||
left.kind === ts.SyntaxKind.NullKeyword ||
left.kind === ts.SyntaxKind.TrueKeyword ||
left.kind === ts.SyntaxKind.FalseKeyword) {
return { kind: 2 /* TypeofTypo */ };
}
return undefined;
}
var predicate = getTypePredicateForKind(left.text);
return predicate === undefined
? { kind: 2 /* TypeofTypo */ }
: {
expression: expression,
isNullOrUndefined: left.text === "undefined",
kind: 0 /* Plain */,
predicate: predicate,
};
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))
) {
protected visitNode(node: ts.Node): void {
if (this.callbackStack.length) {
const validateNode = tsutils.isIdentifier(node) || isThis(node);
if (validateNode) {
const failureNode = this.isUnsafe(node);
if (failureNode) {
this.addFailureAtNode(failureNode, Rule.FAILURE_STRING);
}
}
}
super.visitNode(node);
}
function getTypePredicateOneWay(
left: ts.Expression,
right: ts.Expression,
isStrictEquals: boolean,
): TypePredicate | undefined {
switch (right.kind) {
case ts.SyntaxKind.TypeOfExpression:
const expression = (right as ts.TypeOfExpression).expression;
if (!isLiteralExpression(left)) {
if (
(isIdentifier(left) && left.text === "undefined") ||
left.kind === ts.SyntaxKind.NullKeyword ||
left.kind === ts.SyntaxKind.TrueKeyword ||
left.kind === ts.SyntaxKind.FalseKeyword
) {
return { kind: TypePredicateKind.TypeofTypo };
}
return undefined;
}
const predicate = getTypePredicateForKind(left.text);
return predicate === undefined
? { kind: TypePredicateKind.TypeofTypo }
: {
expression,
isNullOrUndefined: left.text === "undefined",
kind: TypePredicateKind.Plain,
predicate,
child.name !== undefined &&
child.name.text === functionName,
);
}
if (tsutils.isConstructorDeclaration(node)) {
const {
parent: { members },
} = node;
return members.filter(child => tsutils.isConstructorDeclaration(child));
}
if (
tsutils.isMethodDeclaration(node) &&
tsutils.isIdentifier(node.name) &&
tsutils.isClassDeclaration(node.parent)
) {
const methodName = node.name.text;
return node.parent.members.filter(
member =>
tsutils.isMethodDeclaration(member) &&
tsutils.isIdentifier(member.name) &&
member.name.text === methodName,
);
}
return [node];
}
function getEquivalentNodesForDocs(node, docType) {
var exclusions = context.options.get(docType);
if (exclusions === undefined || exclusions.overloadsSeparateDocs) {
return [node];
}
if (tsutils.isFunctionDeclaration(node) && node.name !== undefined) {
var functionName_1 = node.name.text;
return getSiblings(node).filter(function (child) {
return tsutils.isFunctionDeclaration(child) &&
child.name !== undefined &&
child.name.text === functionName_1;
});
}
if (tsutils.isMethodDeclaration(node) &&
tsutils.isIdentifier(node.name) &&
tsutils.isClassDeclaration(node.parent)) {
var methodName_1 = node.name.text;
return node.parent.members.filter(function (member) {
return tsutils.isMethodDeclaration(member) &&
tsutils.isIdentifier(member.name) &&
member.name.text === methodName_1;
});
}
return [node];
}
function addDocumentationFailure(node, docType, requirementNode) {
function tryToGetDeclaredVariable(statement) {
if (statement !== undefined && tsutils.isVariableStatement(statement)) {
if (statement.declarationList.declarations.length === 1) {
var declaration = statement.declarationList.declarations[0];
if (declaration.name && tsutils.isIdentifier(declaration.name)) {
return declaration.name;
}
}
}
return undefined;
}
function tryToGetReturnedVariableName(statement) {
export function isUndefined(expression: ts.Expression): boolean {
return utils.isIdentifier(expression) && expression.text === 'undefined' ||
expression.kind === ts.SyntaxKind.VoidExpression;
}