Skip to content

⬅️ Back to Table of Contents

📄 max-params

📊 Analysis Summary

Metric Count
🔧 Functions 3
📦 Imports 6
📑 Type Aliases 4

📚 Table of Contents

🛠️ File Location:

📂 packages/eslint-plugin/src/rules/max-params.ts

📤 Default Export

export default createRule<Options, MessageIds>({ ... })
Property Value
name 'max-params'
meta.type 'suggestion'
meta.docs.description 'Enforce a maximum number of parameters in function definitions'
meta.docs.extendsBaseRule true
meta.messages baseRule.meta.messages
meta.schema [ { type: 'object', additionalProperties: false, properties: { countVoidThis: { type: 'boolean', description: 'Whethe...
defaultOptions [{ countVoidThis: false, max: 3 }]

Entry point: create — documented under Functions.


📦 Imports

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

Functions

create(context: any, [{ countVoidThis }]: any): any

Parameters:

  • context any
  • [{ countVoidThis }] any

Returns: any

Calls:

  • baseRule.create
  • node.params.slice
  • listener
  • removeVoidThisParam
  • wrapListener
Code
create(context, [{ countVoidThis }]) {
    const baseRules = baseRule.create(context);

    if (countVoidThis === true) {
      return baseRules;
    }

    const removeVoidThisParam = <T extends FunctionLike>(node: T): T => {
      if (
        node.params.length === 0 ||
        node.params[0].type !== AST_NODE_TYPES.Identifier ||
        node.params[0].name !== 'this' ||
        node.params[0].typeAnnotation?.typeAnnotation.type !==
          AST_NODE_TYPES.TSVoidKeyword
      ) {
        return node;
      }

      return {
        ...node,
        params: node.params.slice(1),
      };
    };

    const wrapListener = <T extends FunctionLike>(
      listener: FunctionRuleListener<T>,
    ): FunctionRuleListener<T> => {
      return (node: T): void => {
        listener(removeVoidThisParam(node));
      };
    };

    return {
      ArrowFunctionExpression: wrapListener(baseRules.ArrowFunctionExpression),
      FunctionDeclaration: wrapListener(baseRules.FunctionDeclaration),
      FunctionExpression: wrapListener(baseRules.FunctionExpression),
      TSDeclareFunction: wrapListener(baseRules.FunctionDeclaration),
      TSFunctionType: wrapListener(baseRules.FunctionDeclaration),
    };
  }

Internal helpers

Declared inside another function in this file.

removeVoidThisParam(node: T): T

Parameters:

  • node T

Returns: T

Calls:

  • node.params.slice
Code
<T extends FunctionLike>(node: T): T => {
      if (
        node.params.length === 0 ||
        node.params[0].type !== AST_NODE_TYPES.Identifier ||
        node.params[0].name !== 'this' ||
        node.params[0].typeAnnotation?.typeAnnotation.type !==
          AST_NODE_TYPES.TSVoidKeyword
      ) {
        return node;
      }

      return {
        ...node,
        params: node.params.slice(1),
      };
    }

wrapListener(listener: FunctionRuleListener<T>): FunctionRuleListener<T>

Parameters:

  • listener FunctionRuleListener<T>

Returns: FunctionRuleListener<T>

Calls:

  • listener
  • removeVoidThisParam
Code
<T extends FunctionLike>(
      listener: FunctionRuleListener<T>,
    ): FunctionRuleListener<T> => {
      return (node: T): void => {
        listener(removeVoidThisParam(node));
      };
    }

Type Aliases

FunctionLike

type FunctionLike = | TSESTree.ArrowFunctionExpression
  | TSESTree.FunctionDeclaration
  | TSESTree.FunctionExpression
  | TSESTree.TSDeclareFunction
  | TSESTree.TSFunctionType;

FunctionRuleListener<T extends FunctionLike>

type FunctionRuleListener<T extends FunctionLike> = (node: T) => void;

Options

type Options = InferOptionsTypeFromRule<typeof baseRule>;

MessageIds

type MessageIds = InferMessageIdsTypeFromRule<typeof baseRule>;

Generated by Syntax Scribe