2 * @fileoverview Rule to flag references to the undefined variable.
3 * @author Michael Ficarra
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
16 description: "disallow the use of `undefined` as an identifier",
17 category: "Variables",
19 url: "https://eslint.org/docs/rules/no-undefined"
28 * Report an invalid "undefined" identifier node.
29 * @param {ASTNode} node The node to report.
32 function report(node) {
35 message: "Unexpected use of undefined."
40 * Checks the given scope for references to `undefined` and reports
41 * all references found.
42 * @param {eslint-scope.Scope} scope The scope to check.
45 function checkScope(scope) {
46 const undefinedVar = scope.set.get("undefined");
52 const references = undefinedVar.references;
54 const defs = undefinedVar.defs;
56 // Report non-initializing references (those are covered in defs below)
58 .filter(ref => !ref.init)
59 .forEach(ref => report(ref.identifier));
61 defs.forEach(def => report(def.name));
66 const globalScope = context.getScope();
68 const stack = [globalScope];
70 while (stack.length) {
71 const scope = stack.pop();
73 stack.push(...scope.childScopes);