UNPKG

1.16 kBJavaScriptView Raw
1/**
2 * @fileoverview Disallow shadowing of NaN, undefined, and Infinity (ES5 section 15.1.1)
3 * @author Michael Ficarra
4 */
5"use strict";
6
7//------------------------------------------------------------------------------
8// Rule Definition
9//------------------------------------------------------------------------------
10
11module.exports = function(context) {
12
13 var RESTRICTED = ["undefined", "NaN", "Infinity", "arguments", "eval"];
14
15 function checkForViolation(id) {
16 if(RESTRICTED.indexOf(id.name) > -1) {
17 context.report(id, "Shadowing of global property \"" + id.name + "\".");
18 }
19 }
20
21 return {
22 "VariableDeclarator": function(node) {
23 checkForViolation(node.id);
24 },
25 "FunctionExpression": function(node) {
26 if(node.id) { checkForViolation(node.id); }
27 [].map.call(node.params, checkForViolation);
28 },
29 "FunctionDeclaration": function(node) {
30 checkForViolation(node.id);
31 [].map.call(node.params, checkForViolation);
32 },
33 "CatchClause": function(node) {
34 checkForViolation(node.param);
35 }
36 };
37
38};