Rule proposal: prefer-optional-catch-binding
See original GitHub issuePlease describe what the rule should do:
This rule reports and fixes unused catch
bindings.
try {
f()
} catch (err) { // unused!
g()
}
We can modify such code safely to simple:
try {
f()
} catch {
g()
}
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:
//✗ BAD
try {
f()
} catch (err) { // unused!
g()
}
//✓ GOOD
try {
f()
} catch (err) {
g(err)
}
try {
f()
} catch {
g()
}
Why should this rule be included in ESLint (instead of a plugin)?
This rule will encourage to use new syntax in ES2019. It makes more readable to remove unused variables. The autofix is useful.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:7 (6 by maintainers)
Top Results From Across the Web
eslint-plugin-unicorn/prefer-optional-catch-binding.md at main
Prefer omitting the catch binding parameter 💼 This rule is enabled in the ✅ recommended config. 🔧 This rule is automatically fixable by...
Read more >ES2019: optional catch binding - 2ality
The proposal “Optional catch binding” by Michael Ficarra is at stage 4 and therefore part of ECMAScript 2019. This blog post explains how...
Read more >Issuehunt
Rule proposal : prefer-optional-catch-binding #670. fisker posted onGitHub. There is already a proposal in eslint project, but not accepted there, I'd like ...
Read more >@babel/plugin-proposal-optional-catch-binding | Yarn - Yarn
Fast, reliable, and secure dependency management.
Read more >babel/plugin-proposal-optional-catch-binding
Installation. npm install --save-dev @babel/plugin-proposal-optional-catch-binding. Copy. Usage. With a configuration file (Recommended).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d love to see this reopened and revisited.
Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.
Thanks for contributing to ESLint and we appreciate your understanding.