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

Code before:
                        context.report({
                            node: referenceToReport ? referenceToReport.identifier : unusedVar.identifiers[0],
                            messageId: "unusedVar",
                            data: unusedVar.references.some(ref => ref.isWrite())
                                ? getAssignedMessageData(unusedVar)
                                : getDefinedMessageData(unusedVar)
                        });

                    // If there are no regular declaration, report the first `/*globals*/` comment directive.
                    } else if (unusedVar.eslintExplicitGlobalComments) {
                        const directiveComment = unusedVar.eslintExplicitGlobalComments[0];

                        context.report({
                            node: programNode,
                            loc: astUtils.getNameLocationInGlobalDirectiveComment(sourceCode, directiveComment, unusedVar.name),
                            messageId: "unusedVar",
                            data: getDefinedMessageData(unusedVar)
                        });
                    }
                }

                if (config.reportUsedIgnorePattern) {
                    for (const usedIgnoredVar of usedIgnoredVars) {
                        if (usedIgnoredVar.defs.length > 0) {
                            const references = usedIgnoredVar.references.filter(
                                ref => ref.isRead() && ref.from.variableScope === usedIgnoredVar.scope.variableScope
                            );

                            for (const reference of references) {
                                context.report({
                                    node: reference.identifier,
                                    messageId: "usedIgnoredVar",
                                    data: getUsedIgnoredMessageData(usedIgnoredVar)
                                });
                            }
                        }
                    }
                }
            }
        };
    }
};


Review comment (bug):
Per this condition, `_a` wouldn't be reported at all in the following example, which seems wrong as it's used?

```js
/* eslint no-unused-vars: ["error", {
    varsIgnorePattern: "^_",
    reportUsedIgnorePattern: true
}]*/

var _a = 42;

foo(() => _a);

```

Code after:
                                continue;
                            }
                        } else if (type === "Parameter") {

                            // skip any setter argument
                            if ((def.node.parent.type === "Property" || def.node.parent.type === "MethodDefinition") && def.node.parent.kind === "set") {
                                continue;
                            }

                            // if "args" option is "none", skip any parameter
                            if (config.args === "none") {
                                continue;
                            }

                            // skip ignored parameters
                            if (config.argsIgnorePattern && config.argsIgnorePattern.test(def.name.name)) {
                                if (config.reportUsedIgnorePattern && isUsedVariable(variable)) {
                                    context.report({
                                        node: def.name,
                                        messageId: "usedIgnoredVar",
                                        data: getUsedIgnoredMessageData(variable, "parameter")
                                    });
                                }

                                continue;
                            }

                            // if "args" option is "after-used", skip used variables
                            if (config.args === "after-used" && astUtils.isFunction(def.name.parent) && !isAfterLastUsedArg(variable)) {
                                continue;
                            }
                        } else {

                            // skip ignored variables
                            if (config.varsIgnorePattern && config.varsIgnorePattern.test(def.name.name)) {
                                if (config.reportUsedIgnorePattern && isUsedVariable(variable)) {
                                    context.report({
                                        node: def.name,
                                        messageId: "usedIgnoredVar",
                                        data: getUsedIgnoredMessageData(variable, "variable")
                                    });
                                }

                                continue;
                            }
                        }
                    }

                    if (!isUsedVariable(variable) && !isExported(variable) && !hasRestSpreadSibling(variable)) {
                        unusedVars.push(variable);
                    }