Skip to content

eslint/default-param-last Style

What it does

Requires default parameters in functions to be the last ones.

Why is this bad?

Placing default parameters last allows function calls to omit optional trailing arguments, which improves readability and consistency. This rule applies equally to JavaScript and TypeScript functions.

Options

No options available for this rule

Examples

Examples of incorrect code for this rule:

js
/* default-param-last: "error" */

function f(a = 0, b) {}
function f(a, b = 0, c) {}
function createUser(isAdmin = false, id) {}
createUser(undefined, "tabby");

Examples of correct code for this rule:

js
/* default-param-last: "error" */

function f(a, b = 0) {}
function f(a = 0, b = 0) {}
function createUser(id, isAdmin = false) {}
createUser("tabby");

Examples of incorrect TypeScript code for this rule:

ts
/* default-param-last: "error" */

function greet(message: string = "Hello", name: string) {}
function combine(a: number = 1, b: number, c: number) {}
function combine(a: number, b: number = 2, c: number) {}
function combine(a: number = 1, b?: number, c: number) {}

Examples of correct TypeScript code for this rule:

ts
/* default-param-last: "error" */

function greet(name: string, message: string = "Hello") {}
function combine(a: number, b: number = 2, c: number = 3) {}
function combine(a: number, b?: number, c: number = 3) {}

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny default-param-last
json
{
  "rules": {
    "default-param-last": "error"
  }
}

References

Released under the MIT License.