Skip to content

Commit 81613c1

Browse files
MrHensindresorhus
authored andcommitted
catch-error-name - Support optional catch binding (#187)
1 parent 8ca3255 commit 81613c1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

rules/catch-error-name.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ const create = context => {
8585
}
8686
},
8787
CatchClause: node => {
88+
// Optional catch binding
89+
if (!node || !node.param) {
90+
push(true);
91+
return;
92+
}
93+
8894
if (node.param.name === '_') {
8995
push(!astUtils.someContainIdentifier('_', node.body.body));
9096
return;

test/catch-error-name.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,15 @@ ruleTester.run('catch-error-name', rule, {
120120
caughtErrorsIgnorePattern: '^skip'
121121
}
122122
]
123-
}
123+
},
124+
// TODO: Uncomment once test runner supports optional-catch-binding https://github.com/tc39/proposal-optional-catch-binding
125+
// testCase(`
126+
// try {
127+
// throw new Error('message');
128+
// } catch {
129+
// console.log('failed');
130+
// }
131+
// `),
124132
],
125133
invalid: [
126134
testCase('try {} catch (err) {}', null, true),

0 commit comments

Comments
 (0)