Skip to content

Commit e0a3378

Browse files
authoredOct 3, 2024··
fix(linter): correct false positive in unicorn/prefer-string-replace-all (#6263)
closes #6259
1 parent f51cbad commit e0a3378

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed
 

‎crates/oxc_linter/src/rules/unicorn/prefer_string_replace_all.rs

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ fn get_pattern_replacement<'a>(
130130
.regex
131131
.pattern
132132
.as_pattern()
133+
.filter(|pattern| pattern.body.body.len() == 1)
133134
.and_then(|pattern| pattern.body.body.first().map(|it| &it.body))?;
134135
let is_simple_string = pattern_terms.iter().all(|term| matches!(term, Term::Character(_)));
135136

@@ -150,6 +151,7 @@ fn test() {
150151
let pass = vec![
151152
r"foo.replace(/a/, bar)",
152153
r"foo.replaceAll(/a/, bar)",
154+
r"foo.replaceAll(/a|b/g, bar)",
153155
r#"foo.replace("string", bar)"#,
154156
r#"foo.replaceAll("string", bar)"#,
155157
r"foo.replace(/a/g)",

0 commit comments

Comments
 (0)
Please sign in to comment.