Skip to content

Commit

Permalink
chore: Use reliable way of testing if spacing needed
Browse files Browse the repository at this point in the history
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
  • Loading branch information
Yash-Singh1 and mdjermanovic committed Dec 11, 2021
1 parent e292a77 commit d6dcde5
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/rules/prefer-regex-literals.js
Expand Up @@ -152,7 +152,6 @@ module.exports = {
create(context) {
const [{ disallowRedundantWrapping = false } = {}] = context.options;
const sourceCode = context.getSourceCode();
const text = sourceCode.getText();

/**
* Determines whether the given identifier node is a reference to a global variable.
Expand Down Expand Up @@ -380,9 +379,9 @@ module.exports = {

return fixer.replaceText(
node,
(tokenBefore && !canTokensBeAdjacent(tokenBefore, newRegExpValue) && /\S/u.test(text[node.range[0] - 1]) ? " " : "") +
(tokenBefore && !canTokensBeAdjacent(tokenBefore, newRegExpValue) && tokenBefore.range[1] === node.range[0] ? " " : "") +
newRegExpValue +
(tokenAfter && !canTokensBeAdjacent(newRegExpValue, tokenAfter) && /\S/u.test(text[node.range[1]]) ? " " : "")
(tokenAfter && !canTokensBeAdjacent(newRegExpValue, tokenAfter) && node.range[1] === tokenAfter.range[0] ? " " : "")
);
}
}]
Expand Down

0 comments on commit d6dcde5

Please sign in to comment.