Socket
Socket
Sign inDemoInstall

no-optional-catch-binding

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    no-optional-catch-binding

ESLint rule to flag catch clauses with no error variable binding


Version published
Weekly downloads
115
increased by8.49%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

no-optional-catch-binding

Current Version Build Status via Travis CI Dependencies

disallow optional error variable binding in catch blocks (no-optional-catch-binding)

JavaScript allows error variables to be optionally omitted from catch clauses. For example:

(() => {
    try {
        throw new Error();
        return 1;
    } catch {
        // The caught exception is not used, and has been omitted.
        return 2;
    }
})();

Rule Details

This rule requires that each catch clause includes an error variable binding.

An example of incorrect code for this rule:

/*eslint no-optional-catch-binding: "error"*/
(() => {
    try {
        throw new Error();
        return 1;
    } catch {
        return 2;
    }
})();

An example of correct code for this rule:

/*eslint no-optional-catch-binding: "error"*/
(() => {
    try {
        throw new Error();
        return 1;
    } catch (err) {
        return 2;
    }
})();

When Not To Use It

If you want to allow optional catch binding, you can turn this rule off.

Keywords

FAQs

Last updated on 29 Jan 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc