AphrodyBun GitHub

Runtime docs · Linter · Rules

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

Reported:

function createUser(name, email, role, team) {
  return { name, email, role, team };
}

Not reported:

function createUser({ name, email, role, team }) {
  return { name, email, role, team };
}

Options

bunfig.toml
[lint.rules]
max-params = ["error", 4]
OptionDefaultWhat it does
max3The 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.
countVoidThisfalseAn 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:

function onClick(this: HTMLButtonElement, event: Event, target: Element) {}

With countThis: "never" it has 2:

function onClick(this: HTMLButtonElement, event: Event, target: Element) {}

this: void doesn't count by default, so this passes with a maximum of 2:

function onClick(this: void, event: Event, target: Element) {}

With countThis: "always" it's reported:

function onClick(this: void, event: Event, target: Element) {}