diff --git a/lib/rules/id-match.js b/lib/rules/id-match.js index dd8dbae55474..a7096e7d9975 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 7afcd4c2e467..ccf7abfdf5b8 100644 --- a/tests/lib/rules/id-match.js +++ b/tests/lib/rules/id-match.js @@ -665,6 +665,8 @@ ruleTester.run("id-match", rule, { let e = (Object) => Object.keys(obj, prop); // not global Object let f = (Array) => Array.from(obj, prop); // not global Array foo.Array = 5; // not global Array + + foo = () => Array; // global Array `, options: ["^\\$?[a-z]+([A-Z0-9][a-z0-9]+)*$", { properties: true