diff options
Diffstat (limited to 'tools/eslint/lib/rules/no-invalid-regexp.js')
-rw-r--r-- | tools/eslint/lib/rules/no-invalid-regexp.js | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/tools/eslint/lib/rules/no-invalid-regexp.js b/tools/eslint/lib/rules/no-invalid-regexp.js index 63608c6c47..d46f9cb072 100644 --- a/tools/eslint/lib/rules/no-invalid-regexp.js +++ b/tools/eslint/lib/rules/no-invalid-regexp.js @@ -17,17 +17,29 @@ var espree = require("espree"); module.exports = function(context) { + /** + * Check if node is a string + * @param {ASTNode} node node to evaluate + * @returns {boolean} True if its a string + * @private + */ function isString(node) { return node && node.type === "Literal" && typeof node.value === "string"; } + /** + * Validate strings passed to the RegExp constructor + * @param {ASTNode} node node to evaluate + * @returns {void} + * @private + */ function check(node) { if (node.callee.type === "Identifier" && node.callee.name === "RegExp" && isString(node.arguments[0])) { var flags = isString(node.arguments[1]) ? node.arguments[1].value : ""; try { void new RegExp(node.arguments[0].value); - } catch(e) { + } catch (e) { context.report(node, e.message); } |