From 8b7a902bbc795c21f03279ff4ab22b7696fa9e41 Mon Sep 17 00:00:00 2001 From: Cameron McHenry Date: Sun, 22 Sep 2024 14:55:36 -0400 Subject: [PATCH] test(linter): add regression test for #5227 --- .../src/rules/eslint/no_useless_escape.rs | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs b/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs index afcb56e16c071e..61aec7af6226f6 100644 --- a/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs +++ b/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs @@ -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![ @@ -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();