Skip to content

Commit

Permalink
test(linter): add regression test for #5227
Browse files Browse the repository at this point in the history
  • Loading branch information
camchenry committed Sep 22, 2024
1 parent 74d8714 commit 8b7a902
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_useless_escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,62 @@ fn test() {
"var foo = /[\\p{ASCII}]/u",
"var foo = /[\\P{ASCII}]/u",
"`${/\\s+/g}`",
// Carets
"/[^^]/u", // { "ecmaVersion": 2015 },
// ES2024
r"/[\q{abc}]/v", // { "ecmaVersion": 2024 },
r"/[\(]/v", // { "ecmaVersion": 2024 },
r"/[\)]/v", // { "ecmaVersion": 2024 },
r"/[\{]/v", // { "ecmaVersion": 2024 },
r"/[\]]/v", // { "ecmaVersion": 2024 },
r"/[\}]/v", // { "ecmaVersion": 2024 },
r"/[\/]/v", // { "ecmaVersion": 2024 },
r"/[\-]/v", // { "ecmaVersion": 2024 },
r"/[\|]/v", // { "ecmaVersion": 2024 },
r"/[\$$]/v", // { "ecmaVersion": 2024 },
r"/[\&&]/v", // { "ecmaVersion": 2024 },
r"/[\!!]/v", // { "ecmaVersion": 2024 },
r"/[\##]/v", // { "ecmaVersion": 2024 },
r"/[\%%]/v", // { "ecmaVersion": 2024 },
r"/[\**]/v", // { "ecmaVersion": 2024 },
r"/[\++]/v", // { "ecmaVersion": 2024 },
r"/[\,,]/v", // { "ecmaVersion": 2024 },
r"/[\..]/v", // { "ecmaVersion": 2024 },
r"/[\::]/v", // { "ecmaVersion": 2024 },
r"/[\;;]/v", // { "ecmaVersion": 2024 },
r"/[\<<]/v", // { "ecmaVersion": 2024 },
r"/[\==]/v", // { "ecmaVersion": 2024 },
r"/[\>>]/v", // { "ecmaVersion": 2024 },
r"/[\??]/v", // { "ecmaVersion": 2024 },
r"/[\@@]/v", // { "ecmaVersion": 2024 },
"/[\\``]/v", // { "ecmaVersion": 2024 },
r"/[\~~]/v", // { "ecmaVersion": 2024 },
r"/[^\^^]/v", // { "ecmaVersion": 2024 },
r"/[_\^^]/v", // { "ecmaVersion": 2024 },
r"/[$\$]/v", // { "ecmaVersion": 2024 },
r"/[&\&]/v", // { "ecmaVersion": 2024 },
r"/[!\!]/v", // { "ecmaVersion": 2024 },
r"/[#\#]/v", // { "ecmaVersion": 2024 },
r"/[%\%]/v", // { "ecmaVersion": 2024 },
r"/[*\*]/v", // { "ecmaVersion": 2024 },
r"/[+\+]/v", // { "ecmaVersion": 2024 },
r"/[,\,]/v", // { "ecmaVersion": 2024 },
r"/[.\.]/v", // { "ecmaVersion": 2024 },
r"/[:\:]/v", // { "ecmaVersion": 2024 },
r"/[;\;]/v", // { "ecmaVersion": 2024 },
r"/[<\<]/v", // { "ecmaVersion": 2024 },
r"/[=\=]/v", // { "ecmaVersion": 2024 },
r"/[>\>]/v", // { "ecmaVersion": 2024 },
r"/[?\?]/v", // { "ecmaVersion": 2024 },
r"/[@\@]/v", // { "ecmaVersion": 2024 },
"/[`\\`]/v", // { "ecmaVersion": 2024 },
r"/[~\~]/v", // { "ecmaVersion": 2024 },
r"/[^^\^]/v", // { "ecmaVersion": 2024 },
r"/[_^\^]/v", // { "ecmaVersion": 2024 },
r"/[\&&&\&]/v", // { "ecmaVersion": 2024 },
r"/[[\-]\-]/v", // { "ecmaVersion": 2024 },
r"/[\^]/v", // { "ecmaVersion": 2024 }
r"/[\s\-(]/", // https://github.com/oxc-project/oxc/issues/5227
];

