]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-undefined.js
ad302255420acbb5124332197087b1826f2dd47f
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",
18 url
: "https://eslint.org/docs/rules/no-undefined"
24 unexpectedUndefined
: "Unexpected use of undefined."
31 * Report an invalid "undefined" identifier node.
32 * @param {ASTNode} node The node to report.
35 function report(node
) {
38 messageId
: "unexpectedUndefined"
43 * Checks the given scope for references to `undefined` and reports
44 * all references found.
45 * @param {eslint-scope.Scope} scope The scope to check.
48 function checkScope(scope
) {
49 const undefinedVar
= scope
.set.get("undefined");
55 const references
= undefinedVar
.references
;
57 const defs
= undefinedVar
.defs
;
59 // Report non-initializing references (those are covered in defs below)
61 .filter(ref
=> !ref
.init
)
62 .forEach(ref
=> report(ref
.identifier
));
64 defs
.forEach(def
=> report(def
.name
));
69 const globalScope
= context
.getScope();
71 const stack
= [globalScope
];
73 while (stack
.length
) {
74 const scope
= stack
.pop();
76 stack
.push(...scope
.childScopes
);