Sha256: 74c18fd36234c226e91b0a7c16aad922b755b1e6315b7f9795e4224a41c8a81f

Contents?: true

Size: 1.71 KB

Versions: 62

Compression:

Stored size: 1.71 KB

Contents

/**
 * @fileoverview Reports useless `catch` clauses that just rethrow their error.
 * @author Teddy Katz
 */

"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

/** @type {import('../shared/types').Rule} */
module.exports = {
    meta: {
        type: "suggestion",

        docs: {
            description: "Disallow unnecessary `catch` clauses",
            recommended: true,
            url: "https://eslint.org/docs/latest/rules/no-useless-catch"
        },

        schema: [],

        messages: {
            unnecessaryCatchClause: "Unnecessary catch clause.",
            unnecessaryCatch: "Unnecessary try/catch wrapper."
        }
    },

    create(context) {
        return {
            CatchClause(node) {
                if (
                    node.param &&
                    node.param.type === "Identifier" &&
                    node.body.body.length &&
                    node.body.body[0].type === "ThrowStatement" &&
                    node.body.body[0].argument.type === "Identifier" &&
                    node.body.body[0].argument.name === node.param.name
                ) {
                    if (node.parent.finalizer) {
                        context.report({
                            node,
                            messageId: "unnecessaryCatchClause"
                        });
                    } else {
                        context.report({
                            node: node.parent,
                            messageId: "unnecessaryCatch"
                        });
                    }
                }
            }
        };
    }
};

Version data entries

62 entries across 52 versions & 2 rubygems

Version Path
immosquare-cleaner-0.1.62 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.61 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.60 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.59 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.58 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.57 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.56 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.55 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.54 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.53 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.52 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.51 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.50 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.49 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.48 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.47 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.46 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.45 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.44 node_modules/eslint/lib/rules/no-useless-catch.js
immosquare-cleaner-0.1.43 node_modules/eslint/lib/rules/no-useless-catch.js