2 * @fileoverview Rule to flag when regex literals are not wrapped in parens
3 * @author Matt DuVall <http://www.mattduvall.com>
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 module.exports = function(context) {
16 "Literal": function(node) {
17 var token = context.getFirstToken(node),
18 nodeType = token.type,
23 if (nodeType === "RegularExpression") {
24 source = context.getTokenBefore(node);
25 ancestors = context.getAncestors();
26 grandparent = ancestors[ancestors.length - 1];
28 if (grandparent.type === "MemberExpression" && grandparent.object === node &&
29 (!source || source.value !== "(")) {
30 context.report(node, "Wrap the regexp literal in parens to disambiguate the slash.");