1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | "use strict";
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | module.exports = function(context) {
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | if (typeof(context.options[0]) !== "string") {
|
22 | throw new Error("reject-some-requires expects a regexp");
|
23 | }
|
24 | const RX = new RegExp(context.options[0]);
|
25 |
|
26 | const checkPath = function(node, path) {
|
27 | if (RX.test(path)) {
|
28 | context.report(node, `require(${path}) is not allowed`);
|
29 | }
|
30 | };
|
31 |
|
32 | return {
|
33 | "CallExpression": function(node) {
|
34 | if (node.callee.type == "Identifier" &&
|
35 | node.callee.name == "require" &&
|
36 | node.arguments.length == 1 &&
|
37 | node.arguments[0].type == "Literal") {
|
38 | checkPath(node, node.arguments[0].value);
|
39 | } else if (node.callee.type == "MemberExpression" &&
|
40 | node.callee.property.type == "Identifier" &&
|
41 | node.callee.property.name == "lazyRequireGetter" &&
|
42 | node.arguments.length >= 3 &&
|
43 | node.arguments[2].type == "Literal") {
|
44 | checkPath(node, node.arguments[2].value);
|
45 | }
|
46 | }
|
47 | };
|
48 | };
|