You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/catch-error-name.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,11 @@
1
1
# Enforce a specific parameter name in catch clauses
2
2
3
-
Applies to both `try/catch` clauses and `promise.catch(...)` handlers.
3
+
Applies to both `try/catch` clauses and `promise.catch(…)` handlers.
4
4
5
5
The desired name is configurable, but defaults to `error`.
6
6
7
7
This rule is fixable unless the reported code was destructuring an error.
8
8
9
-
10
9
## Fail
11
10
12
11
```js
@@ -21,7 +20,6 @@ try {
21
20
somePromise.catch(e=> {})
22
21
```
23
22
24
-
25
23
## Pass
26
24
27
25
```js
@@ -74,7 +72,6 @@ somePromise.catch(_ => {
74
72
});
75
73
```
76
74
77
-
78
75
## Options
79
76
80
77
### name
@@ -101,7 +98,7 @@ You can set the `name` option like this:
101
98
]
102
99
```
103
100
104
-
This option lets you specify a regex pattern for matches to ignore. The default is `^_$`.
101
+
This option lets you specify a regex pattern for matches to ignore. The default allows `_` and descriptive names like `networkError`.
105
102
106
103
With `^unicorn$`, this would fail:
107
104
@@ -122,3 +119,7 @@ try {
122
119
// …
123
120
}
124
121
```
122
+
123
+
## Tip
124
+
125
+
In order to avoid shadowing in nested catch clauses, the auto-fix rule appends underscores to the identifier name. Since this might be hard to read, the default setting for `caughtErrorsIgnorePattern` allows the use of descriptive names instead, for example, `fsError` or `authError`.
0 commit comments