1f14b533d71a13aa521ed5b2e238de774a7cd690
[platform/framework/web/crosswalk-tizen.git] /
1 /**
2  * @fileoverview Rule to flag use of alert, confirm, prompt
3  * @author Nicholas C. Zakas
4  */
5 "use strict";
6
7 //------------------------------------------------------------------------------
8 // Helpers
9 //------------------------------------------------------------------------------
10
11 function matchProhibited(name) {
12     return name.match(/^(alert|confirm|prompt)$/);
13 }
14
15 function report(context, node, result) {
16     context.report(node, "Unexpected {{name}}.", { name: result[1] });
17 }
18
19
20 //------------------------------------------------------------------------------
21 // Rule Definition
22 //------------------------------------------------------------------------------
23
24 module.exports = function(context) {
25
26     return {
27
28         "CallExpression": function(node) {
29
30             var result;
31
32             // without window.
33             if (node.callee.type === "Identifier") {
34
35                 result = matchProhibited(node.callee.name);
36
37                 if (result) {
38                     report(context, node, result);
39                 }
40
41             } else if (node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier") {
42
43                 result = matchProhibited(node.callee.property.name);
44
45                 if (result && node.callee.object.name === "window") {
46                     report(context, node, result);
47                 }
48
49             }
50
51         }
52     };
53
54 };