]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-undefined.js
2 * @fileoverview Rule to flag references to the undefined variable.
3 * @author Michael Ficarra
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 /** @type {import('../shared/types').Rule} */
17 description
: "Disallow the use of `undefined` as an identifier",
19 url
: "https://eslint.org/docs/latest/rules/no-undefined"
25 unexpectedUndefined
: "Unexpected use of undefined."
31 const sourceCode
= context
.sourceCode
;
34 * Report an invalid "undefined" identifier node.
35 * @param {ASTNode} node The node to report.
38 function report(node
) {
41 messageId
: "unexpectedUndefined"
46 * Checks the given scope for references to `undefined` and reports
47 * all references found.
48 * @param {eslint-scope.Scope} scope The scope to check.
51 function checkScope(scope
) {
52 const undefinedVar
= scope
.set.get("undefined");
58 const references
= undefinedVar
.references
;
60 const defs
= undefinedVar
.defs
;
62 // Report non-initializing references (those are covered in defs below)
64 .filter(ref
=> !ref
.init
)
65 .forEach(ref
=> report(ref
.identifier
));
67 defs
.forEach(def
=> report(def
.name
));
71 "Program:exit"(node
) {
72 const globalScope
= sourceCode
.getScope(node
);
74 const stack
= [globalScope
];
76 while (stack
.length
) {
77 const scope
= stack
.pop();
79 stack
.push(...scope
.childScopes
);