max-params
在函数定义中强制执行最大数量的参数
带有大量参数的函数可能难以读写,因为它需要记住每个参数是什么、它的类型以及它们应该出现的顺序。因此,许多编码人员遵守了一个约定,该约定限制了函数可以采用的参数数量。
¥Functions that take numerous parameters can be difficult to read and write because it requires the memorization of what each parameter is, its type, and the order they should appear in. As a result, many coders adhere to a convention that caps the number of parameters a function can take.
function foo (bar, baz, qux, qxx) { // four parameters, may be too many
doSomething();
}
规则详情
¥Rule Details
此规则强制执行函数定义中允许的最大参数数量。
¥This rule enforces a maximum number of parameters allowed in function definitions.
选项
¥Options
此规则有一个数字或对象选项:
¥This rule has a number or object option:
-
"max"
(默认3
)强制函数定义中参数的最大数量¥
"max"
(default3
) enforces a maximum number of parameters in function definitions
已弃用:对象属性 maximum
已弃用;请改用对象属性 max
。
¥Deprecated: The object property maximum
is deprecated; please use the object property max
instead.
max
使用默认 { "max": 3 }
选项的此规则的错误代码示例:
¥Examples of incorrect code for this rule with the default { "max": 3 }
option:
/*eslint max-params: ["error", 3]*/
function foo1 (bar, baz, qux, qxx) {
doSomething();
}
let foo2 = (bar, baz, qux, qxx) => {
doSomething();
};
使用默认 { "max": 3 }
选项的此规则的正确代码示例:
¥Examples of correct code for this rule with the default { "max": 3 }
option:
/*eslint max-params: ["error", 3]*/
function foo1 (bar, baz, qux) {
doSomething();
}
let foo2 = (bar, baz, qux) => {
doSomething();
};
相关规则
版本
此规则是在 ESLint v0.0.9 中引入。