Sha256: 1ed8f8e16cd31973d57ceba83be09b2e6740db7d13088205bb14d59ea408f9df
Contents?: true
Size: 1.85 KB
Versions: 45
Compression:
Stored size: 1.85 KB
Contents
/** * @fileoverview Disallow shadowing of NaN, undefined, and Infinity (ES5 section 15.1.1) * @author Michael Ficarra */ "use strict"; //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ module.exports = { meta: { docs: { description: "disallow identifiers from shadowing restricted names", category: "Variables", recommended: false }, schema: [] }, create: 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); } }; } };
Version data entries
45 entries across 45 versions & 2 rubygems