summaryrefslogtreecommitdiff
path: root/tools/eslint/lib/rules/no-undefined.js
blob: 7a785b80fb3ff7814427e3fe154d505fd229d5b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
 * @fileoverview Rule to flag references to the undefined variable.
 * @author Michael Ficarra
 */
"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
    meta: {
        docs: {
            description: "disallow the use of `undefined` as an identifier",
            category: "Variables",
            recommended: false
        },

        schema: []
    },

    create: function(context) {

        return {

            Identifier: function(node) {
                if (node.name === "undefined") {
                    const parent = context.getAncestors().pop();

                    if (!parent || parent.type !== "MemberExpression" || node !== parent.property || parent.computed) {
                        context.report(node, "Unexpected use of undefined.");
                    }
                }
            }
        };

    }
};