max-params
Enforce a maximum number of parameters in function definitions
In a call like createUser("Ada", "ada@example.com", "admin", "core"), nothing tells you which argument is which, and nobody notices if you swap two of them. This rule reports any function with more parameters than the maximum, which is 3 by default.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"max-params" = "error" # or "warn"Every option, set to its default. The ones that are commented out are unset by default.
bunfig.toml
[lint.rules]
"max-params" = ["error", {
max = 3,
countThis = "except-void", # "never", "except-void" or "always"
# countVoidThis = false,
# maximum = <number>,
}]Examples#
example.js1 problem
function createUserFunction createUser has too many parameters (4). Maximum allowed is 3.(name, email, role, team) {
return { name, email, role, team };
}example.jsNo problems
function createUser({ name, email, role, team }) {
return { name, email, role, team };
}Options#
bunfig.toml
[lint.rules]
max-params = ["error", 4]| Option | Default | What it does |
|---|---|---|
max | 3 | The number of parameters a function can have. maximum is an older name for it. |
countThis | "except-void" | Whether a TypeScript this parameter counts: "always", "never", or "except-void", which counts it unless it's this: void. |
countVoidThis | false | An older spelling. true is the same as countThis: "always". |
A number alone is short for { "max": number }.
By default a typed this counts. This function has 3 parameters, so a maximum of 2 reports it:
example.tswith
21 problemfunction onClickFunction onClick has too many parameters (3). Maximum allowed is 2.(this: HTMLButtonElement, event: Event, target: Element) {}With countThis: "never" it has 2:
example.tswith
{ "max": 2, "countThis": "never" }No problemsfunction onClick(this: HTMLButtonElement, event: Event, target: Element) {}this: void doesn't count by default, so this passes with a maximum of 2:
example.tswith
2No problemsfunction onClick(this: void, event: Event, target: Element) {}With countThis: "always" it's reported:
example.tswith
{ "max": 2, "countThis": "always" }1 problemfunction onClickFunction onClick has too many parameters (3). Maximum allowed is 2.(this: void, event: Event, target: Element) {}