default-param-last
强制默认参数位于最后。
此规则扩展了基本规则 eslint/default-param-last
。它添加了对可选参数的支持。
- ❌ 错误
- ✅ 正确
function f(a = 0, b: number) {}
function f(a: number, b = 0, c: number) {}
function f(a: number, b?: number, c: number) {}
class Foo {
constructor(
public a = 10,
private b: number,
) {}
}
class Foo {
constructor(
public a?: number,
private b: number,
) {}
}
在游乐场中打开function f(a = 0) {}
function f(a: number, b = 0) {}
function f(a: number, b?: number) {}
function f(a: number, b?: number, c = 0) {}
function f(a: number, b = 0, c?: number) {}
class Foo {
constructor(
public a,
private b = 0,
) {}
}
class Foo {
constructor(
public a,
private b?: number,
) {}
}
在游乐场中打开选项
查看 eslint/default-param-last
选项.
如何使用
.eslintrc.cjs
module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"default-param-last": "off",
"@typescript-eslint/default-param-last": "error"
}
};
在游乐场中尝试此规则 ↗