]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/max-params.js
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 //------------------------------------------------------------------------------
19 /** @type {import('../shared/types').Rule} */
25 description
: "Enforce a maximum number of parameters in function definitions",
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