From 77182a9a221e47a0d5a1bd52c104ce76fb2f9df9 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Fri, 3 Dec 2021 07:54:56 +0100 Subject: [PATCH] chore(clippy): fix new clippy lints (#3294) --- src/configs/line_break.rs | 8 +------- src/modules/gcloud.rs | 6 +++--- src/modules/git_branch.rs | 9 +++------ src/modules/git_commit.rs | 18 +++--------------- src/modules/golang.rs | 6 +++--- src/modules/helm.rs | 6 +++--- src/modules/julia.rs | 6 +++--- src/modules/status.rs | 6 +++--- 8 files changed, 22 insertions(+), 43 deletions(-) diff --git a/src/configs/line_break.rs b/src/configs/line_break.rs index 3038d5e9..c3d3669f 100644 --- a/src/configs/line_break.rs +++ b/src/configs/line_break.rs @@ -3,13 +3,7 @@ use crate::config::ModuleConfig; use serde::Serialize; use starship_module_config_derive::ModuleConfig; -#[derive(Clone, ModuleConfig, Serialize)] +#[derive(Clone, ModuleConfig, Serialize, Default)] pub struct LineBreakConfig { pub disabled: bool, } - -impl<'a> Default for LineBreakConfig { - fn default() -> Self { - LineBreakConfig { disabled: false } - } -} diff --git a/src/modules/gcloud.rs b/src/modules/gcloud.rs index ac7c7fb1..9e3a0fd7 100644 --- a/src/modules/gcloud.rs +++ b/src/modules/gcloud.rs @@ -44,7 +44,7 @@ impl GcloudContext { .skip(1) .take_while(|line| !line.starts_with('[')) .find(|line| line.starts_with("account"))?; - let account = account_line.splitn(2, '=').nth(1)?.trim(); + let account = account_line.split_once('=')?.1.trim(); let mut segments = account.splitn(2, '@'); Some(( segments.next().map(String::from)?, @@ -60,7 +60,7 @@ impl GcloudContext { .skip(1) .take_while(|line| !line.starts_with('[')) .find(|line| line.starts_with("project"))?; - let project = project_line.splitn(2, '=').nth(1)?.trim(); + let project = project_line.split_once('=')?.1.trim(); Some(project.to_string()) } @@ -72,7 +72,7 @@ impl GcloudContext { .skip(1) .take_while(|line| !line.starts_with('[')) .find(|line| line.starts_with("region"))?; - let region = region_line.splitn(2, '=').nth(1)?.trim(); + let region = region_line.split_once('=')?.1.trim(); Some(region.to_string()) } } diff --git a/src/modules/git_branch.rs b/src/modules/git_branch.rs index 0e90bc14..424098a0 100644 --- a/src/modules/git_branch.rs +++ b/src/modules/git_branch.rs @@ -242,8 +242,8 @@ mod tests { "", format!( "branch: {} {} ", - Color::Blue.bold().paint("1337_hello_world").to_string(), - Color::Red.paint("THE COLORS").to_string() + Color::Blue.bold().paint("1337_hello_world"), + Color::Red.paint("THE COLORS") ), ) } @@ -257,10 +257,7 @@ mod tests { symbol = "git: " style = "green" "#, - format!( - "git: {}", - Color::Green.paint("1337_hello_world").to_string(), - ), + format!("git: {}", Color::Green.paint("1337_hello_world"),), ) } diff --git a/src/modules/git_commit.rs b/src/modules/git_commit.rs index a9c9c2d7..ed6d9f84 100644 --- a/src/modules/git_commit.rs +++ b/src/modules/git_commit.rs @@ -146,10 +146,7 @@ mod tests { let expected = Some(format!( "{} ", - Color::Green - .bold() - .paint(format!("({})", expected_hash)) - .to_string() + Color::Green.bold().paint(format!("({})", expected_hash)) )); assert_eq!(expected, actual); @@ -179,10 +176,7 @@ mod tests { let expected = Some(format!( "{} ", - Color::Green - .bold() - .paint(format!("({})", expected_hash)) - .to_string() + Color::Green.bold().paint(format!("({})", expected_hash)) )); assert_eq!(expected, actual); @@ -226,10 +220,7 @@ mod tests { let expected = Some(format!( "{} ", - Color::Green - .bold() - .paint(format!("({})", expected_hash)) - .to_string() + Color::Green.bold().paint(format!("({})", expected_hash)) )); assert_eq!(expected, actual); @@ -272,7 +263,6 @@ mod tests { Color::Green .bold() .paint(format!("({})", expected_output.trim())) - .to_string() )); assert_eq!(expected, actual); @@ -324,7 +314,6 @@ mod tests { Color::Green .bold() .paint(format!("({})", expected_output.trim())) - .to_string() )); assert_eq!(expected, actual); @@ -396,7 +385,6 @@ mod tests { Color::Green .bold() .paint(format!("({})", expected_output.trim())) - .to_string() )); assert_eq!(expected, actual); diff --git a/src/modules/golang.rs b/src/modules/golang.rs index 7855fc3c..bded55be 100644 --- a/src/modules/golang.rs +++ b/src/modules/golang.rs @@ -62,10 +62,10 @@ fn parse_go_version(go_stdout: &str) -> Option { // go version go1.13.3 linux/amd64 let version = go_stdout - // split into ["", "1.12.4 linux/amd64"] - .splitn(2, "go version go") + // split into ("", "1.12.4 linux/amd64") + .split_once("go version go")? // return "1.12.4 linux/amd64" - .nth(1)? + .1 // split into ["1.12.4", "linux/amd64"] .split_whitespace() // return "1.12.4" diff --git a/src/modules/helm.rs b/src/modules/helm.rs index d012649e..d6181a82 100644 --- a/src/modules/helm.rs +++ b/src/modules/helm.rs @@ -66,10 +66,10 @@ fn parse_helm_version(helm_stdout: &str) -> Option { // `helm version --short --client` output looks like this for Helm 2: // Client: v2.16.9+g8ad7037 let version = helm_stdout - // split into ["v3.1.1","gafe7058"] or ["Client: v3.1.1","gafe7058"] - .splitn(2, '+') + // split into ("v3.1.1","gafe7058") or ("Client: v3.1.1","gafe7058") + .split_once('+') // return "v3.1.1" or "Client: v3.1.1" - .next()? + .map_or(helm_stdout, |x| x.0) // return "v3.1.1" or " v3.1.1" .trim_start_matches("Client: ") // return "v3.1.1" diff --git a/src/modules/julia.rs b/src/modules/julia.rs index d110a0ca..0559b24a 100644 --- a/src/modules/julia.rs +++ b/src/modules/julia.rs @@ -62,10 +62,10 @@ fn parse_julia_version(julia_stdout: &str) -> Option { // julia version 1.4.0 let version = julia_stdout - // split into ["", "1.4.0"] - .splitn(2, "julia version") + // split into ("", "1.4.0") + .split_once("julia version")? // return "1.4.0" - .nth(1)? + .1 .split_whitespace() .next()?; diff --git a/src/modules/status.rs b/src/modules/status.rs index 2f2c1ab0..26c1c8ef 100644 --- a/src/modules/status.rs +++ b/src/modules/status.rs @@ -149,10 +149,10 @@ fn format_exit_code<'a>( .map(|variable| match variable { "status" => Some(Ok(exit_code)), "int" => Some(Ok(exit_code)), - "maybe_int" => Ok(maybe_exit_code_number.as_deref()).transpose(), - "common_meaning" => Ok(common_meaning.as_deref()).transpose(), + "maybe_int" => Ok(maybe_exit_code_number).transpose(), + "common_meaning" => Ok(common_meaning).transpose(), "signal_number" => Ok(signal_number.as_deref()).transpose(), - "signal_name" => Ok(signal_name.as_deref()).transpose(), + "signal_name" => Ok(signal_name).transpose(), "pipestatus" => { let pipestatus = pipestatus.unwrap_or_else(|| { // We might enter this case if pipestatus hasn't