let fail = vec![
Expand Down Expand Up @@ -452,6 +508,49 @@ fn test() {
("let foo = '\\ ';", "let foo = ' ';", None),
("let foo = /\\ /;", "let foo = / /;", None),
("var foo = `\\$\\{{${foo}`;", "var foo = `$\\{{${foo}`;", None),
(r#""use\ strict";"#, r#""use strict";"#, None),
// spellchecker:off
(r#"({ foo() { "foo"; "bar"; "ba\z" } })"#, r#"({ foo() { "foo"; "bar"; "baz" } })"#, None), // { "ecmaVersion": 6 }
// spellchecker:on
// Carets
(r"/[^\^]/", r"/[^^]/", None),
(r"/[^\^]/u", r"/[^^]/u", None), // { "ecmaVersion": 2015 },
// ES2024
(r"/[\$]/v", r"/[$]/v", None), // { "ecmaVersion": 2024 },
(r"/[\&\&]/v", r"/[&\&]/v", None), // { "ecmaVersion": 2024 },
(r"/[\!\!]/v", r"/[!\!]/v", None), // { "ecmaVersion": 2024 },
(r"/[\#\#]/v", r"/[#\#]/v", None), // { "ecmaVersion": 2024 },
(r"/[\%\%]/v", r"/[%\%]/v", None), // { "ecmaVersion": 2024 },
(r"/[\*\*]/v", r"/[*\*]/v", None), // { "ecmaVersion": 2024 },
(r"/[\+\+]/v", r"/[+\+]/v", None), // { "ecmaVersion": 2024 },
(r"/[\,\,]/v", r"/[,\,]/v", None), // { "ecmaVersion": 2024 },
(r"/[\.\.]/v", r"/[.\.]/v", None), // { "ecmaVersion": 2024 },
(r"/[\:\:]/v", r"/[:\:]/v", None), // { "ecmaVersion": 2024 },
(r"/[\;\;]/v", r"/[;\;]/v", None), // { "ecmaVersion": 2024 },
(r"/[\<\<]/v", r"/[<\<]/v", None), // { "ecmaVersion": 2024 },
(r"/[\=\=]/v", r"/[=\=]/v", None), // { "ecmaVersion": 2024 },
(r"/[\>\>]/v", r"/[>\>]/v", None), // { "ecmaVersion": 2024 },
(r"/[\?\?]/v", r"/[?\?]/v", None), // { "ecmaVersion": 2024 },
(r"/[\@\@]/v", r"/[@\@]/v", None), // { "ecmaVersion": 2024 },
(r"/[\`\`]/v", r"/[`\`]/v", None), // { "ecmaVersion": 2024 },
(r"/[\~\~]/v", r"/[~\~]/v", None), // { "ecmaVersion": 2024 },
(r"/[^\^\^]/v", r"/[^^\^]/v", None), // { "ecmaVersion": 2024 },
(r"/[_\^\^]/v", r"/[_^\^]/v", None), // { "ecmaVersion": 2024 },
(r"/[\&\&&\&]/v", r"/[&\&&\&]/v", None), // { "ecmaVersion": 2024 },
(r"/[\p{ASCII}--\.]/v", r"/[\p{ASCII}--.]/v", None), // { "ecmaVersion": 2024 },
(r"/[\p{ASCII}&&\.]/v", r"/[\p{ASCII}&&.]/v", None), // { "ecmaVersion": 2024 },
(r"/[\.--[.&]]/v", r"/[.--[.&]]/v", None), // { "ecmaVersion": 2024 },
(r"/[\.&&[.&]]/v", r"/[.&&[.&]]/v", None), // { "ecmaVersion": 2024 },
(r"/[\.--\.--\.]/v", r"/[.--.--.]/v", None), // { "ecmaVersion": 2024 },
(r"/[\.&&\.&&\.]/v", r"/[.&&.&&.]/v", None), // { "ecmaVersion": 2024 },
(r"/[[\.&]--[\.&]]/v", r"/[[.&]--[.&]]/v", None), // { "ecmaVersion": 2024 },
(r"/[[\.&]&&[\.&]]/v", r"/[[.&]&&[.&]]/v", None), // { "ecmaVersion": 2024 }
(
// https://github.com/oxc-project/oxc/issues/5227
r"const regex = /(https?:\/\/github\.com\/(([^\s]+)\/([^\s]+))\/([^\s]+\/)?(issues|pull)\/([0-9]+))|(([^\s]+)\/([^\s]+))?#([1-9][0-9]*)($|[\s\:\;\-\(\=])/;",
r"const regex = /(https?:\/\/github\.com\/(([^\s]+)\/([^\s]+))\/([^\s]+\/)?(issues|pull)\/([0-9]+))|(([^\s]+)\/([^\s]+))?#([1-9][0-9]*)($|[\s:;\-(=])/;",
None,
),
];

Tester::new(NoUselessEscape::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
Expand Down

0 comments on commit 8b7a902

Please sign in to comment.