no-optional-catch-binding

1.0.0 • Public • Published

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.

Package Sidebar

Install

npm i no-optional-catch-binding

Weekly Downloads

111

Version

1.0.0

License

MIT

Last publish

Collaborators

  • cjihrig