Skip to content

Commit 829a945

Browse files
committed
Enable nursery lints
1 parent a992bc0 commit 829a945

File tree

10 files changed

+36
-49
lines changed

10 files changed

+36
-49
lines changed

cli/src/import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ where
5858
// Add multiple messages to the database
5959
#[allow(clippy::module_name_repetitions)]
6060
pub async fn import_messages<B: Backend>(
61-
db: &mut Database<B>,
61+
db: &Database<B>,
6262
config: &Option<Config>,
6363
new_messages: Vec<NewMessage>,
6464
) -> Result<Vec<Message>> {

cli/src/main.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#![deny(clippy::clone_on_ref_ptr)]
2-
#![deny(clippy::pedantic)]
1+
#![warn(clippy::clone_on_ref_ptr, clippy::pedantic, clippy::nursery)]
2+
#![allow(clippy::future_not_send, clippy::missing_const_for_fn)]
33

44
mod cli;
55
mod config;
@@ -111,7 +111,7 @@ fn states_from_view_message_state(state: ViewMessageState) -> Vec<State> {
111111

112112
async fn run<B: Backend + Send + Sync + 'static>(
113113
config: Option<Config>,
114-
mut db: Database<B>,
114+
db: Database<B>,
115115
) -> Result<()> {
116116
let cli = Cli::parse();
117117
let formatter = create_formatter(&cli);
@@ -132,17 +132,13 @@ async fn run<B: Backend + Send + Sync + 'static>(
132132
content,
133133
state: Some(cli_state),
134134
}];
135-
let messages = import_messages(&mut db, &config, raw_messages).await?;
135+
let messages = import_messages(&db, &config, raw_messages).await?;
136136
print!("{}", formatter.format_messages(&messages)?);
137137
}
138138

139139
Command::Import { format } => {
140-
let messages = import_messages(
141-
&mut db,
142-
&config,
143-
read_messages_stdin(stdin().lock(), format),
144-
)
145-
.await?;
140+
let messages =
141+
import_messages(&db, &config, read_messages_stdin(stdin().lock(), format)).await?;
146142
print!("{}", formatter.format_messages(&messages)?);
147143
}
148144

