1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | module.exports = function(context) {
|
11 |
|
12 | "use strict";
|
13 |
|
14 | return {
|
15 |
|
16 | "Literal": function(node) {
|
17 | var token = context.getTokens(node)[0],
|
18 | nodeType = token.type,
|
19 | source,
|
20 | grandparent,
|
21 | ancestors;
|
22 |
|
23 | if (nodeType === "RegularExpression") {
|
24 | source = context.getTokens(node, 1, 1)[0].value;
|
25 | ancestors = context.getAncestors();
|
26 | grandparent = ancestors[ancestors.length - 1];
|
27 |
|
28 | if (grandparent.type === "MemberExpression" &&
|
29 | source[0] !== "(" && source[source.len - 1] !== ")") {
|
30 | context.report(node, "Wrap the /regexp/ literal in parens to disambiguate the slash operator.");
|
31 | }
|
32 | }
|
33 | }
|
34 | };
|
35 |
|
36 | };
|