UNPKG

1.55 kBMarkdownView Raw
1# `default-param-last`
2
3Enforce default parameters to be last.
4
5## Rule Details
6
7This rule extends the base [`eslint/default-param-last`](https://eslint.org/docs/rules/default-param-last) rule.
8It adds support for optional parameters.
9
10<!--tabs-->
11
12### ❌ Incorrect
13
14```ts
15/* eslint @typescript-eslint/default-param-last: ["error"] */
16
17function f(a = 0, b: number) {}
18function f(a: number, b = 0, c: number) {}
19function f(a: number, b?: number, c: number) {}
20class Foo {
21 constructor(public a = 10, private b: number) {}
22}
23class Foo {
24 constructor(public a?: number, private b: number) {}
25}
26```
27
28### ✅ Correct
29
30```ts
31/* eslint @typescript-eslint/default-param-last: ["error"] */
32
33function f(a = 0) {}
34function f(a: number, b = 0) {}
35function f(a: number, b?: number) {}
36function f(a: number, b?: number, c = 0) {}
37function f(a: number, b = 0, c?: number) {}
38class Foo {
39 constructor(public a, private b = 0) {}
40}
41class Foo {
42 constructor(public a, private b?: number) {}
43}
44```
45
46## How to Use
47
48```jsonc
49{
50 // note you must disable the base rule as it can report incorrect errors
51 "default-param-last": "off",
52 "@typescript-eslint/default-param-last": ["error"]
53}
54```
55
56## Options
57
58See [`eslint/default-param-last` options](https://eslint.org/docs/rules/default-param-last#options).
59
60<sup>
61
62Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/default-param-last.md)
63
64</sup>
65
66## Attributes
67
68- Configs:
69 - [ ] ✅ Recommended
70 - [ ] 🔒 Strict
71- [ ] 🔧 Fixable
72- [ ] 💭 Requires type information