Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/control_flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,25 @@ impl Visit for Analyzer<'_> {
.iter()
.filter_map(|case| self.get_end_reason(case.start()))
.try_fold(
End::Forced {
ret: false,
throw: false,
infinite_loop: false,
(
End::Forced {
ret: false,
throw: false,
infinite_loop: false,
},
// record if previous is continue
false,
),
|acc, cur| {
if matches!(cur, End::Continue) {
Some((acc.0, true))
} else {
acc.0.merge_forced(cur).map(|acc| (acc, false))
}
},
|acc, cur| acc.merge_forced(cur),
);
)
// None if last is continue
.and_then(|(acc, last_continue)| (!last_continue).then_some(acc));

match forced_end {
Some(e) if has_default => e,
Expand Down
17 changes: 17 additions & 0 deletions src/rules/no_fallthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@ switch(someValue) {
console.log(42);
}
"#,
r#"
switch(foo) {
case true:
switch (bar) {
case true:
default:
return true;
}
default:
switch (bar) {
case true:
return true;
default:
return false;
}
}
"#
};
}

Expand Down
Loading