Skip to content

⬅️ Back to Table of Contents

📄 no-misused-new.ts

📊 Analysis Summary

Metric Count
🔧 Functions 2
📦 Imports 3

📚 Table of Contents

🛠️ File Location:

📂 packages/eslint-plugin/src/rules/no-misused-new.ts

📦 Imports

Name Source
TSESTree @typescript-eslint/utils
AST_NODE_TYPES @typescript-eslint/utils
createRule ../util

Functions

`getTypeReferenceName(node: | TSESTree.EntityName

    | TSESTree.TSTypeAnnotation
    | TSESTree.TypeNode
    | undefined): string | null`
Code
function getTypeReferenceName(
      node:
        | TSESTree.EntityName
        | TSESTree.TSTypeAnnotation
        | TSESTree.TypeNode
        | undefined,
    ): string | null {
      if (node) {
        switch (node.type) {
          case AST_NODE_TYPES.TSTypeAnnotation:
            return getTypeReferenceName(node.typeAnnotation);
          case AST_NODE_TYPES.TSTypeReference:
            return getTypeReferenceName(node.typeName);
          case AST_NODE_TYPES.Identifier:
            return node.name;
          default:
            break;
        }
      }
      return null;
    }
  • JSDoc:

    /**
         * @param node type to be inspected.
         * @returns name of simple type or null
         */
    

  • Parameters:

  • node: | TSESTree.EntityName | TSESTree.TSTypeAnnotation | TSESTree.TypeNode | undefined
  • Return Type: string | null
  • Calls:
  • getTypeReferenceName

`isMatchingParentType(parent: | TSESTree.ClassDeclaration

    | TSESTree.ClassExpression
    | TSESTree.Identifier
    | TSESTree.TSInterfaceDeclaration
    | undefined, returnType: TSESTree.TSTypeAnnotation | undefined): boolean`
Code
function isMatchingParentType(
      parent:
        | TSESTree.ClassDeclaration
        | TSESTree.ClassExpression
        | TSESTree.Identifier
        | TSESTree.TSInterfaceDeclaration
        | undefined,
      returnType: TSESTree.TSTypeAnnotation | undefined,
    ): boolean {
      if (
        parent &&
        (parent.type === AST_NODE_TYPES.ClassDeclaration ||
          parent.type === AST_NODE_TYPES.ClassExpression ||
          parent.type === AST_NODE_TYPES.TSInterfaceDeclaration) &&
        parent.id
      ) {
        return getTypeReferenceName(returnType) === parent.id.name;
      }
      return false;
    }
  • JSDoc:

    /**
         * @param parent parent node.
         * @param returnType type to be compared
         */
    

  • Parameters:

  • parent: | TSESTree.ClassDeclaration | TSESTree.ClassExpression | TSESTree.Identifier | TSESTree.TSInterfaceDeclaration | undefined
  • returnType: TSESTree.TSTypeAnnotation | undefined
  • Return Type: boolean
  • Calls:
  • getTypeReferenceName