Skip to content

Commit efdb2cf

Browse files
authored
fix(console): lint new tasks, not just when there is a stats update (console-rs#126)
I was working on a lost waker lint, and noticed that the "coma" task wasn't being linted, because it never sends another stats update. This fixes it to lint tasks when we first get them, too.
1 parent bc2b723 commit efdb2cf

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

console/src/tasks.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ impl State {
164164
let mut stats_update = update.stats_update;
165165
let new_list = &mut self.new_tasks;
166166
new_list.clear();
167+
let linters = &self.linters;
167168

168169
let metas = &mut self.metas;
169170
let new_tasks = update.new_tasks.into_iter().filter_map(|mut task| {
@@ -214,26 +215,19 @@ impl State {
214215
warnings: Vec::new(),
215216
};
216217
task.update();
218+
task.lint(linters);
217219
let task = Rc::new(RefCell::new(task));
218220
new_list.push(Rc::downgrade(&task));
219221
Some((id, task))
220222
});
221223
self.tasks.extend(new_tasks);
222-
let linters = &self.linters;
223224
for (id, stats) in stats_update {
224225
if let Some(task) = self.tasks.get_mut(&id) {
225226
let mut task = task.borrow_mut();
226227
tracing::trace!(?task, "processing stats update for");
227-
task.warnings.clear();
228-
for lint in linters {
229-
tracing::debug!(?lint, ?task, "checking...");
230-
if let Some(lint) = lint.check(&*task) {
231-
tracing::info!(?lint, ?task, "found a warning!");
232-
task.warnings.push(lint)
233-
}
234-
}
235228
task.stats = stats.into();
236229
task.update();
230+
task.lint(linters);
237231
}
238232
}
239233
}
@@ -417,6 +411,17 @@ impl Task {
417411
self.completed_for = 1;
418412
}
419413
}
414+
415+
fn lint(&mut self, linters: &[Linter<Task>]) {
416+
self.warnings.clear();
417+
for lint in linters {
418+
tracing::debug!(?lint, task = ?self, "checking...");
419+
if let Some(warning) = lint.check(self) {
420+
tracing::info!(?warning, task = ?self, "found a warning!");
421+
self.warnings.push(warning)
422+
}
423+
}
424+
}
420425
}
421426

422427
impl Details {

0 commit comments

Comments
 (0)