How to use the tsutils.isPropertyAccessExpression 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 microsoft / tslint-microsoft-contrib / src / chaiVagueErrorsRule.ts View on Github external
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())) {
github cartant / tslint-etc / source / rules / noUnsafeCallbackScopeRule.ts View on Github external
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;
}
github fossasia / susper.com / node_modules / tslint / lib / rules / radixRule.js View on Github external
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) {
github palantir / tslint / src / rules / newlinePerChainedCallRule.ts View on Github external
function hasChildCall(node: ts.PropertyAccessExpression): boolean {
    let { expression } = node;
    while (isPropertyAccessExpression(expression) || isElementAccessExpression(expression)) {
        ({ expression } = expression);
    }
    return expression.kind === ts.SyntaxKind.CallExpression;
}
github nativescript-rtl / ui / node_modules / tslint / lib / rules / radixRule.js View on Github external
function isPropertyAccessParseInt(expression) {
    return tsutils_1.isPropertyAccessExpression(expression) && expression.name.text === "parseInt";
}
function isPropertyAccessOfIdentifier(expression, identifiers) {
github microsoft / tslint-microsoft-contrib / noCookiesRule.js View on Github external
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);
                    }
                }
            }
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);
                    }
                }
            } 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);
github fossasia / susper.com / node_modules / tslint / lib / rules / deprecationRule.js View on Github external
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) {
github cartant / tslint-etc / source / rules / noUnsafeCallbackScopeRule.ts View on Github external
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;
      }
github palantir / tslint / src / rules / banRule.ts View on Github external
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);