mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 04:51:50 +00:00

PR-URL: https://github.com/iojs/io.js/pull/1539 Fixes: https://github.com/iojs/io.js/issues/1253 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
/**
|
|
* @fileoverview Rule to flag when re-assigning native objects
|
|
* @author Ilya Volodin
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
module.exports = function(context) {
|
|
|
|
var nativeObjects = ["Array", "Boolean", "Date", "decodeURI",
|
|
"decodeURIComponent", "encodeURI", "encodeURIComponent",
|
|
"Error", "eval", "EvalError", "Function", "isFinite",
|
|
"isNaN", "JSON", "Math", "Number", "Object", "parseInt",
|
|
"parseFloat", "RangeError", "ReferenceError", "RegExp",
|
|
"String", "SyntaxError", "TypeError", "URIError",
|
|
"Map", "NaN", "Set", "WeakMap", "Infinity", "undefined"];
|
|
|
|
return {
|
|
|
|
"AssignmentExpression": function(node) {
|
|
if (nativeObjects.indexOf(node.left.name) >= 0) {
|
|
context.report(node, node.left.name + " is a read-only native object.");
|
|
}
|
|
},
|
|
|
|
"VariableDeclarator": function(node) {
|
|
if (nativeObjects.indexOf(node.id.name) >= 0) {
|
|
context.report(node, "Redefinition of '{{nativeObject}}'.", { nativeObject: node.id.name });
|
|
}
|
|
}
|
|
};
|
|
|
|
};
|