Proposal: no-optional-catch-binding rule
See original GitHub issuePlease describe what the rule should do:
Prevent use of the new optional catch
binding syntax.
What category of rule is this? (place an “X” next to just one item)
[X] Enforces code style [ ] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
try {
throw new Error('error that should not be ignored');
} catch {
console.log('something happened');
}
Why should this rule be included in ESLint (instead of a plugin)? It seems like it would be applicable across all environments that support the new syntax. Generally, errors should not be ignored. If an error is ignored, I’d prefer an explicit opt eslint-disable opt out, rather than not knowing if it was ignored accidentally or lazily.
I’m volunteering to do the work. I have a proof of concept already.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:13
- Comments:53 (51 by maintainers)
@ljharb Looks reasonable proposition. Yes, “disallow error disposal” rule is nice. However, currently, I think that each core rule is smaller than it. For example, if I want semicolon-less style, I need the following rules:
In the
try-catch
syntax case, I have used the combination ofno-unused-vars
,no-unused-expression
, and some rules in order to disallow error disposal. Then, I want to add therequire-catch-binding
rule to the rule set.The combination of small rules lets me get the goal. Each rule might be too small, but I think it’s another issue that consideration of the proper rule size.
Currently, I’m considering the following rule:
Options:
"always"
… enforce writingcatch
binding."never"
… enforce omittingcatch
binding if it’s unused. This supports autofix.We can develop this after #10392 which adds the support of optional
catch
binding is merged.I will champion this.
no-restricted-syntax
rule withCatchClause[param=null]
can catch this. However, it’s inconvenient if sharable config is using theno-restricted-syntax
rule. It overrides and mess the configuration of shareble configs. Independent rule is useful.