diff --git a/lib/rules/id-match.js b/lib/rules/id-match.js index dd8dbae5547..a7096e7d997 100644 --- a/lib/rules/id-match.js +++ b/lib/rules/id-match.js @@ -67,6 +67,8 @@ module.exports = { onlyDeclarations = !!options.onlyDeclarations, ignoreDestructuring = !!options.ignoreDestructuring; + const globalScope = context.getScope(); + //-------------------------------------------------------------------------- // Helpers //-------------------------------------------------------------------------- @@ -84,15 +86,14 @@ module.exports = { * @returns {boolean} `true` if the node is a reference to a global variable. */ function isReferenceToGlobalVariable(node) { - const scope = context.getScope(); - const variable = scope.set.get(node.name); + const variable = globalScope.set.get(node.name); return variable && variable.defs.length === 0 && variable.references.some(ref => ref.identifier === node); } /** - * Checks if a string matches the provided pattern and is not a global reference + * Checks if a string matches the provided pattern * @param {string} name The string to check. * @returns {boolean} if the string is a match * @private @@ -267,10 +268,6 @@ module.exports = { const isClassField = node.parent.type === "PropertyDefinition"; - if (isReferenceToGlobalVariable(node)) { - return; - } - if (isClassField && !checkClassFields) { return; } diff --git a/tests/lib/rules/id-match.js b/tests/lib/rules/id-match.js index 7afcd4c2e46..2f48a4b2d2c 100644 --- a/tests/lib/rules/id-match.js +++ b/tests/lib/rules/id-match.js @@ -188,12 +188,14 @@ ruleTester.run("id-match", rule, { // Should not report for global references - https://github.com/eslint/eslint/issues/15395 { code: ` - var foo = Object.keys(bar); - var a = Array.from(b); + const foo = Object.keys(bar); + const a = Array.from(b); + const bar = () => Array; `, options: ["^\\$?[a-z]+([A-Z0-9][a-z0-9]+)*$", { properties: true - }] + }], + parserOptions: { ecmaVersion: 2022 } }, // Class Methods