2 * @fileoverview Rule to flag when a function has too many parameters
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const lodash = require("lodash");
14 const astUtils = require("./utils/ast-utils");
16 //------------------------------------------------------------------------------
18 //------------------------------------------------------------------------------
25 description: "enforce a maximum number of parameters in function definitions",
26 category: "Stylistic Issues",
28 url: "https://eslint.org/docs/rules/max-params"
50 additionalProperties: false
56 exceed: "{{name}} has too many parameters ({{count}}). Maximum allowed is {{max}}."
61 const sourceCode = context.getSourceCode();
62 const option = context.options[0];
66 typeof option === "object" &&
67 (Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
69 numParams = option.maximum || option.max;
71 if (typeof option === "number") {
76 * Checks a function to see if it has too many parameters.
77 * @param {ASTNode} node The node to check.
81 function checkFunction(node) {
82 if (node.params.length > numParams) {
84 loc: astUtils.getFunctionHeadLoc(node, sourceCode),
88 name: lodash.upperFirst(astUtils.getFunctionNameWithKind(node)),
89 count: node.params.length,
97 FunctionDeclaration: checkFunction,
98 ArrowFunctionExpression: checkFunction,
99 FunctionExpression: checkFunction