useDefaultParameterLast
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/style/useDefaultParameterLast
Since: v1.0.0
Sources:
- Same as:
default-param-last
- Same as:
@typescript-eslint/default-param-last
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
Section titled ExamplesInvalid
Section titled Invalidcode-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)·{}
│ -----