Skip to content

Commit a92a5c1

Browse files
Trottjasnell
authored andcommitted
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: #14561 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent fb3d0e2 commit a92a5c1

File tree

1 file changed

+2
-29
lines changed

1 file changed

+2
-29
lines changed

tools/eslint-rules/no-unescaped-regexp-dot.js

+2-29
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
*/
55
'use strict';
66

7-
const path = require('path');
8-
const utilsPath = path.join(__dirname, '..', 'eslint', 'lib', 'ast-utils.js');
9-
const astUtils = require(utilsPath);
10-
const getLocationFromRangeIndex = astUtils.getLocationFromRangeIndex;
11-
const getRangeIndexFromLocation = astUtils.getRangeIndexFromLocation;
12-
137
//------------------------------------------------------------------------------
148
// Rule Definition
159
//------------------------------------------------------------------------------
@@ -20,32 +14,11 @@ module.exports = function(context) {
2014
var regexpBuffer = [];
2115
var inRegExp = false;
2216

23-
var getLocFromIndex;
24-
if (typeof sourceCode.getLocFromIndex === 'function') {
25-
getLocFromIndex = function(index) {
26-
return sourceCode.getLocFromIndex(index);
27-
};
28-
} else {
29-
getLocFromIndex = function(index) {
30-
return getLocationFromRangeIndex(sourceCode, index);
31-
};
32-
}
33-
34-
var getIndexFromLoc;
35-
if (typeof sourceCode.getIndexFromLoc === 'function') {
36-
getIndexFromLoc = function(loc) {
37-
return sourceCode.getIndexFromLoc(loc);
38-
};
39-
} else {
40-
getIndexFromLoc = function(loc) {
41-
return getRangeIndexFromLocation(sourceCode, loc);
42-
};
43-
}
44-
4517
function report(node, startOffset) {
18+
const indexOfDot = sourceCode.getIndexFromLoc(node.loc.start) + startOffset;
4619
context.report({
4720
node,
48-
loc: getLocFromIndex(getIndexFromLoc(node.loc.start) + startOffset),
21+
loc: sourceCode.getLocFromIndex(indexOfDot),
4922
message: 'Unescaped dot character in regular expression'
5023
});
5124
}

0 commit comments

Comments
 (0)