1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 |
|
8 |
|
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 |
|
22 |
|
23 |
|
24 | module.exports = function(context) {
|
25 |
|
26 | return {
|
27 |
|
28 | "CallExpression": function(node) {
|
29 |
|
30 | var result;
|
31 |
|
32 |
|
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 | };
|