From 3dc7e189b6457f5b786fe06f2ad7a5a535a364ad Mon Sep 17 00:00:00 2001 From: Linus-Mussmaecher Date: Tue, 28 May 2024 13:01:31 +0200 Subject: [PATCH] Satisfied clippy --- src/app.rs | 2 +- src/config.rs | 4 ++-- src/data/notefile.rs | 4 ++-- src/ui/screen/display_screen.rs | 15 +++++++-------- src/ui/screen/select_screen.rs | 2 +- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/app.rs b/src/app.rs index 8fd7c32..9508bd2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -25,7 +25,7 @@ impl App { pub fn new(config: config::Config) -> Self { // Index all files in path let index = Rc::new(RefCell::new(data::NoteIndex::new( - &std::path::Path::new(&config.get_vault_path()), + std::path::Path::new(&config.get_vault_path()), &config, ))); diff --git a/src/config.rs b/src/config.rs index c1fcbc3..adc26aa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -62,7 +62,7 @@ impl Config { // if none was given, expand the path given from the config file .or_else(|| { config_file.vault_path.and_then(|conf_path_buf| { - expanduser::expanduser(conf_path_buf.to_string_lossy().to_string()).ok() + expanduser::expanduser(conf_path_buf.to_string_lossy()).ok() }) }); @@ -163,7 +163,7 @@ impl Config { target: &mut impl std::io::Write, ) -> Result<(), error::RucolaError> { if let Some(prep) = &self.config_file.html_prepend { - target.write(prep.as_bytes())?; + target.write_all(prep.as_bytes())?; } Ok(()) } diff --git a/src/data/notefile.rs b/src/data/notefile.rs index 3aa6763..e8d5410 100644 --- a/src/data/notefile.rs +++ b/src/data/notefile.rs @@ -171,7 +171,7 @@ pub fn create_note_file( )?; // Add the file to the index if nothing threw and error and early returned. - index.borrow_mut().register(&path::Path::new(&path)); + index.borrow_mut().register(path::Path::new(&path)); Ok(()) } @@ -233,7 +233,7 @@ pub fn create_html( let mut tar_file = std::fs::File::create(tar_path.clone())?; - write!(tar_file, "{}\n", note.name)?; + writeln!(tar_file, "{}", note.name)?; config.prepend_to_html(&mut tar_file)?; comrak::format_html( diff --git a/src/ui/screen/display_screen.rs b/src/ui/screen/display_screen.rs index 7a65446..f39e4e8 100644 --- a/src/ui/screen/display_screen.rs +++ b/src/ui/screen/display_screen.rs @@ -99,13 +99,12 @@ impl super::Screen for DisplayScreen { .tags .iter() .enumerate() - .map(|(index, s)| { + .flat_map(|(index, s)| { [ Span::styled(if index == 0 { "" } else { ", " }, styles.text_style), Span::styled(s.as_str(), styles.subtitle_style), ] }) - .flatten() .collect_vec(); // Stats Area @@ -175,21 +174,21 @@ impl super::Screen for DisplayScreen { KeyCode::Left | KeyCode::Char('H' | 'h') => ui::Message::DisplayStackPop, // Go up in the current list with k KeyCode::Up | KeyCode::Char('K' | 'k') => { - self.selected - .get_mut(self.foc_table) - .map(|selected| *selected = selected.saturating_sub(1)); + if let Some(selected) = self.selected.get_mut(self.foc_table) { + *selected = selected.saturating_sub(1); + } ui::Message::None } // Go down in the current list with j KeyCode::Down | KeyCode::Char('J' | 'j') => { - self.selected.get_mut(self.foc_table).map(|selected| { + if let Some(selected) = self.selected.get_mut(self.foc_table) { *selected = selected.saturating_add(1).min( self.links .get(self.foc_table) .map(|list| list.len().saturating_sub(1)) .unwrap_or_default(), - ) - }); + ); + } ui::Message::None } // Change list with Tab diff --git a/src/ui/screen/select_screen.rs b/src/ui/screen/select_screen.rs index afc5ee4..f59f4fa 100644 --- a/src/ui/screen/select_screen.rs +++ b/src/ui/screen/select_screen.rs @@ -258,7 +258,7 @@ impl SelectScreen { SortingMode::GlobalInLinks => env_stats.inlinks_global, SortingMode::LocalInLinks => env_stats.inlinks_local, SortingMode::Score => env_stats.match_score as usize, - SortingMode::Broken => env_stats.broken_links as usize, + SortingMode::Broken => env_stats.broken_links, } } else { 0