Skip to content

Commit 95a6dab

Browse files
authored
feat(console): add LostWaker lint (console-rs#127)
This lint will warn when a task that isn't completed has no more wakers, implying the task will never wake up again. Note that this depends on console-rs#126 in most cases. ![image](https://user-images.githubusercontent.com/2796466/132753053-2a8e18be-3251-41c3-92e5-1e0d0939b369.png)
1 parent efdb2cf commit 95a6dab

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

console/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ async fn main() -> color_eyre::Result<()> {
4747
let mut tasks = State::default()
4848
// TODO(eliza): allow configuring the list of linters via the
4949
// CLI/possibly a config file?
50-
.with_linters(vec![warnings::Linter::new(
51-
warnings::SelfWakePercent::default(),
52-
)]);
50+
.with_linters(vec![
51+
warnings::Linter::new(warnings::SelfWakePercent::default()),
52+
warnings::Linter::new(warnings::LostWaker),
53+
]);
5354
let mut input = input::EventStream::new();
5455
let mut view = view::View::new(styles);
5556

console/src/warnings.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,20 @@ impl Warn<Task> for SelfWakePercent {
133133
)
134134
}
135135
}
136+
137+
#[derive(Clone, Debug, Default)]
138+
pub(crate) struct LostWaker;
139+
140+
impl Warn<Task> for LostWaker {
141+
fn summary(&self) -> &str {
142+
"tasks have lost their waker"
143+
}
144+
145+
fn check(&self, task: &Task) -> bool {
146+
!task.is_completed() && task.waker_count() == 0
147+
}
148+
149+
fn format(&self, _: &Task) -> String {
150+
"This task has lost its waker, and will never be woken again.".into()
151+
}
152+
}

0 commit comments

Comments
 (0)