Skip to content

Commit 86b35bc

Browse files
authored
refactor: use clippy::unwrap_used (#1882)
* refactor: use clippy::unwrap_used * fix log format use * fix a bunch of macos ones * oop * allow schema script * driveby schema bump
1 parent 85af7ba commit 86b35bc

File tree

23 files changed

+195
-127
lines changed

23 files changed

+195
-127
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,4 @@ missing_crate_level_docs = "deny"
254254
todo = "deny"
255255
unimplemented = "deny"
256256
missing_safety_doc = "deny"
257+
unwrap_used = "deny"

build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! General build script used by bottom to generate completion files and set binary version.
22
3+
#![expect(clippy::unwrap_used)]
4+
35
#[expect(dead_code)]
46
#[path = "src/options/args.rs"]
57
mod args;

clippy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
cognitive-complexity-threshold = 100
22
type-complexity-threshold = 500
33
too-many-arguments-threshold = 8
4+
allow-unwrap-in-consts = true
5+
allow-unwrap-in-tests = true

schema/nightly/bottom.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,12 @@
471471
}
472472
]
473473
},
474+
"read_only": {
475+
"type": [
476+
"boolean",
477+
"null"
478+
]
479+
},
474480
"regex": {
475481
"type": [
476482
"boolean",

src/app/data/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl StoredData {
213213
reason = "this is fine since it's done via a static OnceLock. In the future though, separate it out."
214214
)]
215215
if let Some(new_name) = DISK_REGEX
216-
.get_or_init(|| Regex::new(r"disk\d+").unwrap())
216+
.get_or_init(|| Regex::new(r"disk\d+").expect("valid regex"))
217217
.find(checked_name)
218218
{
219219
io.get(new_name.as_str())

src/app/states.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl AppSearchState {
192192

193193
self.grapheme_cursor
194194
.next_boundary(chunk, start_position)
195-
.unwrap();
195+
.expect("another grapheme boundary should exist after the cursor with the provided context");
196196
}
197197
_ => panic!("{err:?}"),
198198
},
@@ -213,7 +213,9 @@ impl AppSearchState {
213213
self.grapheme_cursor
214214
.provide_context(&self.current_search_query[0..ctx], 0);
215215

216-
self.grapheme_cursor.prev_boundary(chunk, 0).unwrap();
216+
self.grapheme_cursor
217+
.prev_boundary(chunk, 0)
218+
.expect("another grapheme boundary should exist before the cursor with the provided context");
217219
}
218220
_ => panic!("{err:?}"),
219221
},

src/bin/schema.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#![cfg(feature = "generate_schema")]
2+
#![expect(
3+
clippy::unwrap_used,
4+
reason = "this is just used to generate jsonschema files"
5+
)]
26

37
use bottom::{options::config, widgets};
48
use clap::Parser;

