Browse Source

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 <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v6
Rich Trott 8 years ago
committed by James M Snell
parent
commit
a92a5c17eb
  1. 31
      tools/eslint-rules/no-unescaped-regexp-dot.js

31
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'
});
}

Loading…
Cancel
Save