mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
54 lines
1.6 KiB
/**
|
|
* @fileoverview Disallow shadowing of NaN, undefined, and Infinity (ES5 section 15.1.1)
|
|
* @author Michael Ficarra
|
|
* @copyright 2013 Michael Ficarra. All rights reserved.
|
|
*/
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
module.exports = function(context) {
|
|
|
|
var RESTRICTED = ["undefined", "NaN", "Infinity", "arguments", "eval"];
|
|
|
|
/**
|
|
* Check if the node name is present inside the restricted list
|
|
* @param {ASTNode} id id to evaluate
|
|
* @returns {void}
|
|
* @private
|
|
*/
|
|
function checkForViolation(id) {
|
|
if (RESTRICTED.indexOf(id.name) > -1) {
|
|
context.report(id, "Shadowing of global property '" + id.name + "'.");
|
|
}
|
|
}
|
|
|
|
return {
|
|
"VariableDeclarator": function(node) {
|
|
checkForViolation(node.id);
|
|
},
|
|
"ArrowFunctionExpression": function(node) {
|
|
[].map.call(node.params, checkForViolation);
|
|
},
|
|
"FunctionExpression": function(node) {
|
|
if (node.id) {
|
|
checkForViolation(node.id);
|
|
}
|
|
[].map.call(node.params, checkForViolation);
|
|
},
|
|
"FunctionDeclaration": function(node) {
|
|
if (node.id) {
|
|
checkForViolation(node.id);
|
|
[].map.call(node.params, checkForViolation);
|
|
}
|
|
},
|
|
"CatchClause": function(node) {
|
|
checkForViolation(node.param);
|
|
}
|
|
};
|
|
|
|
};
|
|
|
|
module.exports.schema = [];
|
|
|