How to use the eslint-utils.getPropertyName function in eslint-utils

To help you get started, we’ve selected a few eslint-utils 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 mysticatea / eslint-plugin-node / lib / rules / no-unsupported-features.js View on Github external
// Check static methods.
                for (const reference of getReferences(
                    Object.keys(PROPERTY_TEST_TARGETS)
                )) {
                    const node = reference.identifier
                    const parentNode = node.parent
                    if (
                        parentNode.type !== "MemberExpression" ||
                        parentNode.object !== node
                    ) {
                        continue
                    }

                    const objectName = node.name
                    const properties = PROPERTY_TEST_TARGETS[objectName]
                    const propertyName = getPropertyName(parentNode)
                    if (
                        propertyName &&
                        properties.indexOf(propertyName) !== -1
                    ) {
                        report(parentNode, `${objectName}.${propertyName}`)
                    }
                }

                // Check subclassing
                for (const reference of getReferences(
                    SUBCLASSING_TEST_TARGETS
                )) {
                    const node = reference.identifier
                    const parentNode = node.parent
                    if (
                        CLASS_TYPE.test(parentNode.type) &&
github mysticatea / eslint-plugin-node / lib / rules / no-unsupported-features.js View on Github external
"Program:exit"() {
                // Check new global variables.
                for (const name of NEW_BUILTIN_TYPES) {
                    for (const reference of getReferences([name])) {
                        // Ignore if it's using new static methods.
                        const node = reference.identifier
                        const parentNode = node.parent
                        const properties = PROPERTY_TEST_TARGETS[name]
                        if (
                            properties &&
                            parentNode.type === "MemberExpression"
                        ) {
                            const propertyName = getPropertyName(parentNode)
                            if (properties.indexOf(propertyName) !== -1) {
                                continue
                            }
                        }

                        report(reference.identifier, name)
                    }
                }

                // Check static methods.
                for (const reference of getReferences(
                    Object.keys(PROPERTY_TEST_TARGETS)
                )) {
                    const node = reference.identifier
                    const parentNode = node.parent
                    if (
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / prefer-string-starts-ends-with.ts View on Github external
function isLengthExpression(
      node: TSESTree.Node,
      expectedObjectNode: TSESTree.Node,
    ): boolean {
      if (node.type === 'MemberExpression') {
        return (
          getPropertyName(node, globalScope) === 'length' &&
          isSameTokens(node.object, expectedObjectNode)
        );
      }

      const evaluatedLength = getStaticValue(node, globalScope);
      const evaluatedString = getStaticValue(expectedObjectNode, globalScope);
      return (
        evaluatedLength != null &&
        evaluatedString != null &&
        typeof evaluatedLength.value === 'number' &&
        typeof evaluatedString.value === 'string' &&
        evaluatedLength.value === evaluatedString.value.length
      );
    }
github sikidamjanovic / cowrite / node_modules / @typescript-eslint / eslint-plugin / dist / rules / prefer-string-starts-ends-with.js View on Github external
function isLengthExpression(node, expectedObjectNode) {
            if (node.type === 'MemberExpression') {
                return (eslint_utils_1.getPropertyName(node, globalScope) === 'length' &&
                    isSameTokens(node.object, expectedObjectNode));
            }
            const evaluatedLength = eslint_utils_1.getStaticValue(node, globalScope);
            const evaluatedString = eslint_utils_1.getStaticValue(expectedObjectNode, globalScope);
            return (evaluatedLength != null &&
                evaluatedString != null &&
                typeof evaluatedLength.value === 'number' &&
                typeof evaluatedString.value === 'string' &&
                evaluatedLength.value === evaluatedString.value.length);
        }
        /**