node/tools/eslint/lib/rules/no-shadow-restricted-names.js
Roman Reiss d91e10b3bd tools: update eslint to 0.24.0
PR-URL: https://github.com/nodejs/io.js/pull/2072
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-by: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alex Kocharin <alex@kocharin.ru>
2015-06-29 19:02:17 +02:00

51 lines
1.5 KiB
JavaScript

/**
* @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"];
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) {
if (node.id) {
checkForViolation(node.id);
}
[].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 = [];