question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: prefer-optional-catch-binding

See original GitHub issue

Please 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:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
ljharbcommented, Dec 11, 2018

I’d love to see this reopened and revisited.

0reactions
eslint-deprecated[bot]commented, Dec 11, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found