A parameter with a default value comes before one without

tx0/ts:default-parameter-before-requiredstrictwarningsmell

What it finds

A default value only applies when the argument is left out or undefined. On a parameter followed by a required one, callers cannot leave it out without passing undefined explicitly, so the default rarely does what it seems to promise.

A parameter with a default value is reported when a later parameter has neither a default value nor ?, and is not a rest parameter. Reducers written as (state = initial, action) => ... follow this shape on purpose, which is why this is a strict rule.

From the rule's source, default_parameter_before_required.rs.

Example from the rule's tests
export function greet(greeting = "Hello", name: string) {tx0 reports: only applies when undefined is passed  return greeting + name;}export function fine(name: string, greeting = "Hello", ...rest: string[]) {  return greeting + name + rest.length;}export function optional(a = 1, b?: number) {  return a + (b ?? 0);}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:default-parameter-before-required" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:default-parameter-before-required] reason="..."

tx0 explain tx0/ts:default-parameter-before-required shows the same in the terminal. Found a false positive? Report it.