From bf9dcac7045c0d2314df147ec2744a3ad886564b Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Thu, 15 Dec 2022 16:34:24 +0000 Subject: [PATCH] chore: Rust 1.66 linting --- src/app_data/container_state.rs | 12 ++++++------ src/app_data/mod.rs | 6 +++--- src/app_error.rs | 4 ++-- src/main.rs | 6 +++--- src/ui/draw_blocks.rs | 30 +++++++++++++++--------------- src/ui/gui_state.rs | 2 +- src/ui/mod.rs | 2 +- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/app_data/container_state.rs b/src/app_data/container_state.rs index a6ff466..96d7c50 100644 --- a/src/app_data/container_state.rs +++ b/src/app_data/container_state.rs @@ -111,7 +111,7 @@ impl StatefulList { .state .selected() .map_or(0, |value| if len > 0 { value + 1 } else { value }); - format!("{}/{}", c, self.items.len()) + format!("{c}/{}", self.items.len()) } } } @@ -191,7 +191,7 @@ impl fmt::Display for State { Self::Running => "✓ running", Self::Unknown => "? unknown", }; - write!(f, "{}", disp) + write!(f, "{disp}") } } @@ -237,7 +237,7 @@ impl fmt::Display for DockerControls { Self::Stop => "stop", Self::Unpause => "unpause", }; - write!(f, "{}", disp) + write!(f, "{disp}") } } @@ -292,7 +292,7 @@ impl Stats for CpuStats { impl fmt::Display for CpuStats { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let disp = format!("{:05.2}%", self.0); - write!(f, "{:>x$}", disp, x = f.width().unwrap_or(1)) + write!(f, "{disp:>x$}", x = f.width().unwrap_or(1)) } } @@ -346,7 +346,7 @@ impl fmt::Display for ByteStats { x if x >= ONE_KB => format!("{y:.2} kB", y = as_f64 / ONE_KB), _ => format!("{} B", self.0), }; - write!(f, "{:>x$}", p, x = f.width().unwrap_or(1)) + write!(f, "{p:>x$}", x = f.width().unwrap_or(1)) } } @@ -429,7 +429,7 @@ impl ContainerItem { self.cpu_stats .iter() .enumerate() - .map(|i| (i.0 as f64, i.1 .0 as f64)) + .map(|i| (i.0 as f64, i.1.0)) .collect::>() } diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index 0fa8092..0e7dc7b 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -51,7 +51,7 @@ impl fmt::Display for Header { Self::Rx => "↓ rx", Self::Tx => "↑ tx", }; - write!(f, "{:>x$}", disp, x = f.width().unwrap_or(1)) + write!(f, "{disp:>x$}", x = f.width().unwrap_or(1)) } } @@ -280,9 +280,9 @@ impl AppData { let mut name = self.containers.items[index].name.clone(); name.truncate(32); if logs_len.is_empty() { - format!("- {} ", name) + format!("- {name} ") } else { - format!("{} - {}", logs_len, name) + format!("{logs_len} - {name}") } }) } diff --git a/src/app_error.rs b/src/app_error.rs index 1f90db6..f580b06 100644 --- a/src/app_error.rs +++ b/src/app_error.rs @@ -17,13 +17,13 @@ pub enum AppError { impl fmt::Display for AppError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Self::DockerCommand(s) => write!(f, "Unable to {} container", s), + Self::DockerCommand(s) => write!(f, "Unable to {s} container"), Self::DockerConnect => write!(f, "Unable to access docker daemon"), Self::DockerInterval => write!(f, "Docker update interval needs to be greater than 0"), Self::InputPoll => write!(f, "Unable to poll user input"), Self::MouseCapture(x) => { let reason = if *x { "en" } else { "dis" }; - write!(f, "Unbale to {}able mouse capture", reason) + write!(f, "Unable to {reason}able mouse capture") } Self::Terminal => write!(f, "Unable to draw to terminal"), } diff --git a/src/main.rs b/src/main.rs index e3845ef..88a1fd7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,9 @@ #![forbid(unsafe_code)] #![warn(clippy::unused_async, clippy::unwrap_used, clippy::expect_used)] // Wanring - These are indeed pedantic -// #![warn(clippy::pedantic)] -// #![warn(clippy::nursery)] -// #![allow(clippy::module_name_repetitions, clippy::doc_markdown)] +#![warn(clippy::pedantic)] +#![warn(clippy::nursery)] +#![allow(clippy::module_name_repetitions, clippy::doc_markdown)] // Only allow when debugging // #![allow(unused)] diff --git a/src/ui/draw_blocks.rs b/src/ui/draw_blocks.rs index 9c5c3af..fc7c317 100644 --- a/src/ui/draw_blocks.rs +++ b/src/ui/draw_blocks.rs @@ -148,7 +148,7 @@ pub fn containers( state_style, ), Span::styled( - format!("{}{:>width$}", MARGIN, i.status, width = &widths.status.1), + format!("{MARGIN}{:>width$}", i.status, width = &widths.status.1), state_style, ), Span::styled( @@ -161,7 +161,7 @@ pub fn containers( state_style, ), Span::styled( - format!("{}{:>width$}", MARGIN, mems, width = &widths.mem.1), + format!("{MARGIN}{mems:>width$}", width = &widths.mem.1), state_style, ), Span::styled( @@ -174,19 +174,19 @@ pub fn containers( blue, ), Span::styled( - format!("{}{:>width$}", MARGIN, i.name, width = widths.name.1), + format!("{MARGIN}{:>width$}", i.name, width = widths.name.1), blue, ), Span::styled( - format!("{}{:>width$}", MARGIN, i.image, width = widths.image.1), + format!("{MARGIN}{:>width$}", i.image, width = widths.image.1), blue, ), Span::styled( - format!("{}{:>width$}", MARGIN, i.rx, width = widths.net_rx.1), + format!("{MARGIN}{:>width$}", i.rx, width = widths.net_rx.1), Style::default().fg(Color::Rgb(255, 233, 193)), ), Span::styled( - format!("{}{:>width$}", MARGIN, i.tx, width = widths.net_tx.1), + format!("{MARGIN}{:>width$}", i.tx, width = widths.net_tx.1), Style::default().fg(Color::Rgb(205, 140, 140)), ), ]); @@ -220,7 +220,7 @@ pub fn logs( let block = generate_block(app_data, area, gui_state, SelectablePanel::Logs); let contains_init = gui_state.lock().status_contains(&[Status::Init]); if contains_init { - let paragraph = Paragraph::new(format!("parsing logs {}", loading_icon)) + let paragraph = Paragraph::new(format!("parsing logs {loading_icon}")) .style(Style::default()) .block(block) .alignment(Alignment::Center); @@ -309,7 +309,7 @@ fn make_chart<'a, T: Stats + Display>( Block::default() .title_alignment(Alignment::Center) .title(Span::styled( - format!(" {} {} ", name, current), + format!(" {name} {current} "), Style::default() .fg(title_color) .add_modifier(Modifier::BOLD), @@ -327,7 +327,7 @@ fn make_chart<'a, T: Stats + Display>( .labels(vec![ Span::styled("", Style::default().fg(label_color)), Span::styled( - format!("{}", max), + format!("{max}"), Style::default() .add_modifier(Modifier::BOLD) .fg(label_color), @@ -432,7 +432,7 @@ pub fn heading_bar( .collect::>(); let suffix = if help_visible { "exit" } else { "show" }; - let info_text = format!("( h ) {} help {}", suffix, MARGIN,); + let info_text = format!("( h ) {suffix} help {MARGIN}",); let info_width = info_text.chars().count(); let column_width = usize::from(area.width) - info_width; @@ -453,7 +453,7 @@ pub fn heading_bar( .split(area); if has_containers { // Draw loading icon, or not, and a prefix with a single space - let loading_icon = format!("{:>2}", loading_icon); + let loading_icon = format!("{loading_icon:>2}"); let loading_paragraph = Paragraph::new(loading_icon) .block(block(Color::White)) .alignment(Alignment::Center); @@ -507,9 +507,9 @@ fn max_line_width(text: &str) -> usize { /// Draw the help box in the centre of the screen /// TODO should make every line it's own renderable span pub fn help_box(f: &mut Frame<'_, B>) { - let title = format!(" {} ", VERSION); + let title = format!(" {VERSION} "); - let description_text = format!("\n{}", DESCRIPTION); + let description_text = format!("\n{DESCRIPTION}"); let mut help_text = String::from("\n ( tab ) or ( shift+tab ) to change panels"); help_text @@ -527,7 +527,7 @@ pub fn help_box(f: &mut Frame<'_, B>) { help_text.push_str(format!("\n {}", REPO.trim()).as_str()); // Find the maximum line widths & height - let all_text = format!("{}{}{}", NAME_TEXT, description_text, help_text); + let all_text = format!("{NAME_TEXT}{description_text}{help_text}"); let mut max_line_width = max_line_width(&all_text); let mut lines = all_text.lines().count(); @@ -604,7 +604,7 @@ pub fn error(f: &mut Frame<'_, B>, error: AppError, seconds: Option< _ => String::from("\n\n ( c ) to clear error\n ( q ) to quit oxker"), }; - let mut text = format!("\n{}", error); + let mut text = format!("\n{error}"); text.push_str(to_push.as_str()); diff --git a/src/ui/gui_state.rs b/src/ui/gui_state.rs index 9fc0a0a..bc83f81 100644 --- a/src/ui/gui_state.rs +++ b/src/ui/gui_state.rs @@ -169,7 +169,7 @@ impl fmt::Display for Loading { Self::Nine => '⠇', Self::Ten => '⠏', }; - write!(f, "{}", disp) + write!(f, "{disp}") } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index a3d0517..6632eac 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -67,7 +67,7 @@ pub async fn create_ui( terminal.show_cursor()?; if let Err(err) = res { - println!("{}", err); + println!("{err}"); } Ok(()) }