How to use the @typescript-eslint/experimental-utils.AST_NODE_TYPES.AssignmentPattern 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 / explicit-member-accessibility.ts View on Github external
function checkParameterPropertyAccessibilityModifier(
      node: TSESTree.TSParameterProperty,
    ): void {
      const nodeType = 'parameter property';
      // HAS to be an identifier or assignment or TSC will throw
      if (
        node.parameter.type !== AST_NODE_TYPES.Identifier &&
        node.parameter.type !== AST_NODE_TYPES.AssignmentPattern
      ) {
        return;
      }

      const nodeName =
        node.parameter.type === AST_NODE_TYPES.Identifier
          ? node.parameter.name
          : // has to be an Identifier or TSC will throw an error
            (node.parameter.left as TSESTree.Identifier).name;

      switch (paramPropCheck) {
        case 'explicit': {
          if (!node.accessibility) {
            reportIssue('missingAccessibility', nodeType, node, nodeName);
          }
          break;
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / indent-new-do-not-use / index.ts View on Github external
} from 'eslint-utils';
import { TokenOrComment } from './BinarySearchTree';
import { OffsetStorage } from './OffsetStorage';
import { TokenInfo } from './TokenInfo';
import { createRule, ExcludeKeys, RequireKeys } from '../../util';

const GLOBAL_LINEBREAK_REGEX = /\r\n|[\r\n\u2028\u2029]/gu;
const WHITESPACE_REGEX = /\s*$/u;

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

const KNOWN_NODES = new Set([
  AST_NODE_TYPES.AssignmentExpression,
  AST_NODE_TYPES.AssignmentPattern,
  AST_NODE_TYPES.ArrayExpression,
  AST_NODE_TYPES.ArrayPattern,
  AST_NODE_TYPES.ArrowFunctionExpression,
  AST_NODE_TYPES.AwaitExpression,
  AST_NODE_TYPES.BlockStatement,
  AST_NODE_TYPES.BinaryExpression,
  AST_NODE_TYPES.BreakStatement,
  AST_NODE_TYPES.CallExpression,
  AST_NODE_TYPES.CatchClause,
  AST_NODE_TYPES.ClassBody,
  AST_NODE_TYPES.ClassDeclaration,
  AST_NODE_TYPES.ClassExpression,
  AST_NODE_TYPES.ConditionalExpression,
  AST_NODE_TYPES.ContinueStatement,
  AST_NODE_TYPES.DoWhileStatement,
  AST_NODE_TYPES.DebuggerStatement,
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / no-parameter-properties.ts View on Github external
TSParameterProperty(node): void {
        const modifiers = getModifiers(node);

        if (!allows.includes(modifiers)) {
          // HAS to be an identifier or assignment or TSC will throw
          if (
            node.parameter.type !== AST_NODE_TYPES.Identifier &&
            node.parameter.type !== AST_NODE_TYPES.AssignmentPattern
          ) {
            return;
          }

          const name =
            node.parameter.type === AST_NODE_TYPES.Identifier
              ? node.parameter.name
              : // has to be an Identifier or TSC will throw an error
                (node.parameter.left as TSESTree.Identifier).name;

          context.report({
            node,
            messageId: 'noParamProp',
            data: {
              parameter: name,
            },
github microsoft / fluent-ui-react / packages / eslint-plugin / rules / no-visibility-modifiers / index.js View on Github external
function checkParameterPropertyAccessibilityModifier(node) {
      const nodeType = 'parameter property'

      if (isTypeScriptFile(context.getFilename())) {
        // HAS to be an identifier or assignment or TSC will throw
        if (
          node.parameter.type !== AST_NODE_TYPES.Identifier &&
          node.parameter.type !== AST_NODE_TYPES.AssignmentPattern
        ) {
          return
        }

        const nodeName =
          node.parameter.type === AST_NODE_TYPES.Identifier
            ? node.parameter.name
            : // has to be an Identifier or TSC will throw an error
              node.parameter.left.name

        if (!!node.accessibility) {
          reportIssue('presentModifier', nodeType, node, nodeName)
        }
      }
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / typedef.ts View on Github external
function checkParameters(params: TSESTree.Parameter[]): void {
      for (const param of params) {
        let annotationNode: TSESTree.Node | undefined;

        switch (param.type) {
          case AST_NODE_TYPES.AssignmentPattern:
            annotationNode = param.left;
            break;
          case AST_NODE_TYPES.TSParameterProperty:
            annotationNode = param.parameter;

            // Check TS parameter property with default value like `constructor(private param: string = 'something') {}`
            if (
              annotationNode &&
              annotationNode.type === AST_NODE_TYPES.AssignmentPattern
            ) {
              annotationNode = annotationNode.left;
            }

            break;
          default:
            annotationNode = param;
            break;
        }

        if (annotationNode !== undefined && !annotationNode.typeAnnotation) {
          report(param, getNodeName(param));
        }
      }
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / no-use-before-define.ts View on Github external
while (node) {
    if (node.type === AST_NODE_TYPES.VariableDeclarator) {
      if (isInRange(node.init, location)) {
        return true;
      }
      if (
        node.parent &&
        node.parent.parent &&
        (node.parent.parent.type === AST_NODE_TYPES.ForInStatement ||
          node.parent.parent.type === AST_NODE_TYPES.ForOfStatement) &&
        isInRange(node.parent.parent.right, location)
      ) {
        return true;
      }
      break;
    } else if (node.type === AST_NODE_TYPES.AssignmentPattern) {
      if (isInRange(node.right, location)) {
        return true;
      }
    } else if (SENTINEL_TYPE.test(node.type)) {
      break;
    }

    node = node.parent;
  }

  return false;
}
github jonaskello / eslint-plugin-functional / src / util / typeguard.ts View on Github external
export function isAssignmentPattern(
  node: TSESTree.Node
): node is TSESTree.AssignmentPattern {
  return node.type === AST_NODE_TYPES.AssignmentPattern;
}
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / camelcase.ts View on Github external
function isTSPropertyType(node: TSESTree.Node): boolean {
      if (TS_PROPERTY_TYPES.includes(node.type)) {
        return true;
      }

      if (node.type === AST_NODE_TYPES.AssignmentPattern) {
        return (
          node.parent !== undefined &&
          TS_PROPERTY_TYPES.includes(node.parent.type)
        );
      }

      return false;
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / no-inferrable-types.ts View on Github external
param =>
          param.type === AST_NODE_TYPES.AssignmentPattern &&
          param.left &&
          param.right,
      ) as TSESTree.AssignmentPattern[]).forEach(param => {
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / member-naming.ts View on Github external
function getParameterNode(
      node: TSESTree.TSParameterProperty,
    ): TSESTree.Identifier | null {
      if (node.parameter.type === AST_NODE_TYPES.AssignmentPattern) {
        return node.parameter.left as TSESTree.Identifier;
      }

      if (node.parameter.type === AST_NODE_TYPES.Identifier) {
        return node.parameter;
      }

      return null;
    }

@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