Skip to content

⬅️ Back to Table of Contents

📄 parameter-properties.ts

📊 Analysis Summary

Metric Count
🔧 Functions 3
📦 Imports 4
📊 Variables & Constants 5
📐 Interfaces 1
📑 Type Aliases 4

📚 Table of Contents

🛠️ File Location:

📂 packages/eslint-plugin/src/rules/parameter-properties.ts

📦 Imports

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

Variables & Constants

Name Type Kind Value Exported
modifiers Modifier[] const []
name any const `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`
propertyNodesByNameStack Map<string, PropertyNodes>[] const []
propertyNodesByName Map<string, PropertyNodes> const propertyNodesByNameStack[propertyNodesByNameStack.length - 1]
created PropertyNodes const {}

Functions

getModifiers(node: TSESTree.PropertyDefinition | TSESTree.TSParameterProperty): Modifier

Code
function getModifiers(
      node: TSESTree.PropertyDefinition | TSESTree.TSParameterProperty,
    ): Modifier {
      const modifiers: Modifier[] = [];

      if (node.accessibility) {
        modifiers.push(node.accessibility);
      }
      if (node.readonly) {
        modifiers.push('readonly');
      }

      return modifiers.filter(Boolean).join(' ') as Modifier;
    }
  • JSDoc:

    /**
         * Gets the modifiers of `node`.
         * @param node the node to be inspected.
         */
    

  • Parameters:

  • node: TSESTree.PropertyDefinition | TSESTree.TSParameterProperty
  • Return Type: Modifier
  • Calls:
  • modifiers.push
  • modifiers.filter(Boolean).join

getNodesByName(name: string): PropertyNodes

Code
function getNodesByName(name: string): PropertyNodes {
      const propertyNodesByName =
        propertyNodesByNameStack[propertyNodesByNameStack.length - 1];
      const existing = propertyNodesByName.get(name);
      if (existing) {
        return existing;
      }

      const created: PropertyNodes = {};
      propertyNodesByName.set(name, created);
      return created;
    }
  • Parameters:
  • name: string
  • Return Type: PropertyNodes
  • Calls:
  • propertyNodesByName.get
  • propertyNodesByName.set

typeAnnotationsMatch(classProperty: TSESTree.PropertyDefinition, constructorParameter: TSESTree.Identifier): boolean

Code
function typeAnnotationsMatch(
      classProperty: TSESTree.PropertyDefinition,
      constructorParameter: TSESTree.Identifier,
    ): boolean {
      if (
        !classProperty.typeAnnotation ||
        !constructorParameter.typeAnnotation
      ) {
        return (
          classProperty.typeAnnotation === constructorParameter.typeAnnotation
        );
      }

      return (
        context.sourceCode.getText(classProperty.typeAnnotation) ===
        context.sourceCode.getText(constructorParameter.typeAnnotation)
      );
    }
  • Parameters:
  • classProperty: TSESTree.PropertyDefinition
  • constructorParameter: TSESTree.Identifier
  • Return Type: boolean
  • Calls:
  • context.sourceCode.getText

Interfaces

PropertyNodes

Interface Code
interface PropertyNodes {
      classProperty?: TSESTree.PropertyDefinition;
      constructorAssignment?: TSESTree.AssignmentExpression;
      constructorParameter?: TSESTree.Identifier;
    }

Properties

Name Type Optional Description
classProperty TSESTree.PropertyDefinition
constructorAssignment TSESTree.AssignmentExpression
constructorParameter TSESTree.Identifier

Type Aliases

Modifier

type Modifier = | 'private'
  | 'private readonly'
  | 'protected'
  | 'protected readonly'
  | 'public'
  | 'public readonly'
  | 'readonly';

Prefer

type Prefer = 'class-property' | 'parameter-property';

Options

type Options = [
  {
    allow?: Modifier[];
    prefer?: Prefer;
  },
];

MessageIds

type MessageIds = 'preferClassProperty' | 'preferParameterProperty';