Skip to content

Commit

Permalink
tools: simplify no-unescaped-regexp-dot rule
Browse files Browse the repository at this point in the history
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: #14561
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Trott authored and addaleax committed Aug 7, 2017
1 parent 255b9bf commit 767644d
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions tools/eslint-rules/no-unescaped-regexp-dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
//------------------------------------------------------------------------------
Expand All @@ -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'
});
}
Expand Down

0 comments on commit 767644d

Please sign in to comment.