UNPKG

989 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag references to the undefined variable.
3 * @author Michael Ficarra
4 */
5"use strict";
6
7//------------------------------------------------------------------------------
8// Rule Definition
9//------------------------------------------------------------------------------
10
11module.exports = {
12 meta: {
13 docs: {
14 description: "disallow the use of `undefined` as an identifier",
15 category: "Variables",
16 recommended: false
17 },
18
19 schema: []
20 },
21
22 create(context) {
23
24 return {
25
26 Identifier(node) {
27 if (node.name === "undefined") {
28 const parent = context.getAncestors().pop();
29
30 if (!parent || parent.type !== "MemberExpression" || node !== parent.property || parent.computed) {
31 context.report(node, "Unexpected use of undefined.");
32 }
33 }
34 }
35 };
36
37 }
38};