Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
prefer-string-replace-all: Ignore regex with pipe (#1962)
  • Loading branch information
hampuskraft committed Nov 14, 2022
1 parent 505a203 commit 76deaa3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rules/prefer-string-replace-all.js
Expand Up @@ -19,7 +19,7 @@ const isRegexWithGlobalFlag = node =>

function isLiteralCharactersOnly(node) {
const searchPattern = node.regex.pattern;
return !/[$()*+.?[\\\]^{}]/.test(searchPattern.replace(/\\[$()*+.?[\\\]^{}]/g, ''));
return !/[$()*+.?[\\\]^{|}]/.test(searchPattern.replace(/\\[$()*+.?[\\\]^{|}]/g, ''));
}

function removeEscapeCharacters(regexString) {
Expand Down
6 changes: 6 additions & 0 deletions test/prefer-string-replace-all.mjs
Expand Up @@ -14,6 +14,7 @@ test({
'foo.replace(/[a]/g, bar)',
'foo.replace(/a?/g, bar)',
'foo.replace(/.*/g, bar)',
'foo.replace(/a|b/g, bar)',
'foo.replace(/\\W/g, bar)',
'foo.replace(/\\u{61}/g, bar)',
'foo.replace(/\\u{61}/gu, bar)',
Expand Down Expand Up @@ -86,6 +87,11 @@ test({
output: 'foo.replaceAll(\'\\\\.\', bar)',
errors: [error],
},
{
code: 'foo.replace(/\\|/g, bar)',
output: 'foo.replaceAll(\'|\', bar)',
errors: [error],
},
],
});

Expand Down

0 comments on commit 76deaa3

Please sign in to comment.