Skip to content

Commit 1fcf56c

Browse files
committed
test(linter/no-fallthrough): add test for switch with logical operators + break (#14811)
fixes #6417
1 parent 7e888d2 commit 1fcf56c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

crates/oxc_linter/src/rules/eslint/no_fallthrough.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ fn test() {
585585
"reportUnusedFallthroughComment": false
586586
}])),
587587
),
588+
// Issue #6417: switch with logical operators should work correctly with break
589+
("switch(true) { case x === 1 || x === 2: a(); break; case x === 3: b(); }", None),
590+
("switch(true) { case x === 1 && y: a(); break; case x === 3: b(); }", None),
588591
];
589592

590593
let fail = vec![
@@ -648,6 +651,9 @@ fn test() {
648651
"reportUnusedFallthroughComment": true
649652
}])),
650653
),
654+
// Issue #6417: switch with logical operators should detect fallthrough
655+
("switch(true) { case x === 1 || x === 2: a(); case x === 3: b(); }", None),
656+
("switch(true) { case x === 1 && y: a(); case x === 3: b(); }", None),
651657
// TODO: it should fail but doesn't, we ignore conditional discriminants for now.
652658
// ("switch (a === b ? c : d) { case 1: ; case 2: ; case 3: ; }", None)
653659
];

crates/oxc_linter/src/snapshots/eslint_no_fallthrough.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,15 @@ source: crates/oxc_linter/src/tester.rs
174174
1switch(foo) { case 0: a(); break; /* falls through */ case 1: b(); }
175175
· ─────────────────────
176176
╰────
177+
178+
eslint(no-fallthrough): Expected a 'break' statement before 'case'.
179+
╭─[no_fallthrough.tsx:1:46]
180+
1switch(true) { case x === 1 || x === 2: a(); case x === 3: b(); }
181+
· ──────────────────
182+
╰────
183+
184+
eslint(no-fallthrough): Expected a 'break' statement before 'case'.
185+
╭─[no_fallthrough.tsx:1:40]
186+
1switch(true) { case x === 1 && y: a(); case x === 3: b(); }
187+
· ──────────────────
188+
╰────

0 commit comments

Comments
 (0)