default-param-last
Enforce default parameters to be last
将默认参数放在最后,允许函数调用省略可选的尾部参数。
// Correct: optional argument can be omitted
function createUser(id, isAdmin = false) {}
createUser("tabby")
// Incorrect: optional argument can **not** be omitted
function createUser(isAdmin = false, id) {}
createUser(undefined, "tabby")
规则细节
这条规则强制规定默认参数为参数的最后一个。
使用此规则的错误示例:
Open in Playground
/* eslint default-param-last: ["error"] */
function f(a = 0, b) {}
function f(a, b = 0, c) {}
使用此规则的正确示例:
Open in Playground
/* eslint default-param-last: ["error"] */
function f(a, b = 0) {}
Version
This rule was introduced in ESLint v6.4.0.