]>
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 //------------------------------------------------------------------------------
24 description
: "enforce a maximum number of parameters in function definitions",
26 url
: "https://eslint.org/docs/rules/max-params"
48 additionalProperties
: false
54 exceed
: "{{name}} has too many parameters ({{count}}). Maximum allowed is {{max}}."
59 const sourceCode
= context
.getSourceCode();
60 const option
= context
.options
[0];
64 typeof option
=== "object" &&
65 (Object
.prototype.hasOwnProperty
.call(option
, "maximum") || Object
.prototype.hasOwnProperty
.call(option
, "max"))
67 numParams
= option
.maximum
|| option
.max
;
69 if (typeof option
=== "number") {
74 * Checks a function to see if it has too many parameters.
75 * @param {ASTNode} node The node to check.
79 function checkFunction(node
) {
80 if (node
.params
.length
> numParams
) {
82 loc
: astUtils
.getFunctionHeadLoc(node
, sourceCode
),
86 name
: upperCaseFirst(astUtils
.getFunctionNameWithKind(node
)),
87 count
: node
.params
.length
,
95 FunctionDeclaration
: checkFunction
,
96 ArrowFunctionExpression
: checkFunction
,
97 FunctionExpression
: checkFunction