Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void {
if (isElementAccessExpression(node)) {
const argument = node.argumentExpression;
if (
argument !== undefined &&
isStringLiteral(argument) &&
isValidPropertyAccess(argument.text)
) {
const unescapeIdentifier: typeof Rule["id"] =
// typescript@<2.5.0 has an extra underscore in escaped identifier text content,
// to avoid fixing issue `expr['__foo'] → expr.___foo`, unescapeIdentifier() is to be used
// As of typescript@3, unescapeIdentifier() removed, thus check in runtime, if the method exists
// tslint:disable-next-line no-unsafe-any strict-boolean-expressions
(ts as any).unescapeIdentifier || Rule.id;
const propertyName = unescapeIdentifier(argument.text);
ctx.addFailureAtNode(
argument,
Rule.FAILURE_STRING,
// expr['foo'] -> expr.foo
Lint.Replacement.replaceFromTo(
node.expression.end,
node.end,
private checkImportEqualsDeclaration(node: ts.ImportEqualsDeclaration) {
// only allowed `import x = require('y');`
const { moduleReference } = node;
if (!isExternalModuleReference(moduleReference)) {
return;
}
const { expression } = moduleReference;
if (expression === undefined || !isStringLiteral(expression)) {
return;
}
const source = this.options.importSourcesOrderTransform(removeQuotes(expression.text));
this.checkSource(source, node);
}
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);
function isNecessaryDynamicAccess(argumentExpression) {
if (isNumberLike(argumentExpression)) {
return true;
}
return (tsutils.isStringLiteral(argumentExpression) &&
!tsutils.isValidPropertyAccess(argumentExpression.text));
}
var templateObject_1;
function cb(node) {
if (tsutils.isCallExpression(node)) {
var functionName = AstUtils_1.AstUtils.getFunctionName(node);
if (AstUtils_1.AstUtils.isJQuery(functionName) && node.arguments.length > 0) {
var firstArg = node.arguments[0];
if (tsutils.isStringLiteral(firstArg)) {
if (isComplexHtmlElement(firstArg)) {
ctx.addFailureAt(node.getStart(), node.getWidth(), FAILURE_STRING_COMPLEX + node.getText());
}
}
else {
htmlLikeStringLiteralFinder(ctx, node);
}
}
}
return ts.forEachChild(node, cb);
}
return ts.forEachChild(ctx.sourceFile, cb);
function isTypeMatchedTo(node, attributes, condition) {
if (attributes.type === undefined) {
return false;
}
for (var _i = 0, _a = node.attributes.properties; _i < _a.length; _i++) {
var attribute = _a[_i];
if (tsutils.isJsxAttribute(attribute)) {
if (attribute.initializer !== undefined && tsutils.isStringLiteral(attribute.initializer)) {
var attributeText = attribute.initializer.text;
if (condition(attributeText)) {
return true;
}
}
}
}
return false;
}
function isExcludedInputType(node, attributes) {
function isNecessaryDynamicAccess(argumentExpression: ts.Expression): boolean {
if (isNumberLike(argumentExpression)) {
return true;
}
return (
tsutils.isStringLiteral(argumentExpression) &&
!tsutils.isValidPropertyAccess(argumentExpression.text)
);
}
function addImport(moduleReference: ts.Expression): void {
if (util.isStringLiteral(moduleReference)) {
imports.add(moduleReference.text);
}
}
function cb(node) {
if (tsutils.isStringLiteral(node) || node.kind === ts.SyntaxKind.FirstTemplateToken) {
failOnOctalString(node);
}
return ts.forEachChild(node, cb);
}
return ts.forEachChild(ctx.sourceFile, cb);