From 4a3d32cf9bed3e28396407d2a0206fd35859c47e Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sun, 5 Sep 2021 23:40:48 +0900 Subject: [PATCH] fix clippy warnings --- src/app.rs | 2 +- src/components/record_table.rs | 4 ---- src/components/table.rs | 2 +- src/components/utils/scroll_vertical.rs | 15 +++++++++++++++ src/config.rs | 12 ++++++------ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/app.rs b/src/app.rs index b522e50..b48deef 100644 --- a/src/app.rs +++ b/src/app.rs @@ -6,7 +6,7 @@ use crate::{ components::tab::Tab, components::{ command, ConnectionsComponent, DatabasesComponent, ErrorComponent, HelpComponent, - RecordTableComponent, TabComponent, TableComponent, TableStatusComponent, + RecordTableComponent, TabComponent, TableComponent, }, config::Config, }; diff --git a/src/components/record_table.rs b/src/components/record_table.rs index 7c9898c..ebdf1ba 100644 --- a/src/components/record_table.rs +++ b/src/components/record_table.rs @@ -49,10 +49,6 @@ impl RecordTableComponent { self.filter.reset(); } - pub fn len(&self) -> usize { - self.table.rows.len() - } - pub fn filter_focused(&self) -> bool { matches!(self.focus, Focus::Filter) } diff --git a/src/components/table.rs b/src/components/table.rs index 5e38f59..abf7914 100644 --- a/src/components/table.rs +++ b/src/components/table.rs @@ -505,7 +505,7 @@ impl DrawableComponent for TableComponent { } else { Some(self.headers.len()) }, - self.table.as_ref().map_or(None, |t| Some(t.1.clone())), + self.table.as_ref().map(|t| t.1.clone()), ) .draw(f, chunks[1], focused)?; diff --git a/src/components/utils/scroll_vertical.rs b/src/components/utils/scroll_vertical.rs index 3d8f310..0c2fb88 100644 --- a/src/components/utils/scroll_vertical.rs +++ b/src/components/utils/scroll_vertical.rs @@ -74,3 +74,18 @@ const fn calc_scroll_top( current_top } } + +#[cfg(test)] +mod tests { + use super::calc_scroll_top; + + #[test] + fn test_scroll_no_scroll_to_top() { + assert_eq!(calc_scroll_top(1, 10, 4, 4), 0); + } + + #[test] + fn test_scroll_zero_height() { + assert_eq!(calc_scroll_top(4, 0, 4, 3), 0); + } +} diff --git a/src/config.rs b/src/config.rs index 7352997..3384e0b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -159,15 +159,15 @@ impl Connection { let user = self .user .as_ref() - .ok_or(anyhow::anyhow!("user is not set"))?; + .ok_or_else(|| anyhow::anyhow!("user is not set"))?; let host = self .host .as_ref() - .ok_or(anyhow::anyhow!("host is not set"))?; + .ok_or_else(|| anyhow::anyhow!("host is not set"))?; let port = self .port .as_ref() - .ok_or(anyhow::anyhow!("port is not set"))?; + .ok_or_else(|| anyhow::anyhow!("port is not set"))?; match self.database.as_ref() { Some(database) => Ok(format!( @@ -189,15 +189,15 @@ impl Connection { let user = self .user .as_ref() - .ok_or(anyhow::anyhow!("user is not set"))?; + .ok_or_else(|| anyhow::anyhow!("user is not set"))?; let host = self .host .as_ref() - .ok_or(anyhow::anyhow!("host is not set"))?; + .ok_or_else(|| anyhow::anyhow!("host is not set"))?; let port = self .port .as_ref() - .ok_or(anyhow::anyhow!("port is not set"))?; + .ok_or_else(|| anyhow::anyhow!("port is not set"))?; match self.database.as_ref() { Some(database) => Ok(format!(