# 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.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml 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.

```toml bunfig.toml
[lint.rules]
"max-params" = ["error", {
  max = 3,
  countThis = "except-void", # "never", "except-void" or "always"
  # countVoidThis = false,
  # maximum = <number>,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
function createUser(name, email, role, team) {
  return { name, email, role, team };
}
```

Not reported:

{/* good */}
```js
function createUser({ name, email, role, team }) {
  return { name, email, role, team };
}
```

## Options

```toml 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:

{/* bad {"options": [2]} */}
```ts
function onClick(this: HTMLButtonElement, event: Event, target: Element) {}
```

With `countThis: "never"` it has 2:

{/* good {"options": [{"max": 2, "countThis": "never"}]} */}
```ts
function onClick(this: HTMLButtonElement, event: Event, target: Element) {}
```

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

{/* good {"options": [2]} */}
```ts
function onClick(this: void, event: Event, target: Element) {}
```

With `countThis: "always"` it's reported:

{/* bad {"options": [{"max": 2, "countThis": "always"}]} */}
```ts
function onClick(this: void, event: Event, target: Element) {}
```
