mirror of
https://git.proxmox.com/git/pve-eslint
synced 2025-10-05 11:41:00 +00:00

includes a (minimal) working wrapper Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
64 lines
1.6 KiB
Markdown
64 lines
1.6 KiB
Markdown
# enforce a maximum number of parameters in function definitions (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.
|
|
|
|
```js
|
|
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"` (default `3`) enforces a maximum number of parameters in function definitions
|
|
|
|
**Deprecated:** The object property `maximum` is deprecated; please use the object property `max` instead.
|
|
|
|
### max
|
|
|
|
Examples of **incorrect** code for this rule with the default `{ "max": 3 }` option:
|
|
|
|
```js
|
|
/*eslint max-params: ["error", 3]*/
|
|
/*eslint-env es6*/
|
|
|
|
function foo (bar, baz, qux, qxx) {
|
|
doSomething();
|
|
}
|
|
|
|
let foo = (bar, baz, qux, qxx) => {
|
|
doSomething();
|
|
};
|
|
```
|
|
|
|
Examples of **correct** code for this rule with the default `{ "max": 3 }` option:
|
|
|
|
```js
|
|
/*eslint max-params: ["error", 3]*/
|
|
/*eslint-env es6*/
|
|
|
|
function foo (bar, baz, qux) {
|
|
doSomething();
|
|
}
|
|
|
|
let foo = (bar, baz, qux) => {
|
|
doSomething();
|
|
};
|
|
```
|
|
|
|
## Related Rules
|
|
|
|
* [complexity](complexity.md)
|
|
* [max-depth](max-depth.md)
|
|
* [max-len](max-len.md)
|
|
* [max-lines](max-lines.md)
|
|
* [max-lines-per-function](max-lines-per-function.md)
|
|
* [max-nested-callbacks](max-nested-callbacks.md)
|
|
* [max-statements](max-statements.md)
|