跳转到内容

useDefaultParameterLast

此内容尚不支持你的语言。

Diagnostic Category: lint/style/useDefaultParameterLast

Since: v1.0.0

Sources:

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.

function f(a = 0, b) {}
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)·{}
----
function f(a, b = 0, c) {}
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)·{}
----
function f(a: number, b?: number, c: number) {}
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)·{}
-
class Foo {
constructor(readonly a = 10, readonly b: 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)·{}
-----
function f(a, b = 0) {}
function f(a: number, b?: number, c = 0) {}
function f(a: number, b = 0, c?: number) {}