How to use the tsutils.isStringLiteral function in tsutils

To help you get started, we’ve selected a few tsutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github palantir / tslint / src / rules / noStringLiteralRule.ts View on Github external
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,
github intershop / intershop-pwa / tslint-rules / src / ishOrderedImportsRule.ts View on Github external
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);
  }
github palantir / tslint / src / rules / noTautologyExpressionRule.ts View on Github external
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);
github fossasia / susper.com / node_modules / tslint / lib / rules / noDynamicDeleteRule.js View on Github external
function isNecessaryDynamicAccess(argumentExpression) {
    if (isNumberLike(argumentExpression)) {
        return true;
    }
    return (tsutils.isStringLiteral(argumentExpression) &&
        !tsutils.isValidPropertyAccess(argumentExpression.text));
}
var templateObject_1;
github microsoft / tslint-microsoft-contrib / noJqueryRawElementsRule.js View on Github external
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);
github microsoft / tslint-microsoft-contrib / reactA11yInputElementsRule.js View on Github external
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) {
github palantir / tslint / src / rules / noDynamicDeleteRule.ts View on Github external
function isNecessaryDynamicAccess(argumentExpression: ts.Expression): boolean {
    if (isNumberLike(argumentExpression)) {
        return true;
    }

    return (
        tsutils.isStringLiteral(argumentExpression) &&
        !tsutils.isValidPropertyAccess(argumentExpression.text)
    );
}
github microsoft / dtslint / src / rules / noReferenceImportRule.ts View on Github external
function addImport(moduleReference: ts.Expression): void {
		if (util.isStringLiteral(moduleReference)) {
			imports.add(moduleReference.text);
		}
	}
github microsoft / tslint-microsoft-contrib / noOctalLiteralRule.js View on Github external
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);