29ff4a3836b2b4e181b2e90da0c2e4f542c666c2
[platform/framework/web/crosswalk-tizen.git] /
1 /**
2  * @fileoverview Rule to flag when re-assigning native objects
3  * @author Ilya Volodin
4  */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Rule Definition
10 //------------------------------------------------------------------------------
11
12 module.exports = function(context) {
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 };