2 * @fileoverview Rule to flag when a function has too many parameters
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const astUtils = require("./utils/ast-utils");
13 const { upperCaseFirst } = require("../shared/string-utils");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
24 description: "enforce a maximum number of parameters in function definitions",
25 category: "Stylistic Issues",
27 url: "https://eslint.org/docs/rules/max-params"
49 additionalProperties: false
55 exceed: "{{name}} has too many parameters ({{count}}). Maximum allowed is {{max}}."
60 const sourceCode = context.getSourceCode();
61 const option = context.options[0];
65 typeof option === "object" &&
66 (Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
68 numParams = option.maximum || option.max;
70 if (typeof option === "number") {
75 * Checks a function to see if it has too many parameters.
76 * @param {ASTNode} node The node to check.
80 function checkFunction(node) {
81 if (node.params.length > numParams) {
83 loc: astUtils.getFunctionHeadLoc(node, sourceCode),
87 name: upperCaseFirst(astUtils.getFunctionNameWithKind(node)),
88 count: node.params.length,
96 FunctionDeclaration: checkFunction,
97 ArrowFunctionExpression: checkFunction,
98 FunctionExpression: checkFunction