diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_regexp_test.rs b/crates/oxc_linter/src/rules/unicorn/prefer_regexp_test.rs index 1b88d20e7..220ef4fdf 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_regexp_test.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_regexp_test.rs @@ -202,7 +202,7 @@ fn test() { r"const re = /a/; if (foo.match(re)) {}", r"const bar = {bar: /a/}; if (foo.match(bar.baz)) {}", r"if (foo.match(bar.baz())) {}", - r#"if (foo.match(new RegExp(\"re\", \"g\"))) {}"#, + r#"if (foo.match(new RegExp("re", "g"))) {}"#, r"if (foo.match(new SomeRegExp())) {}", r"if (foo.match(new SomeRegExp)) {}", r"if (foo.match(bar?.baz)) {}", @@ -219,13 +219,13 @@ fn test() { r"if (foo.match(/a/y));", r"if (foo.match(/a/gy));", r"if (foo.match(/a/ig));", - r#"if (foo.match(new RegExp(\"a\", \"g\")));"#, + r#"if (foo.match(new RegExp("a", "g")));"#, r"if (/a/g.exec(foo));", r"if (/a/y.exec(foo));", r"if (/a/gy.exec(foo));", r"if (/a/yi.exec(foo));", - r#"if (new RegExp(\"a\", \"g\").exec(foo));"#, - r#"if (new RegExp(\"a\", \"y\").exec(foo));"#, + r#"if (new RegExp("a", "g").exec(foo));"#, + r#"if (new RegExp("a", "y").exec(foo));"#, r"!/a/u.exec(foo)", r"!/a/v.exec(foo)", ]; diff --git a/crates/oxc_linter/src/snapshots/prefer_regexp_test.snap b/crates/oxc_linter/src/snapshots/prefer_regexp_test.snap index b3cd8b261..4533fd00c 100644 --- a/crates/oxc_linter/src/snapshots/prefer_regexp_test.snap +++ b/crates/oxc_linter/src/snapshots/prefer_regexp_test.snap @@ -156,29 +156,12 @@ expression: prefer_regexp_test ╰──── help: RegExp#test() exclusively returns a boolean and therefore is more efficient - × Invalid Unicode escape sequence + ⚠ eslint-plugin-unicorn(prefer-regexp-test): Prefer RegExp#test() over String#match() and RegExp#exec() ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (foo.match(new RegExp(\"re\", \"g\"))) {} - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (foo.match(new RegExp(\"re\", \"g\"))) {} - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (foo.match(new RegExp(\"re\", \"g\"))) {} - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (foo.match(new RegExp(\"re\", \"g\"))) {} - · ─ + 1 │ if (foo.match(new RegExp("re", "g"))) {} + · ───── ╰──── + help: RegExp#test() exclusively returns a boolean and therefore is more efficient ⚠ eslint-plugin-unicorn(prefer-regexp-test): Prefer RegExp#test() over String#match() and RegExp#exec() ╭─[prefer_regexp_test.tsx:1:1] @@ -292,29 +275,12 @@ expression: prefer_regexp_test ╰──── help: RegExp#test() exclusively returns a boolean and therefore is more efficient - × Invalid Unicode escape sequence + ⚠ eslint-plugin-unicorn(prefer-regexp-test): Prefer RegExp#test() over String#match() and RegExp#exec() ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (foo.match(new RegExp(\"a\", \"g\"))); - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (foo.match(new RegExp(\"a\", \"g\"))); - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (foo.match(new RegExp(\"a\", \"g\"))); - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (foo.match(new RegExp(\"a\", \"g\"))); - · ─ + 1 │ if (foo.match(new RegExp("a", "g"))); + · ───── ╰──── + help: RegExp#test() exclusively returns a boolean and therefore is more efficient ⚠ eslint-plugin-unicorn(prefer-regexp-test): Prefer RegExp#test() over String#match() and RegExp#exec() ╭─[prefer_regexp_test.tsx:1:1] @@ -344,53 +310,19 @@ expression: prefer_regexp_test ╰──── help: RegExp#test() exclusively returns a boolean and therefore is more efficient - × Invalid Unicode escape sequence + ⚠ eslint-plugin-unicorn(prefer-regexp-test): Prefer RegExp#test() over String#match() and RegExp#exec() ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (new RegExp(\"a\", \"g\").exec(foo)); - · ─ + 1 │ if (new RegExp("a", "g").exec(foo)); + · ──── ╰──── + help: RegExp#test() exclusively returns a boolean and therefore is more efficient - × Invalid Unicode escape sequence + ⚠ eslint-plugin-unicorn(prefer-regexp-test): Prefer RegExp#test() over String#match() and RegExp#exec() ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (new RegExp(\"a\", \"g\").exec(foo)); - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (new RegExp(\"a\", \"g\").exec(foo)); - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (new RegExp(\"a\", \"g\").exec(foo)); - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (new RegExp(\"a\", \"y\").exec(foo)); - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (new RegExp(\"a\", \"y\").exec(foo)); - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (new RegExp(\"a\", \"y\").exec(foo)); - · ─ - ╰──── - - × Invalid Unicode escape sequence - ╭─[prefer_regexp_test.tsx:1:1] - 1 │ if (new RegExp(\"a\", \"y\").exec(foo)); - · ─ + 1 │ if (new RegExp("a", "y").exec(foo)); + · ──── ╰──── + help: RegExp#test() exclusively returns a boolean and therefore is more efficient ⚠ eslint-plugin-unicorn(prefer-regexp-test): Prefer RegExp#test() over String#match() and RegExp#exec() ╭─[prefer_regexp_test.tsx:1:1]