Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (isIndirectEval(node)) {
return false;
}
return both(node.left, node.right);
case ts.SyntaxKind.AmpersandAmpersandToken:
case ts.SyntaxKind.BarBarToken:
if (allowFastNullChecks) {
noCheck(node.left, cb);
return cb(node.right);
}
}
}
noCheck(node, forEachChild);
return isUnusedExpression(node, ctx.options);
}
if (isExpressionStatement(node)) {
allowFastNullChecks = ctx.options.allowFastNullChecks;
if (!isDirective(node)) {
check(node.expression, node);
}
allowFastNullChecks = true;
return false;
} else if (isVoidExpression(node)) {
// allow `void 0` and `void(0)`
if (
!isLiteralZero(
isParenthesizedExpression(node.expression)
? node.expression.expression
: node.expression,
)
) {
check(node.expression);
function isDirective(node) {
if (node.expression.kind !== ts.SyntaxKind.StringLiteral || !canContainDirective(node.parent)) {
return false;
}
var parent = node.parent;
// check if all previous statements in block are also directives
for (var i = parent.statements.indexOf(node) - 1; i >= 0; --i) {
var statement = parent.statements[i];
if (!tsutils_1.isExpressionStatement(statement) ||
statement.expression.kind !== ts.SyntaxKind.StringLiteral) {
return false;
}
}
return true;
}
function canContainDirective(node) {
if (isIndirectEval(node)) {
return false;
}
return both(node.left, node.right);
case ts.SyntaxKind.AmpersandAmpersandToken:
case ts.SyntaxKind.BarBarToken:
if (allowFastNullChecks) {
noCheck(node.left, cb);
return cb(node.right);
}
}
}
noCheck(node, forEachChild);
return isUnusedExpression(node, ctx.options);
}
if (tsutils_1.isExpressionStatement(node)) {
allowFastNullChecks = ctx.options.allowFastNullChecks;
if (!isDirective(node)) {
check(node.expression, node);
}
allowFastNullChecks = true;
return false;
}
else if (tsutils_1.isVoidExpression(node)) {
// allow `void 0` and `void(0)`
if (!isLiteralZero(tsutils_1.isParenthesizedExpression(node.expression)
? node.expression.expression
: node.expression)) {
check(node.expression);
}
return false;
}
if (isIndirectEval(node)) {
return false;
}
return both(node.left, node.right);
case ts.SyntaxKind.AmpersandAmpersandToken:
case ts.SyntaxKind.BarBarToken:
if (allowFastNullChecks) {
noCheck(node.left, cb);
return cb(node.right);
}
}
}
noCheck(node, forEachChild);
return isUnusedExpression(node, ctx.options);
}
if (isExpressionStatement(node)) {
allowFastNullChecks = ctx.options.allowFastNullChecks;
if (!isDirective(node)) {
check(node.expression, node);
}
allowFastNullChecks = true;
return false;
}
if (isVoidExpression(node)) {
// allow `void 0` and `void(0)`
if (
!isLiteralZero(
isParenthesizedExpression(node.expression)
? node.expression.expression
: node.expression,
)
) {
): ts.Expression | undefined {
if (isIfStatement(statement)) {
if (inElse === false || (!checkElseIf && inElse) || statement.elseStatement === undefined) {
return undefined;
}
const then = detectAssignment(statement.thenStatement, sourceFile, checkElseIf, false);
if (then === undefined) {
return undefined;
}
const elze = detectAssignment(statement.elseStatement, sourceFile, checkElseIf, true);
return elze !== undefined && nodeEquals(then, elze, sourceFile) ? then : undefined;
} else if (isBlock(statement)) {
return statement.statements.length === 1
? detectAssignment(statement.statements[0], sourceFile, checkElseIf, inElse)
: undefined;
} else if (isExpressionStatement(statement) && isBinaryExpression(statement.expression)) {
const {
operatorToken: { kind },
left,
right,
} = statement.expression;
return kind === ts.SyntaxKind.EqualsToken &&
isSameLine(sourceFile, right.getStart(sourceFile), right.end)
? left
: undefined;
} else {
return undefined;
}
}
function isUseStrictDeclaration(node) {
return node.text === "use strict" && tsutils_1.isExpressionStatement(node.parent);
}
function isLookupTypeParameter(node) {
function isUseStrictDeclaration(node: StringLiteralLike) {
return node.text === "use strict" && isExpressionStatement(node.parent);
}
return ts.forEachChild(ctx.sourceFile, function cb(node) {
if (tsutils_1.isExpressionStatement(node)) {
var expression = node.expression;
if (tsutils_1.isCallExpression(expression) &&
!isPromiseCatchCall(expression) &&
!isPromiseThenCallWithRejectionHandler(expression)) {
var symbol = tc.getTypeAtLocation(expression).symbol;
if (symbol !== undefined && ctx.options.indexOf(symbol.name) !== -1) {
ctx.addFailureAtNode(expression, Rule.FAILURE_STRING);
}
}
}
return ts.forEachChild(node, cb);
});
}
function getCallExpressionFromStatement(statement) {
var expression;
if (tsutils.isExpressionStatement(statement)) {
expression = statement.expression;
}
else if (tsutils.isReturnStatement(statement)) {
expression = statement.expression;
if (expression === undefined) {
return undefined;
}
}
else {
return undefined;
}
if (!tsutils.isCallExpression(expression)) {
return undefined;
}
var call = expression;
if (!tsutils.isPropertyAccessExpression(call.expression)) {