mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 00:47:24 +00:00

PR-URL: https://github.com/iojs/io.js/pull/1539 Fixes: https://github.com/iojs/io.js/issues/1253 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
/**
|
|
* @fileoverview Rule to flag when regex literals are not wrapped in parens
|
|
* @author Matt DuVall <http://www.mattduvall.com>
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
module.exports = function(context) {
|
|
|
|
return {
|
|
|
|
"Literal": function(node) {
|
|
var token = context.getFirstToken(node),
|
|
nodeType = token.type,
|
|
source,
|
|
grandparent,
|
|
ancestors;
|
|
|
|
if (nodeType === "RegularExpression") {
|
|
source = context.getTokenBefore(node);
|
|
ancestors = context.getAncestors();
|
|
grandparent = ancestors[ancestors.length - 1];
|
|
|
|
if (grandparent.type === "MemberExpression" && grandparent.object === node &&
|
|
(!source || source.value !== "(")) {
|
|
context.report(node, "Wrap the regexp literal in parens to disambiguate the slash.");
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
};
|