Repository: eslint/eslint
File: lib/rules/no-unused-vars.js (JavaScript)

Code before:
        //--------------------------------------------------------------------------

        const STATEMENT_TYPE = /(?:Statement|Declaration)$/u;

        /**
         * Determines if a given variable is being exported from a module.
         * @param {Variable} variable eslint-scope variable object.
         * @returns {boolean} True if the variable is exported, false if not.
         * @private
         */
        function isExported(variable) {

            const definition = variable.defs[0];

            if (definition) {

                let node = definition.node;

                if (node.type === "VariableDeclarator") {
                    node = node.parent;
                } else if (definition.type === "Parameter") {
                    return false;
                }

                return node.parent.type.indexOf("Export") === 0;
            }
            return false;

        }

        /**
         * Checks whether a node is a sibling of the rest property or not.
         * @param {ASTNode} node a node to check
         * @returns {boolean} True if the node is a sibling of the rest property, otherwise false.
         */
        function hasRestSibling(node) {
            return node.type === "Property" &&
                node.parent.type === "ObjectPattern" &&
                REST_PROPERTY_TYPE.test(node.parent.properties[node.parent.properties.length - 1].type);
        }

        /**
         * Determines if a variable has a sibling rest property
         * @param {Variable} variable eslint-scope variable object.
         * @returns {boolean} True if the variable is exported, false if not.
         * @private
         */
        function hasRestSpreadSibling(variable) {
            if (config.ignoreRestSiblings) {
                const hasRestSiblingDefinition = variable.defs.some(def => hasRestSibling(def.name.parent));
                const hasRestSiblingReference = variable.references.some(ref => hasRestSibling(ref.identifier.parent));

Review comment (suggestion):
```suggestion
                switch (true) {
                    case defType === "CatchClause" && config.caughtErrorsIgnorePattern:
                        type = "args";
                        pattern = config.caughtErrorsIgnorePattern.toString();
                        break;
                    case defType === "Parameter" && config.argsIgnorePattern:
                        type = "args";
                        pattern = config.argsIgnorePattern.toString();
                        break;
                    case defType !== "Parameter" && config.varsIgnorePattern:
                        type = "vars";
                        pattern = config.varsIgnorePattern.toString();
                    case def.name.parent.type === "ArrayPattern" && config.destructuredArrayIgnorePattern:
                        type = "elements of array destructuring";
                        pattern = config.destructuredArrayIgnorePattern.toString();
                        break;
                }
```

Code after:
            };
        }

        /**
         * Generate the warning message about the variable being
         * assigned and unused, including the ignore pattern if configured.
         * @param {Variable} unusedVar eslint-scope variable object.
         * @returns {UnusedVarMessageData} The message data to be used with this unused variable.
         */
        function getAssignedMessageData(unusedVar) {
            const def = unusedVar.defs && unusedVar.defs[0];
            let additionalMessageData = "";

            if (def) {
                let pattern;
                let variableDescription;

                if (def.name.parent.type === "ArrayPattern" && config.destructuredArrayIgnorePattern) {
                    [variableDescription, pattern] = getVariableDescription("array-destructure");
                } else if (config.varsIgnorePattern) {
                    [variableDescription, pattern] = getVariableDescription("variable");
                }

                if (pattern && variableDescription) {
                    additionalMessageData = `. Allowed unused ${variableDescription} must match ${pattern}`;
                }
            }

            return {
                varName: unusedVar.name,
                action: "assigned a value",
                additional: additionalMessageData
            };
        }

        /**
         * Generate the warning message about a variable being used even though
         * it is marked as being ignored.
         * @param {Variable} variable eslint-scope variable object
         * @param {VariableType} variableType a simple name for the types of variables that this rule supports
         * @returns {UsedIgnoredVarMessageData} The message data to be used with
         * this used ignored variable.
         */
        function getUsedIgnoredMessageData(variable, variableType) {
            const [variableDescription, pattern] = getVariableDescription(variableType);

            let additionalMessageData = "";

            if (pattern && variableDescription) {
                additionalMessageData = `. Used ${variableDescription} must not match ${pattern}`;
            }