Skip to content

Commit 179d3e1

Browse files
1995parhamclaude
andcommitted
fix: satisfy clippy manual_checked_division lint
Use checked_div instead of manual zero-guarded division in views.rs to fix the cargo clippy -- -D warnings CI step. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 487f2ae commit 179d3e1

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

src/views.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@ where
7171
let remaining = week.iter().map(|&i| self.remaining(i)).sum::<u32>();
7272
let completions = weekly_goal - remaining;
7373
let full = VIEW_WIDTH - 8;
74-
let bars_to_fill = if weekly_goal > 0 {
75-
(completions * full as u32) / weekly_goal
76-
} else {
77-
0
78-
};
74+
let bars_to_fill = (completions * full as u32).checked_div(weekly_goal).unwrap_or(0);
7975
let percentage = if weekly_goal > 0 {
8076
(completions as f64 * 100.) / weekly_goal as f64
8177
} else {
@@ -173,7 +169,7 @@ where
173169
p.print(coords, &format!("{month_name} --"));
174170
});
175171
} else {
176-
let pct = (reached_days * 100) / total_days;
172+
let pct = (reached_days * 100).checked_div(total_days).unwrap_or(0);
177173
let style = if reached_days >= total_days {
178174
goal_reached_style
179175
} else if reached_days > 0 {
@@ -216,11 +212,7 @@ where
216212
} else {
217213
0
218214
};
219-
let pct = if total_days > 0 {
220-
(reached_days * 100) / total_days
221-
} else {
222-
0
223-
};
215+
let pct = (reached_days * 100).checked_div(total_days).unwrap_or(0);
224216

225217
printer.with_style(future_style, |p| {
226218
p.print((0, line), &format!("{y}"));

0 commit comments

Comments
 (0)