How to use the @typescript-eslint/experimental-utils.AST_NODE_TYPES.RestElement function in @typescript-eslint/experimental-utils

To help you get started, we’ve selected a few @typescript-eslint/experimental-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 typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / prefer-for-of.ts View on Github external
// a[i]++, --a[i], etc.
      if (
        parent.type === AST_NODE_TYPES.UpdateExpression &&
        parent.argument === node
      ) {
        return true;
      }

      // [a[i]] = [0]
      if (parent.type === AST_NODE_TYPES.ArrayPattern) {
        return true;
      }

      // [...a[i]] = [0]
      if (parent.type === AST_NODE_TYPES.RestElement) {
        return true;
      }

      // ({ foo: a[i] }) = { foo: 0 }
      if (
        parent.type === AST_NODE_TYPES.Property &&
        parent.value === node &&
        parent.parent?.type === AST_NODE_TYPES.ObjectExpression &&
        isAssignee(parent.parent)
      ) {
        return true;
      }

      return false;
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / naming-convention.ts View on Github external
pattern.properties.forEach(property => {
        if (property.type === AST_NODE_TYPES.RestElement) {
          getIdentifiersFromPattern(property, identifiers);
        } else {
          // this is a bit weird, but it's because ESTree doesn't have a new node type
          // for object destructuring properties - it just reuses Property...
          // https://github.com/estree/estree/blob/9ae284b71130d53226e7153b42f01bf819e6e657/es2015.md#L206-L211
          // However, the parser guarantees this is safe (and there is error handling)
          getIdentifiersFromPattern(
            property.value as TSESTree.DestructuringPattern,
            identifiers,
          );
        }
      });
      break;
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / unified-signatures.ts View on Github external
if (
        !util.arraysAreEqual(
          types1.slice(index + 1),
          types2.slice(index + 1),
          parametersAreEqual,
        )
      ) {
        return undefined;
      }

      const a = types1[index];
      const b = types2[index];
      // Can unify `a?: string` and `b?: number`. Can't unify `...args: string[]` and `...args: number[]`.
      // See https://github.com/Microsoft/TypeScript/issues/5077
      return parametersHaveEqualSigils(a, b) &&
        a.type !== AST_NODE_TYPES.RestElement
        ? { kind: 'single-parameter-difference', p0: a, p1: b }
        : undefined;
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / naming-convention.ts View on Github external
if (property.type === AST_NODE_TYPES.RestElement) {
          getIdentifiersFromPattern(property, identifiers);
        } else {
          // this is a bit weird, but it's because ESTree doesn't have a new node type
          // for object destructuring properties - it just reuses Property...
          // https://github.com/estree/estree/blob/9ae284b71130d53226e7153b42f01bf819e6e657/es2015.md#L206-L211
          // However, the parser guarantees this is safe (and there is error handling)
          getIdentifiersFromPattern(
            property.value as TSESTree.DestructuringPattern,
            identifiers,
          );
        }
      });
      break;

    case AST_NODE_TYPES.RestElement:
      getIdentifiersFromPattern(pattern.argument, identifiers);
      break;

    case AST_NODE_TYPES.AssignmentPattern:
      getIdentifiersFromPattern(pattern.left, identifiers);
      break;

    case AST_NODE_TYPES.MemberExpression:
      // ignore member expressions, as the everything must already be defined
      break;

    default:
      // https://github.com/typescript-eslint/typescript-eslint/issues/1282
      // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
      throw new Error(`Unexpected pattern type ${pattern!.type}`);
  }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / no-explicit-any.ts View on Github external
function isNodeRestElementInFunction(node: TSESTree.Node): boolean {
      return (
        node.type === AST_NODE_TYPES.RestElement &&
        typeof node.parent !== 'undefined' &&
        isNodeValidFunction(node.parent)
      );
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / unified-signatures.ts View on Github external
function parametersHaveEqualSigils(
      a: TSESTree.Parameter,
      b: TSESTree.Parameter,
    ): boolean {
      const optionalA = isTSParameterProperty(a)
        ? a.parameter.optional
        : a.optional;
      const optionalB = isTSParameterProperty(b)
        ? b.parameter.optional
        : b.optional;

      return (
        (a.type === AST_NODE_TYPES.RestElement) ===
          (b.type === AST_NODE_TYPES.RestElement) &&
        (optionalA !== undefined) === (optionalB !== undefined)
      );
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / unified-signatures.ts View on Github external
const sig2i = sig2[i];
        const typeAnnotation1 = isTSParameterProperty(sig1i)
          ? sig1i.parameter.typeAnnotation
          : sig1i.typeAnnotation;
        const typeAnnotation2 = isTSParameterProperty(sig2i)
          ? sig2i.parameter.typeAnnotation
          : sig2i.typeAnnotation;

        if (!typesAreEqual(typeAnnotation1, typeAnnotation2)) {
          return undefined;
        }
      }

      if (
        minLength > 0 &&
        shorter[minLength - 1].type === AST_NODE_TYPES.RestElement
      ) {
        return undefined;
      }

      return {
        extraParameter: longer[longer.length - 1],
        kind: 'extra-parameter',
        otherSignature: shorterSig,
      };
    }
github jonaskello / eslint-plugin-functional / src / util / typeguard.ts View on Github external
export function isRestElement(
  node: TSESTree.Node
): node is TSESTree.RestElement {
  return node.type === AST_NODE_TYPES.RestElement;
}

@typescript-eslint/experimental-utils

(Experimental) Utilities for working with TypeScript + ESLint together

MIT
Latest version published 11 months ago

Package Health Score

91 / 100
Full package analysis