UNPKG

1.37 kBJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag when re-assigning native objects
3 * @author Ilya Volodin
4 */
5
6//------------------------------------------------------------------------------
7// Rule Definition
8//------------------------------------------------------------------------------
9
10module.exports = function(context) {
11
12 "use strict";
13
14 var nativeObjects = ["Array", "Boolean", "Date", "decodeURI",
15 "decodeURIComponent", "encodeURI", "encodeURIComponent",
16 "Error", "eval", "EvalError", "Function", "isFinite",
17 "isNaN", "JSON", "Math", "Number", "Object", "parseInt",
18 "parseFloat", "RangeError", "ReferenceError", "RegExp",
19 "String", "SyntaxError", "TypeError", "URIError",
20 "Map", "NaN", "Set", "WeakMap", "Infinity", "undefined"];
21
22 return {
23
24 "AssignmentExpression": function(node) {
25 if (nativeObjects.indexOf(node.left.name) >= 0) {
26 context.report(node, node.left.name + " is a read-only native object.");
27 }
28 },
29
30 "VariableDeclarator": function(node) {
31 if (nativeObjects.indexOf(node.id.name) >= 0) {
32 context.report(node, "Redefinition of '{{nativeObject}}'.", { nativeObject: node.id.name });
33 }
34 }
35 };
36
37};