cli/src/message_components.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl MessageComponents {
1818
// Attempt to truncate the combined length of the message components down
1919
// to max_length. If this isn't possible, the message components will be
2020
// truncated as much as possible.
21-
pub fn truncate(self, max_length: usize) -> MessageComponents {
21+
pub fn truncate(self, max_length: usize) -> Self {
2222
let total_length =
2323
8 + self.content.width() + self.mailbox.width() + self.time.len() + self.appendix.len();
2424
if total_length <= max_length {
@@ -30,22 +30,22 @@ impl MessageComponents {
3030
let others_length = total_length - self.mailbox.width();
3131
if others_length + 4 <= max_length {
3232
let mailbox = truncate_string(&self.mailbox, max_length - others_length).0;
33-
return MessageComponents { mailbox, ..self };
33+
return Self { mailbox, ..self };
3434
}
3535

3636
// Next try to truncate the content
3737
let others_length = total_length - self.content.width();
3838
if others_length + 4 <= max_length {
3939
let content = truncate_string(&self.content, max_length - others_length).0;
40-
return MessageComponents { content, ..self };
40+
return Self { content, ..self };
4141
}
4242

4343
// Lastly, truncate the content and the mailbox
4444
let others_length = total_length - self.content.width() - self.mailbox.width();
4545
let mailbox_and_content_length = max(max_length.saturating_sub(others_length) / 2, 4);
4646
let mailbox = truncate_string(&self.mailbox, mailbox_and_content_length).0;
4747
let content = truncate_string(&self.content, mailbox_and_content_length).0;
48-
MessageComponents {
48+
Self {
4949
content,
5050
mailbox,
5151
..self

cli/src/truncate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct TruncatedLine {
2020
impl TruncatedLine {
2121
// Create a new instance
2222
pub fn new(max_columns: usize) -> Self {
23-
TruncatedLine {
23+
Self {
2424
available_columns: max_columns,
2525
sections: Vec::default(),
2626
}

cli/src/tui/app.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ impl App {
6161
db: Database<B>,
6262
initial_mailbox: Option<database::Mailbox>,
6363
initial_states: Vec<State>,
64-
) -> Result<App> {
64+
) -> Result<Self> {
6565
let db = Arc::new(db);
6666
let (worker_tx, worker_rx) = spawn(Arc::clone(&db));
67-
let mut app = App {
67+
let mut app = Self {
6868
active_pane: Pane::Messages,
6969
mailboxes: TreeList::new(),
7070
messages: MultiselectList::new(),
@@ -145,15 +145,15 @@ impl App {
145145
}
146146

147147
// Update the mailboxes list
148-
pub fn update_mailboxes(&mut self) -> Result<()> {
148+
pub fn update_mailboxes(&self) -> Result<()> {
149149
self.worker_tx.send(Request::LoadMailboxes(
150150
Filter::new().with_states(self.get_active_states()),
151151
))?;
152152
Ok(())
153153
}
154154

155155
// Update the messages list based on the mailbox and other filters
156-
pub fn update_messages(&mut self) -> Result<()> {
156+
pub fn update_messages(&self) -> Result<()> {
157157
let filter = self.get_display_filter();
158158
self.worker_tx.send(Request::LoadMessages(filter))?;
159159
Ok(())

cli/src/tui/mod.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,19 @@ fn handle_mailbox_key(app: &mut App, key: KeyEvent) -> Result<()> {
134134
app.mailboxes.parent();
135135
}
136136
KeyCode::Char('a') => {
137-
if let Some(active_mailbox) = old_active_mailbox.clone() {
137+
if let Some(active_mailbox) = old_active_mailbox {
138138
app.set_mailbox_message_state(active_mailbox, State::Archived)?;
139139
}
140140
return Ok(());
141141
}
142142
KeyCode::Char('r') => {
143-
if let Some(active_mailbox) = old_active_mailbox.clone() {
143+
if let Some(active_mailbox) = old_active_mailbox {
144144
app.set_mailbox_message_state(active_mailbox, State::Read)?;
145145
}
146146
return Ok(());
147147
}
148148
KeyCode::Char('u') => {
149-
if let Some(active_mailbox) = old_active_mailbox.clone() {
149+
if let Some(active_mailbox) = old_active_mailbox {
150150
app.set_mailbox_message_state(active_mailbox, State::Unread)?;
151151
}
152152
return Ok(());
@@ -163,11 +163,9 @@ fn handle_mailbox_key(app: &mut App, key: KeyEvent) -> Result<()> {
163163
// If the new active mailbox is a descendant of the old one or if there wasn't an old active mailbox, the
164164
// messages list can be optimistically updated by filtering against the new active mailbox instead of needing
165165
// to refresh the whole list
166-
let local_update = if let Some(old_active_mailbox) = old_active_mailbox {
166+
let local_update = old_active_mailbox.map_or(true, |old_active_mailbox| {
167167
old_active_mailbox.is_ancestor_of(active_mailbox)
168-
} else {
169-
true
170-
};
168+
});
171169

172170
if local_update {
173171
// Optimistically update the messages list
@@ -258,7 +256,7 @@ fn ui<B: Backend>(frame: &mut Frame<B>, app: &mut App) {
258256
}
259257

260258
// Render the footer section of the UI
261-
fn render_footer<B: Backend>(frame: &mut Frame<B>, app: &mut App, area: Rect) {
259+
fn render_footer<B: Backend>(frame: &mut Frame<B>, app: &App, area: Rect) {
262260
const ACTIVE_STYLE: Style = Style::new().fg(Color::Black).bg(Color::Green);
263261
const INACTIVE_STYLE: Style = Style::new();
264262
const SELECTING_STYLE: Style = Style::new().fg(Color::LightBlue);
@@ -338,10 +336,9 @@ fn render_mailboxes<B: Backend>(frame: &mut Frame<B>, app: &mut App, area: Rect)
338336
.border_style(border_style)
339337
.title(format!(
340338
"Mailboxes ({}{})",
341-
match app.mailboxes.get_cursor() {
342-
None => String::new(),
343-
Some(index) => format!("{}/", index + 1),
344-
},
339+
app.mailboxes
340+
.get_cursor()
341+
.map_or_else(String::new, |index| format!("{}/", index + 1)),
345342
app.mailboxes.get_items().len()
346343
)),
347344
)
@@ -398,10 +395,9 @@ fn render_messages<B: Backend>(frame: &mut Frame<B>, app: &mut App, area: Rect)
398395
.border_style(border_style)
399396
.title(format!(
400397
"Messages ({}{})",
401-
match app.messages.get_cursor() {
402-
None => String::new(),
403-
Some(index) => format!("{}/", index + 1),
404-
},
398+
app.messages
399+
.get_cursor()
400+
.map_or_else(String::new, |index| format!("{}/", index + 1)),
405401
app.messages.get_items().len()
406402
)),
407403
)

cli/src/tui/monotonic_counter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct MonotonicCounter {
1818
impl MonotonicCounter {
1919
// Create a new monotonic counter
2020
pub fn new() -> Self {
21-
MonotonicCounter {
21+
Self {
2222
last_id: Arc::new(AtomicU64::new(0)),
2323
}
2424
}

cli/src/tui/multiselect_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ where
7373
{
7474
// Create a new list with no items
7575
pub fn new() -> Self {
76-
MultiselectList {
76+
Self {
7777
state: ListState::default(),
7878
items: vec![],
7979
selected_items: HashSet::new(),

cli/src/tui/navigable_list.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ where
4242
self.set_cursor(match self.get_items().len() {
4343
0 => None,
4444
num_items => {
45-
let new_index = (match self.get_cursor() {
46-
None => -1,
47-
Some(index) => index as i32,
48-
}) + change;
45+
let new_index = self.get_cursor().map_or(-1, |index| index as i32) + change;
4946
// Bounds check the new index
5047
Some((new_index).clamp(0, num_items as i32 - 1) as usize)
5148
}
@@ -75,20 +72,18 @@ where
7572

7673
// Replace the list's items with a new set of items
7774
fn replace_items(&mut self, items: Vec<Item>) {
78-
let cursor_candidates = match self.get_cursor() {
79-
None => vec![],
75+
let cursor_candidates = self.get_cursor().map_or_else(Vec::new, |index| {
8076
// The items at and after the cursor are the first candidates,
8177
// starting with the items closest to the cursor, followed by
8278
// the items before the cursor, again starting with the items
8379
// closest to the cursor
84-
Some(index) => self
85-
.get_items()
80+
self.get_items()
8681
.iter()
8782
.skip(index)
8883
.chain(self.get_items().iter().take(index).rev())
8984
.map(Keyed::get_key)
90-
.collect(),
91-
};
85+
.collect()
86+
});
9287

9388
*self.get_items_mut() = items;
9489

cli/src/tui/tree_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ where
3434
impl<Item: Depth + Keyed> TreeList<Item> {
3535
// Create a new list with no items
3636
pub fn new() -> Self {
37-
TreeList {
37+
Self {
3838
state: ListState::default(),
3939
items: vec![],
4040
}

0 commit comments

Comments
 (0)