useDefaultParameterLast
诊断类别:lint/style/useDefaultParameterLast
¥Diagnostic Category: lint/style/useDefaultParameterLast
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
default-param-last
¥Same as:
default-param-last
-
与以下相同:
@typescript-eslint/default-param-last
¥Same as:
@typescript-eslint/default-param-last
强制 switch 语句中的默认子句位于最后
¥Enforce default function parameters and optional function parameters to be last.
在调用站点不能省略必需参数之前的默认和可选参数。
¥Default and optional parameters that precede a required parameter cannot be omitted at call site.
¥Examples
¥Invalid
code-block.js:1:12 lint/style/useDefaultParameterLast FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This default parameter should follow the last required parameter or should be a required parameter.
> 1 │ function f(a = 0, b) {}
│ ^^^^^
2 │
ℹ The last required parameter is here:
> 1 │ function f(a = 0, b) {}
│ ^
2 │
ℹ A default parameter that precedes a required parameter cannot be omitted at call site.
ℹ Unsafe fix: Turn the parameter into a required parameter.
1 │ function·f(a·=·0,·b)·{}
│ ----
code-block.js:1:15 lint/style/useDefaultParameterLast FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This default parameter should follow the last required parameter or should be a required parameter.
> 1 │ function f(a, b = 0, c) {}
│ ^^^^^
2 │
ℹ The last required parameter is here:
> 1 │ function f(a, b = 0, c) {}
│ ^
2 │
ℹ A default parameter that precedes a required parameter cannot be omitted at call site.
ℹ Unsafe fix: Turn the parameter into a required parameter.
1 │ function·f(a,·b·=·0,·c)·{}
│ ----
code-block.ts:1:23 lint/style/useDefaultParameterLast FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This optional parameter should follow the last required parameter or should be a required parameter.
> 1 │ function f(a: number, b?: number, c: number) {}
│ ^^^^^^^^^^
2 │
ℹ The last required parameter is here:
> 1 │ function f(a: number, b?: number, c: number) {}
│ ^^^^^^^^^
2 │
ℹ A optional parameter that precedes a required parameter cannot be omitted at call site.
ℹ Unsafe fix: Turn the parameter into a required parameter.
1 │ function·f(a:·number,·b?:·number,·c:·number)·{}
│ -
code-block.ts:2:17 lint/style/useDefaultParameterLast FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This default parameter should follow the last required parameter or should be a required parameter.
1 │ class Foo {
> 2 │ constructor(readonly a = 10, readonly b: number) {}
│ ^^^^^^^^^^^^^^^
3 │ }
4 │
ℹ The last required parameter is here:
1 │ class Foo {
> 2 │ constructor(readonly a = 10, readonly b: number) {}
│ ^^^^^^^^^^^^^^^^^^
3 │ }
4 │
ℹ A default parameter that precedes a required parameter cannot be omitted at call site.
ℹ Unsafe fix: Turn the parameter into a required parameter.
2 │ ····constructor(readonly·a·=·10,·readonly·b:·number)·{}
│ -----
¥Valid
¥Related links