From 767644def520cd908c0d80c1cbc8643b46c9a11f Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 31 Jul 2017 20:20:08 -0700 Subject: [PATCH] tools: simplify no-unescaped-regexp-dot rule no-unescaped-regexp-dot ESLint custom rule contains feature detection that is not needed on master or the v6.x-staging branch. The rule does not exist in the v4.x-staging branch. Remove the unnecessary complexity. PR-URL: https://github.com/nodejs/node/pull/14561 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- tools/eslint-rules/no-unescaped-regexp-dot.js | 31 ++----------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/tools/eslint-rules/no-unescaped-regexp-dot.js b/tools/eslint-rules/no-unescaped-regexp-dot.js index cf542a3d7021ff..d0c575071297fb 100644 --- a/tools/eslint-rules/no-unescaped-regexp-dot.js +++ b/tools/eslint-rules/no-unescaped-regexp-dot.js @@ -4,12 +4,6 @@ */ 'use strict'; -const path = require('path'); -const utilsPath = path.join(__dirname, '..', 'eslint', 'lib', 'ast-utils.js'); -const astUtils = require(utilsPath); -const getLocationFromRangeIndex = astUtils.getLocationFromRangeIndex; -const getRangeIndexFromLocation = astUtils.getRangeIndexFromLocation; - //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ @@ -20,32 +14,11 @@ module.exports = function(context) { var regexpBuffer = []; var inRegExp = false; - var getLocFromIndex; - if (typeof sourceCode.getLocFromIndex === 'function') { - getLocFromIndex = function(index) { - return sourceCode.getLocFromIndex(index); - }; - } else { - getLocFromIndex = function(index) { - return getLocationFromRangeIndex(sourceCode, index); - }; - } - - var getIndexFromLoc; - if (typeof sourceCode.getIndexFromLoc === 'function') { - getIndexFromLoc = function(loc) { - return sourceCode.getIndexFromLoc(loc); - }; - } else { - getIndexFromLoc = function(loc) { - return getRangeIndexFromLocation(sourceCode, loc); - }; - } - function report(node, startOffset) { + const indexOfDot = sourceCode.getIndexFromLoc(node.loc.start) + startOffset; context.report({ node, - loc: getLocFromIndex(getIndexFromLoc(node.loc.start) + startOffset), + loc: sourceCode.getLocFromIndex(indexOfDot), message: 'Unescaped dot character in regular expression' }); }