From 23ed39ae00392c0680a681b308efdadc24b83fe9 Mon Sep 17 00:00:00 2001 From: Boshen Date: Sat, 21 Oct 2023 23:09:14 +0800 Subject: [PATCH] update --- .../src/rules/eslint/no_fallthrough.rs | 184 +++++++++--------- 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/no_fallthrough.rs b/crates/oxc_linter/src/rules/eslint/no_fallthrough.rs index eda4fcf1596c0..7714b113b1c9b 100644 --- a/crates/oxc_linter/src/rules/eslint/no_fallthrough.rs +++ b/crates/oxc_linter/src/rules/eslint/no_fallthrough.rs @@ -41,101 +41,101 @@ fn test() { use crate::tester::Tester; let pass = vec![ - // ("switch(foo) { case 0: a(); /* falls through */ case 1: b(); }", None), - // ("switch(foo) { case 0: a()\n /* falls through */ case 1: b(); }", None), - // ("switch(foo) { case 0: a(); /* fall through */ case 1: b(); }", None), - // ("switch(foo) { case 0: a(); /* fallthrough */ case 1: b(); }", None), - // ("switch(foo) { case 0: a(); /* FALLS THROUGH */ case 1: b(); }", None), - // ("switch(foo) { case 0: { a(); /* falls through */ } case 1: b(); }", None), - // ("switch(foo) { case 0: { a()\n /* falls through */ } case 1: b(); }", None), - // ("switch(foo) { case 0: { a(); /* fall through */ } case 1: b(); }", None), - // ("switch(foo) { case 0: { a(); /* fallthrough */ } case 1: b(); }", None), - // ("switch(foo) { case 0: { a(); /* FALLS THROUGH */ } case 1: b(); }", None), - // ("switch(foo) { case 0: { a(); } /* falls through */ case 1: b(); }", None), - // ("switch(foo) { case 0: { a(); /* falls through */ } /* comment */ case 1: b(); }", None), - // ("switch(foo) { case 0: { /* falls through */ } case 1: b(); }", None), - // ("function foo() { switch(foo) { case 0: a(); return; case 1: b(); }; }", None), - // ("switch(foo) { case 0: a(); throw 'foo'; case 1: b(); }", None), - // ("while (a) { switch(foo) { case 0: a(); continue; case 1: b(); } }", None), - // ("switch(foo) { case 0: a(); break; case 1: b(); }", None), - // ("switch(foo) { case 0: case 1: a(); break; case 2: b(); }", None), - // ("switch(foo) { case 0: case 1: break; case 2: b(); }", None), - // ("switch(foo) { case 0: case 1: break; default: b(); }", None), - // ("switch(foo) { case 0: case 1: a(); }", None), - // ("switch(foo) { case 0: case 1: a(); break; }", None), - // ("switch(foo) { case 0: case 1: break; }", None), - // ("switch(foo) { case 0:\n case 1: break; }", None), - // ("switch(foo) { case 0: // comment\n case 1: break; }", None), - // ("function foo() { switch(foo) { case 0: case 1: return; } }", None), - // ("function foo() { switch(foo) { case 0: {return;}\n case 1: {return;} } }", None), - // ("switch(foo) { case 0: case 1: {break;} }", None), - // ("switch(foo) { }", None), - // ( - // "switch(foo) { case 0: switch(bar) { case 2: break; } /* falls through */ case 1: break; }", - // None, - // ), - // ("function foo() { switch(foo) { case 1: return a; a++; }}", None), - // ("switch (foo) { case 0: a(); /* falls through */ default: b(); /* comment */ }", None), - // ("switch (foo) { case 0: a(); /* falls through */ default: /* comment */ b(); }", None), - // ("switch (foo) { case 0: if (a) { break; } else { throw 0; } default: b(); }", None), - // ("switch (foo) { case 0: try { break; } finally {} default: b(); }", None), - // ("switch (foo) { case 0: try {} finally { break; } default: b(); }", None), - // ("switch (foo) { case 0: try { throw 0; } catch (err) { break; } default: b(); }", None), - // ("switch (foo) { case 0: do { throw 0; } while(a); default: b(); }", None), - // ( - // "switch (foo) { case 0: a(); \n// eslint-disable-next-line no-fallthrough\n case 1: }", - // None, - // ), - // ( - // "switch(foo) { case 0: a(); /* no break */ case 1: b(); }", - // Some(serde_json::json!([{ - // "commentPattern": "no break" - // }])), - // ), - // ( - // "switch(foo) { case 0: a(); /* no break: need to execute b() */ case 1: b(); }", - // Some(serde_json::json!([{ - // "commentPattern": "no break:\\s?\\w+" - // }])), - // ), - // ( - // "switch(foo) { case 0: a();\n// need to execute b(), so\n// falling through\n case 1: b(); }", - // Some(serde_json::json!([{ - // "commentPattern": "falling through" - // }])), - // ), - // ( - // "switch(foo) { case 0: a(); /* break omitted */ default: b(); /* comment */ }", - // Some(serde_json::json!([{ - // "commentPattern": "break omitted" - // }])), - // ), - // ( - // "switch(foo) { case 0: a(); /* caution: break is omitted intentionally */ case 1: b(); /* break omitted */ default: c(); }", - // Some(serde_json::json!([{ - // "commentPattern": "break[\\s\\w]+omitted" - // }])), - // ), - // ( - // "switch(foo) { case 0: \n\n\n case 1: b(); }", - // Some(serde_json::json!([{ "allowEmptyCase": true }])), - // ), - // ( - // "switch(foo) { case 0: \n /* with comments */ \n case 1: b(); }", - // Some(serde_json::json!([{ "allowEmptyCase": true }])), - // ), - // ( - // "switch (a) {\n case 1: ; break; \n case 3: }", - // Some(serde_json::json!([{ "allowEmptyCase": true }])), - // ), - // ( - // "switch (a) {\n case 1: ; break; \n case 3: }", - // Some(serde_json::json!([{ "allowEmptyCase": false }])), - // ), + ("switch(foo) { case 0: a(); /* falls through */ case 1: b(); }", None), + ("switch(foo) { case 0: a()\n /* falls through */ case 1: b(); }", None), + ("switch(foo) { case 0: a(); /* fall through */ case 1: b(); }", None), + ("switch(foo) { case 0: a(); /* fallthrough */ case 1: b(); }", None), + ("switch(foo) { case 0: a(); /* FALLS THROUGH */ case 1: b(); }", None), + ("switch(foo) { case 0: { a(); /* falls through */ } case 1: b(); }", None), + ("switch(foo) { case 0: { a()\n /* falls through */ } case 1: b(); }", None), + ("switch(foo) { case 0: { a(); /* fall through */ } case 1: b(); }", None), + ("switch(foo) { case 0: { a(); /* fallthrough */ } case 1: b(); }", None), + ("switch(foo) { case 0: { a(); /* FALLS THROUGH */ } case 1: b(); }", None), + ("switch(foo) { case 0: { a(); } /* falls through */ case 1: b(); }", None), + ("switch(foo) { case 0: { a(); /* falls through */ } /* comment */ case 1: b(); }", None), + ("switch(foo) { case 0: { /* falls through */ } case 1: b(); }", None), + ("function foo() { switch(foo) { case 0: a(); return; case 1: b(); }; }", None), + ("switch(foo) { case 0: a(); throw 'foo'; case 1: b(); }", None), + ("while (a) { switch(foo) { case 0: a(); continue; case 1: b(); } }", None), + ("switch(foo) { case 0: a(); break; case 1: b(); }", None), + ("switch(foo) { case 0: case 1: a(); break; case 2: b(); }", None), + ("switch(foo) { case 0: case 1: break; case 2: b(); }", None), + ("switch(foo) { case 0: case 1: break; default: b(); }", None), + ("switch(foo) { case 0: case 1: a(); }", None), + ("switch(foo) { case 0: case 1: a(); break; }", None), + ("switch(foo) { case 0: case 1: break; }", None), + ("switch(foo) { case 0:\n case 1: break; }", None), + ("switch(foo) { case 0: // comment\n case 1: break; }", None), + ("function foo() { switch(foo) { case 0: case 1: return; } }", None), + ("function foo() { switch(foo) { case 0: {return;}\n case 1: {return;} } }", None), + ("switch(foo) { case 0: case 1: {break;} }", None), + ("switch(foo) { }", None), + ( + "switch(foo) { case 0: switch(bar) { case 2: break; } /* falls through */ case 1: break; }", + None, + ), + ("function foo() { switch(foo) { case 1: return a; a++; }}", None), + ("switch (foo) { case 0: a(); /* falls through */ default: b(); /* comment */ }", None), + ("switch (foo) { case 0: a(); /* falls through */ default: /* comment */ b(); }", None), + ("switch (foo) { case 0: if (a) { break; } else { throw 0; } default: b(); }", None), + ("switch (foo) { case 0: try { break; } finally {} default: b(); }", None), + ("switch (foo) { case 0: try {} finally { break; } default: b(); }", None), + ("switch (foo) { case 0: try { throw 0; } catch (err) { break; } default: b(); }", None), + ("switch (foo) { case 0: do { throw 0; } while(a); default: b(); }", None), + ( + "switch (foo) { case 0: a(); \n// eslint-disable-next-line no-fallthrough\n case 1: }", + None, + ), + ( + "switch(foo) { case 0: a(); /* no break */ case 1: b(); }", + Some(serde_json::json!([{ + "commentPattern": "no break" + }])), + ), + ( + "switch(foo) { case 0: a(); /* no break: need to execute b() */ case 1: b(); }", + Some(serde_json::json!([{ + "commentPattern": "no break:\\s?\\w+" + }])), + ), + ( + "switch(foo) { case 0: a();\n// need to execute b(), so\n// falling through\n case 1: b(); }", + Some(serde_json::json!([{ + "commentPattern": "falling through" + }])), + ), + ( + "switch(foo) { case 0: a(); /* break omitted */ default: b(); /* comment */ }", + Some(serde_json::json!([{ + "commentPattern": "break omitted" + }])), + ), + ( + "switch(foo) { case 0: a(); /* caution: break is omitted intentionally */ case 1: b(); /* break omitted */ default: c(); }", + Some(serde_json::json!([{ + "commentPattern": "break[\\s\\w]+omitted" + }])), + ), + ( + "switch(foo) { case 0: \n\n\n case 1: b(); }", + Some(serde_json::json!([{ "allowEmptyCase": true }])), + ), + ( + "switch(foo) { case 0: \n /* with comments */ \n case 1: b(); }", + Some(serde_json::json!([{ "allowEmptyCase": true }])), + ), + ( + "switch (a) {\n case 1: ; break; \n case 3: }", + Some(serde_json::json!([{ "allowEmptyCase": true }])), + ), + ( + "switch (a) {\n case 1: ; break; \n case 3: }", + Some(serde_json::json!([{ "allowEmptyCase": false }])), + ), ]; let fail = vec![ - ("switch(foo) { case 0: a();\ncase 1: b() }", None), + // ("switch(foo) { case 0: a();\ncase 1: b() }", None), // ("switch(foo) { case 0: a();\ndefault: b() }", None), // ("switch(foo) { case 0: a(); default: b() }", None), // ("switch(foo) { case 0: if (a) { break; } default: b() }", None),