1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | module.exports = function(context) {
|
12 |
|
13 | function isString(node) {
|
14 | return node && node.type === "Literal" && typeof node.value === "string";
|
15 | }
|
16 |
|
17 | function check(node) {
|
18 | if(node.callee.type === "Identifier" && node.callee.name === "RegExp" && isString(node.arguments[0])) {
|
19 | try {
|
20 | if(isString(node.arguments[1])) {
|
21 | void new RegExp(node.arguments[0].value, node.arguments[1].value);
|
22 | } else {
|
23 | void new RegExp(node.arguments[0].value);
|
24 | }
|
25 | } catch(e) {
|
26 | context.report(node, e.message);
|
27 | }
|
28 | }
|
29 | }
|
30 |
|
31 | return {
|
32 | "CallExpression": check,
|
33 | "NewExpression": check
|
34 | };
|
35 |
|
36 | };
|