useMaxParams
¥Summary
-
规则生效日期:
v2.2.0¥Rule available since:
v2.2.0 -
诊断类别:
lint/nursery/useMaxParams¥Diagnostic Category:
lint/nursery/useMaxParams -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
与
max-params相同¥Same as
max-params -
与
too_many_arguments相同¥Same as
too_many_arguments -
与
@typescript-eslint/max-params相同¥Same as
@typescript-eslint/max-params
-
¥How to configure
{ "linter": { "rules": { "nursery": { "useMaxParams": "error" } } }}¥Description
强制函数定义中参数的最大数量。
¥Enforce a maximum number of parameters in function definitions.
接受大量参数的函数可能难以阅读和编写,因为它需要记住每个参数是什么、它们的类型以及它们的出现顺序。
¥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.
¥Examples
¥Invalid
function foo(a, b, c, d, e, f, g, h) { // too many parameters}code-block.js:1:13 lint/nursery/useMaxParams ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Function has 8 parameters, but only 4 are allowed.
> 1 │ function foo(a, b, c, d, e, f, g, h) {
│ ^^^^^^^^^^^^^^^^^^^^^^^^
2 │ // too many parameters
3 │ }
ℹ Functions with many parameters are hard to read and maintain.
ℹ Consider using an options object, splitting into smaller functions, or grouping related parameters.
const bar = (a, b, c, d, e, f, g, h) => { // too many parameters}code-block.js:1:13 lint/nursery/useMaxParams ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Function has 8 parameters, but only 4 are allowed.
> 1 │ const bar = (a, b, c, d, e, f, g, h) => {
│ ^^^^^^^^^^^^^^^^^^^^^^^^
2 │ // too many parameters
3 │ }
ℹ Functions with many parameters are hard to read and maintain.
ℹ Consider using an options object, splitting into smaller functions, or grouping related parameters.
class Baz { method(a, b, c, d, e, f, g, h) { // too many parameters }}code-block.js:2:11 lint/nursery/useMaxParams ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Function has 8 parameters, but only 4 are allowed.
1 │ class Baz {
> 2 │ method(a, b, c, d, e, f, g, h) {
│ ^^^^^^^^^^^^^^^^^^^^^^^^
3 │ // too many parameters
4 │ }
ℹ Functions with many parameters are hard to read and maintain.
ℹ Consider using an options object, splitting into smaller functions, or grouping related parameters.
¥Valid
function foo(a, b, c) { // within limit}const bar = (a, b, c) => { // within limit}class Baz { method(a, b, c) { // within limit }}¥Options
允许的最大参数数量(默认值:4)。
¥The maximum number of parameters allowed (default: 4).
¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号