chore: linting nursery

This commit is contained in:
Jack Wills
2022-08-04 13:01:16 +00:00
parent 1263662bd9
commit 1bd61d4ce8
8 changed files with 23 additions and 35 deletions
+9 -13
View File
@@ -68,15 +68,11 @@ impl<T> StatefulList<T> {
String::from("")
} else {
let len = self.items.len();
let c = if let Some(value) = self.state.selected() {
if len > 0 {
let c = self.state.selected().map_or(0, |value| if len > 0 {
value + 1
} else {
value
}
} else {
0
};
});
format!("{}/{}", c, self.items.len())
}
}
@@ -95,7 +91,7 @@ pub enum State {
}
impl State {
pub fn get_color(&self) -> Color {
pub const fn get_color(&self) -> Color {
match self {
Self::Running => Color::Green,
Self::Removing => Color::LightRed,
@@ -105,7 +101,7 @@ impl State {
}
}
// Dirty way to create order for the state, rather than impl Ord
pub fn order(&self) -> &'static str {
pub const fn order(&self) -> &'static str {
match self {
Self::Running => "a",
Self::Paused => "b",
@@ -158,7 +154,7 @@ pub enum DockerControls {
}
impl DockerControls {
pub fn get_color(&self) -> Color {
pub const fn get_color(&self) -> Color {
match self {
Self::Start => Color::Green,
Self::Stop => Color::Red,
@@ -205,7 +201,7 @@ pub struct CpuStats {
}
impl CpuStats {
pub fn new(value: f64) -> Self {
pub const fn new(value: f64) -> Self {
Self { value }
}
}
@@ -276,7 +272,7 @@ impl Ord for ByteStats {
}
impl ByteStats {
pub fn new(value: u64) -> Self {
pub const fn new(value: u64) -> Self {
Self { value }
}
pub fn update(&mut self, value: u64) {
@@ -423,8 +419,8 @@ pub struct Columns {
}
impl Columns {
// (Column titles, minimum header string length)
pub fn new() -> Self {
/// (Column titles, minimum header string length)
pub const fn new() -> Self {
Self {
state: (Header::State, 11),
status: (Header::Status, 16),
+1 -5
View File
@@ -259,11 +259,7 @@ impl AppData {
/// Get the title for log panel for selected container
/// will be "logs x/x"
pub fn get_log_title(&self) -> String {
if let Some(index) = self.get_selected_log_index() {
self.containers.items[index].logs.get_state_title()
} else {
String::from("")
}
self.get_selected_log_index().map_or_else(|| String::from(""), |index| self.containers.items[index].logs.get_state_title())
}
/// select next selected log line
+1 -5
View File
@@ -102,11 +102,7 @@ impl DockerData {
let mem_stat = stats.memory_stats.usage.unwrap_or(0);
let mem_limit = stats.memory_stats.limit.unwrap_or(0);
let some_key = if let Some(networks) = &stats.networks {
networks.keys().next().cloned()
} else {
None
};
let some_key = stats.networks.as_ref().and_then(|networks| networks.keys().next().cloned());
let cpu_stats = Self::calculate_usage(&stats);
+2 -2
View File
@@ -1,8 +1,8 @@
#![forbid(unsafe_code)]
#![warn(clippy::unused_async, clippy::unwrap_used, clippy::expect_used)]
// Wanring - These are indeed pedantic
#![warn(clippy::pedantic)]
// #![warn(clippy::nursery)]
// #![warn(clippy::pedantic)]
#![warn(clippy::nursery)]
#![allow(clippy::module_name_repetitions, clippy::doc_markdown)]
// Only allow when debugging
+1 -1
View File
@@ -31,7 +31,7 @@ pub struct CliArgs {
impl CliArgs {
/// Parse cli arguments
pub fn new() -> Self {
let args = CliArgs::parse();
let args = Self::parse();
// Quit the program if the docker update argument is 0
// Should maybe change it to check if less than 100
+1 -1
View File
@@ -54,7 +54,7 @@ pub mod log_sanitizer {
}
/// Change from ansi to tui colors
fn color_ansi_to_tui(color: CansiColor) -> Color {
const fn color_ansi_to_tui(color: CansiColor) -> Color {
match color {
CansiColor::Black | CansiColor::BrightBlack => Color::Black,
CansiColor::Red => Color::Red,
+7 -7
View File
@@ -30,7 +30,7 @@ pub enum BoxLocation {
}
impl BoxLocation {
pub fn get_indexes(self) -> (usize, usize) {
pub const fn get_indexes(self) -> (usize, usize) {
match self {
Self::TopLeft => (0, 0),
Self::TopCentre => (0, 1),
@@ -45,7 +45,7 @@ impl BoxLocation {
}
// Should combine and just return a tuple?
pub fn get_horizontal_constraints(
pub const fn get_horizontal_constraints(
self,
blank_vertical: u16,
text_width: u16,
@@ -68,7 +68,7 @@ impl BoxLocation {
],
}
}
pub fn get_vertical_constraints(
pub const fn get_vertical_constraints(
self,
blank_vertical: u16,
number_lines: u16,
@@ -108,7 +108,7 @@ pub enum Loading {
}
impl Loading {
pub fn next(&self) -> Self {
pub const fn next(&self) -> Self {
match self {
Self::One => Self::Two,
Self::Two => Self::Three,
@@ -143,21 +143,21 @@ impl fmt::Display for Loading {
}
impl SelectablePanel {
pub fn title(self) -> &'static str {
pub const fn title(self) -> &'static str {
match self {
Self::Containers => "Containers",
Self::Logs => "Logs",
Self::Commands => "",
}
}
pub fn next(self) -> Self {
pub const fn next(self) -> Self {
match self {
Self::Containers => Self::Commands,
Self::Commands => Self::Logs,
Self::Logs => Self::Containers,
}
}
pub fn prev(self) -> Self {
pub const fn prev(self) -> Self {
match self {
Self::Containers => Self::Logs,
Self::Commands => Self::Containers,
+1 -1
View File
@@ -72,7 +72,7 @@ pub async fn create_ui(
}
/// Run a loop to draw the gui
async fn run_app<B: Backend>(
async fn run_app<B: Backend + Send>(
terminal: &mut Terminal<B>,
app_data: Arc<Mutex<AppData>>,
sender: Sender<InputMessages>,