src/canvas/components/time_graph/base/time_chart.rs

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -674,17 +674,22 @@ impl<'a> TimeChart<'a> {
674674
&self, buf: &mut Buffer, layout: &ChartLayout, chart_area: Rect, graph_area: Rect,
675675
) {
676676
let Some(y) = layout.label_x else { return };
677-
let labels = self.x_axis.labels.as_ref().unwrap();
677+
let Some(labels) = self.x_axis.labels.as_ref() else {
678+
return;
679+
};
678680
let labels_len = labels.len() as u16;
679681
if labels_len < 2 {
680682
return;
681683
}
682684

685+
let first_label = labels.first().expect("must have at least 2 labels");
686+
let last_label = labels.last().expect("must have at least 2 labels");
687+
683688
let width_between_ticks = graph_area.width / labels_len;
684689

685690
let label_area = self.first_x_label_area(
686691
y,
687-
labels.first().unwrap().width() as u16,
692+
first_label.width() as u16,
688693
width_between_ticks,
689694
chart_area,
690695
graph_area,
@@ -696,7 +701,7 @@ impl<'a> TimeChart<'a> {
696701
Alignment::Right => Alignment::Left,
697702
};
698703

699-
Self::render_label(buf, labels.first().unwrap(), label_area, label_alignment);
704+
Self::render_label(buf, first_label, label_area, label_alignment);
700705

701706
for (i, label) in labels[1..labels.len() - 1].iter().enumerate() {
702707
// We add 1 to x (and width-1 below) to leave at least one space before each
@@ -710,7 +715,7 @@ impl<'a> TimeChart<'a> {
710715
let x = graph_area.right() - width_between_ticks;
711716
let label_area = Rect::new(x, y, width_between_ticks, 1);
712717
// The last label should be aligned Right to be at the edge of the graph area
713-
Self::render_label(buf, labels.last().unwrap(), label_area, Alignment::Right);
718+
Self::render_label(buf, last_label, label_area, Alignment::Right);
714719
}
715720

716721
fn first_x_label_area(
@@ -751,8 +756,11 @@ impl<'a> TimeChart<'a> {
751756
// FIXME: Control how many y-axis labels are rendered based on height.
752757

753758
let Some(x) = layout.label_y else { return };
754-
let labels = self.y_axis.labels.as_ref().unwrap();
759+
let Some(labels) = self.y_axis.labels.as_ref() else {
760+
return;
761+
};
755762
let labels_len = labels.len() as u16;
763+
756764
for (i, label) in labels.iter().enumerate() {
757765
let dy = i as u16 * (graph_area.height - 1) / (labels_len - 1);
758766
if dy < graph_area.bottom() {
@@ -836,39 +844,41 @@ impl Widget for TimeChart<'_> {
836844
.render(graph_area, buf);
837845

838846
if let Some((x, y)) = layout.title_x {
839-
let title = self.x_axis.title.as_ref().unwrap();
840-
let width = graph_area
841-
.right()
842-
.saturating_sub(x)
843-
.min(title.width() as u16);
844-
buf.set_style(
845-
Rect {
846-
x,
847-
y,
848-
width,
849-
height: 1,
850-
},
851-
original_style,
852-
);
853-
buf.set_line(x, y, title, width);
847+
if let Some(title) = self.x_axis.title.as_ref() {
848+
let width = graph_area
849+
.right()
850+
.saturating_sub(x)
851+
.min(title.width() as u16);
852+
buf.set_style(
853+
Rect {
854+
x,
855+
y,
856+
width,
857+
height: 1,
858+
},
859+
original_style,
860+
);
861+
buf.set_line(x, y, title, width);
862+
}
854863
}
855864

856865
if let Some((x, y)) = layout.title_y {
857-
let title = self.y_axis.title.as_ref().unwrap();
858-
let width = graph_area
859-
.right()
860-
.saturating_sub(x)
861-
.min(title.width() as u16);
862-
buf.set_style(
863-
Rect {
864-
x,
865-
y,
866-
width,
867-
height: 1,
868-
},
869-
original_style,
870-
);
871-
buf.set_line(x, y, title, width);
866+
if let Some(title) = self.y_axis.title.as_ref() {
867+
let width = graph_area
868+
.right()
869+
.saturating_sub(x)
870+
.min(title.width() as u16);
871+
buf.set_style(
872+
Rect {
873+
x,
874+
y,
875+
width,
876+
height: 1,
877+
},
878+
original_style,
879+
);
880+
buf.set_line(x, y, title, width);
881+
}
872882
}
873883

874884
if let Some(legend_area) = layout.legend_area {

src/canvas/components/time_graph/base/time_chart/grid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Grid for BrailleGrid {
7575
}
7676

7777
fn save(&self) -> Layer {
78-
let string = String::from_utf16(&self.utf16_code_points).unwrap();
78+
let string = String::from_utf16(&self.utf16_code_points).expect("valid UTF-16 data");
7979
// the background color is always reset for braille patterns
8080
let colors = self.colors.iter().map(|c| (*c, Color::Reset)).collect();
8181
Layer { string, colors }

src/canvas/components/widget_carousel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ impl Painter {
1818
let current_table = if let BottomWidgetType::ProcSort = current_table.widget_type {
1919
current_table
2020
.right_neighbour
21-
.map(|id| app_state.widget_map.get(&id).unwrap())
22-
.unwrap()
21+
.and_then(|id| app_state.widget_map.get(&id))
22+
.expect("id must exist in widget mapping")
2323
} else {
2424
current_table
2525
};

0 commit comments

Comments
 (0)