Skip to content

Commit 9ae4953

Browse files
committed
fix(linter): fix no-fallthrough rule, when the default condition is not last (#12793)
1 parent b9f200f commit 9ae4953

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,12 @@ fn get_switch_semantic_cases(
437437
let cfg = ctx.cfg();
438438
let graph = cfg.graph();
439439
let has_default = switch.cases.iter().any(SwitchCase::is_default_case);
440-
let (tests, exit) = graph
440+
let (cfg_ids, tests, exit) = graph
441441
.edges_directed(node.cfg_id(), Direction::Outgoing)
442-
.fold((Vec::new(), None), |(mut conds, exit), it| {
442+
.fold((Vec::new(), Vec::new(), None), |(mut cfg_ids, mut conds, exit), it| {
443443
let target = it.target();
444444
if !matches!(it.weight(), EdgeType::Normal) {
445-
(conds, exit)
445+
(cfg_ids, conds, exit)
446446
} else if cfg
447447
.basic_block(target)
448448
.instructions()
@@ -466,18 +466,16 @@ fn get_switch_semantic_cases(
466466
})
467467
})
468468
.is_some_and(|it| it.consequent.is_empty() || it.consequent.iter().exactly_one().is_ok_and(|it| matches!(it, Statement::BlockStatement(b) if b.body.is_empty())));
469+
cfg_ids.push(target);
469470
conds.push((target, is_empty));
470-
(conds, exit)
471+
(cfg_ids, conds, exit)
471472
} else {
472-
(conds, Some(target))
473+
cfg_ids.push(target);
474+
(cfg_ids, conds, Some(target))
473475
}
474476
});
475477

476-
let mut cfg_ids: Vec<_> = tests.iter().rev().map(|it| it.0).collect();
477478
let (default, exit) = if has_default {
478-
if let Some(exit) = exit {
479-
cfg_ids.push(exit);
480-
}
481479
(exit, None)
482480
} else {
483481
(None, exit)

0 commit comments

Comments
 (0)