From 6e38683c89eff3a365f2a4affed971a627bf261b Mon Sep 17 00:00:00 2001 From: David Knaack Date: Sat, 5 Nov 2022 12:40:46 +0100 Subject: [PATCH] chore: fix new clippy lints (#4557) --- .github/config-schema.json | 2 +- build.rs | 2 +- src/bug_report.rs | 6 +- src/config.rs | 2 +- src/configs/aws.rs | 2 +- src/configs/starship_root.rs | 2 +- src/configure.rs | 32 ++++----- src/context.rs | 4 +- src/formatter/parser.rs | 16 +++-- src/formatter/string_formatter.rs | 8 +-- src/formatter/version.rs | 2 +- src/init/mod.rs | 6 +- src/logger.rs | 8 +-- src/modules/aws.rs | 6 +- src/modules/azure.rs | 2 +- src/modules/container.rs | 2 +- src/modules/directory.rs | 40 +++++------ src/modules/docker_context.rs | 18 ++--- src/modules/dotnet.rs | 4 +- src/modules/elm.rs | 2 +- src/modules/env_var.rs | 6 +- src/modules/gcloud.rs | 38 +++++----- src/modules/git_branch.rs | 40 +++++------ src/modules/git_commit.rs | 88 +++++++++++------------ src/modules/git_metrics.rs | 20 +++--- src/modules/git_state.rs | 34 ++++----- src/modules/git_status.rs | 108 ++++++++++++++--------------- src/modules/golang.rs | 2 +- src/modules/haskell.rs | 2 +- src/modules/hg_branch.rs | 4 +- src/modules/java.rs | 4 +- src/modules/kubernetes.rs | 2 +- src/modules/lua.rs | 2 +- src/modules/memory_usage.rs | 2 +- src/modules/mod.rs | 4 +- src/modules/nodejs.rs | 4 +- src/modules/openstack.rs | 6 +- src/modules/package.rs | 10 +-- src/modules/pulumi.rs | 12 ++-- src/modules/rlang.rs | 2 +- src/modules/ruby.rs | 2 +- src/modules/rust.rs | 6 +- src/modules/status.rs | 8 +-- src/modules/sudo.rs | 8 +-- src/modules/terraform.rs | 4 +- src/modules/utils/directory_win.rs | 2 +- src/modules/utils/truncate.rs | 2 +- src/print.rs | 8 +-- src/serde_utils.rs | 10 +-- src/test/mod.rs | 26 +++---- src/utils.rs | 16 ++--- 51 files changed, 324 insertions(+), 324 deletions(-) diff --git a/.github/config-schema.json b/.github/config-schema.json index 5a0c7838..92ed18e7 100644 --- a/.github/config-schema.json +++ b/.github/config-schema.json @@ -1613,7 +1613,7 @@ "definitions": { "AwsConfig": { "title": "AWS", - "description": "The `aws` module shows the current AWS region and profile and an expiration timer when using temporary credentials. The output of the module uses the `AWS_REGION`, `AWS_DEFAULT_REGION`, and `AWS_PROFILE` env vars and the `~/.aws/config` and `~/.aws/credentials` files as required.\n\nThe module will display a profile only if its credentials are present in `~/.aws/credentials` or if a `credential_process` or `sso_start_url` are defined in `~/.aws/config`. Alternatively, having any of the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, or `AWS_SESSION_TOKEN` env vars defined will also suffice. If the option `force_display` is set to `true`, all available information will be displayed even if no credentials per the conditions above are detected.\n\nWhen using [aws-vault](https://github.com/99designs/aws-vault) the profile is read from the `AWS_VAULT` env var and the credentials expiration date is read from the `AWS_SESSION_EXPIRATION` env var.\n\nWhen using [awsu](https://github.com/kreuzwerker/awsu) the profile is read from the `AWSU_PROFILE` env var.\n\nWhen using [AWSume](https://awsu.me) the profile is read from the `AWSUME_PROFILE` env var and the credentials expiration date is read from the `AWSUME_EXPIRATION` env var.", + "description": "The `aws` module shows the current AWS region and profile and an expiration timer when using temporary credentials. The output of the module uses the `AWS_REGION`, `AWS_DEFAULT_REGION`, and `AWS_PROFILE` env vars and the `~/.aws/config` and `~/.aws/credentials` files as required.\n\nThe module will display a profile only if its credentials are present in `~/.aws/credentials` or if a `credential_process` or `sso_start_url` are defined in `~/.aws/config`. Alternatively, having any of the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, or `AWS_SESSION_TOKEN` env vars defined will also suffice. If the option `force_display` is set to `true`, all available information will be displayed even if no credentials per the conditions above are detected.\n\nWhen using [aws-vault](https://github.com/99designs/aws-vault) the profile is read from the `AWS_VAULT` env var and the credentials expiration date is read from the `AWS_SESSION_EXPIRATION` env var.\n\nWhen using [awsu](https://github.com/kreuzwerker/awsu) the profile is read from the `AWSU_PROFILE` env var.\n\nWhen using [`AWSume`](https://awsu.me) the profile is read from the `AWSUME_PROFILE` env var and the credentials expiration date is read from the `AWSUME_EXPIRATION` env var.", "type": "object", "properties": { "format": { diff --git a/build.rs b/build.rs index 8e9457e7..8ae49092 100644 --- a/build.rs +++ b/build.rs @@ -33,7 +33,7 @@ fn gen_presets_hook(mut file: &File) -> SdResult<()> { .to_str() .and_then(|v| v.strip_suffix(".toml")) .expect("Failed to process filename"); - presets.push_str(format!("print::Preset(\"{}\"),\n", name).as_str()); + presets.push_str(format!("print::Preset(\"{name}\"),\n").as_str()); match_arms.push_str( format!( r#" diff --git a/src/bug_report.rs b/src/bug_report.rs index 9a89eb6e..8c6ac98f 100644 --- a/src/bug_report.rs +++ b/src/bug_report.rs @@ -26,7 +26,7 @@ pub fn create() { println!("Click this link to create a GitHub issue populated with your configuration:\n"); } - println!("{}", link); + println!("{link}"); } const UNKNOWN_SHELL: &str = ""; @@ -225,11 +225,11 @@ fn get_shell_version(shell: &str) -> String { let time_limit = Duration::from_millis(500); match shell { "powershell" => exec_cmd( - &shell, + shell, &["(Get-Host | Select Version | Format-Table -HideTableHeaders | Out-String).trim()"], time_limit, ), - _ => exec_cmd(&shell, &["--version"], time_limit), + _ => exec_cmd(shell, &["--version"], time_limit), } .map_or_else( || UNKNOWN_VERSION.to_string(), diff --git a/src/config.rs b/src/config.rs index 7a44a311..35cb8656 100644 --- a/src/config.rs +++ b/src/config.rs @@ -141,7 +141,7 @@ impl StarshipConfig { fn config_from_file() -> Option { let file_path = get_config_path()?; - let toml_content = match utils::read_file(&file_path) { + let toml_content = match utils::read_file(file_path) { Ok(content) => { log::trace!("Config file content: \"\n{}\"", &content); Some(content) diff --git a/src/configs/aws.rs b/src/configs/aws.rs index e226af1b..45b06f87 100644 --- a/src/configs/aws.rs +++ b/src/configs/aws.rs @@ -23,7 +23,7 @@ use std::collections::HashMap; /// When using [awsu](https://github.com/kreuzwerker/awsu) the profile /// is read from the `AWSU_PROFILE` env var. /// -/// When using [AWSume](https://awsu.me) the profile +/// When using [`AWSume`](https://awsu.me) the profile /// is read from the `AWSUME_PROFILE` env var and the credentials expiration /// date is read from the `AWSUME_EXPIRATION` env var. pub struct AwsConfig<'a> { diff --git a/src/configs/starship_root.rs b/src/configs/starship_root.rs index 48116eb2..7456c3ca 100644 --- a/src/configs/starship_root.rs +++ b/src/configs/starship_root.rs @@ -118,7 +118,7 @@ impl Default for StarshipRootConfig { Self { schema: "https://starship.rs/config-schema.json".to_string(), format: "$all".to_string(), - right_format: "".to_string(), + right_format: String::new(), continuation_prompt: "[∙](bright-black) ".to_string(), scan_timeout: 30, command_timeout: 500, diff --git a/src/configure.rs b/src/configure.rs index e6f3d790..3cb209f6 100644 --- a/src/configure.rs +++ b/src/configure.rs @@ -24,7 +24,7 @@ pub fn update_configuration(name: &str, value: &str) { match handle_update_configuration(&mut doc, name, value) { Err(e) => { - eprintln!("{}", e); + eprintln!("{e}"); process::exit(1); } _ => write_configuration(&doc), @@ -99,7 +99,7 @@ pub fn print_configuration(use_default: bool, paths: &[String]) { "# $all is shorthand for {}", PROMPT_ORDER .iter() - .map(|module_name| format!("${}", module_name)) + .map(|module_name| format!("${module_name}")) .collect::() ); @@ -110,7 +110,7 @@ pub fn print_configuration(use_default: bool, paths: &[String]) { "# $custom (excluding any modules already listed in `format`) is shorthand for {}", custom_modules .keys() - .map(|module_name| format!("${{custom.{}}}", module_name)) + .map(|module_name| format!("${{custom.{module_name}}}")) .collect::() ); } @@ -124,7 +124,7 @@ pub fn print_configuration(use_default: bool, paths: &[String]) { let string_config = toml::to_string_pretty(&print_config).unwrap(); - println!("{}", string_config); + println!("{string_config}"); } fn extract_toml_paths(mut config: toml::Value, paths: &[String]) -> toml::Value { @@ -186,7 +186,7 @@ pub fn toggle_configuration(name: &str, key: &str) { match handle_toggle_configuration(&mut doc, name, key) { Err(e) => { - eprintln!("{}", e); + eprintln!("{e}"); process::exit(1); } _ => write_configuration(&doc), @@ -202,17 +202,17 @@ fn handle_toggle_configuration(doc: &mut Document, name: &str, key: &str) -> Res let values = table .get_mut(name) - .ok_or_else(|| format!("Given module '{}' not found in config file", name))? + .ok_or_else(|| format!("Given module '{name}' not found in config file"))? .as_table_like_mut() - .ok_or_else(|| format!("Given config entry '{}' is not a module", key))?; + .ok_or_else(|| format!("Given config entry '{key}' is not a module"))?; let old_value = values .get(key) - .ok_or_else(|| format!("Given config key '{}' must exist in config file", key))?; + .ok_or_else(|| format!("Given config key '{key}' must exist in config file"))?; let old = old_value .as_bool() - .ok_or_else(|| format!("Given config key '{}' must be in 'boolean' format", key))?; + .ok_or_else(|| format!("Given config key '{key}' must be in 'boolean' format"))?; let mut new_value = toml_edit::value(!old); // Above code already checks if it is a value (bool) @@ -232,7 +232,7 @@ pub fn get_configuration() -> Value { pub fn get_configuration_edit() -> Document { let file_path = get_config_path(); - let toml_content = match utils::read_file(&file_path) { + let toml_content = match utils::read_file(file_path) { Ok(content) => { log::trace!("Config file content: \"\n{}\"", &content); Some(content) @@ -260,7 +260,7 @@ pub fn write_configuration(doc: &Document) { let config_str = doc.to_string(); - File::create(&config_path) + File::create(config_path) .and_then(|mut file| file.write_all(config_str.as_ref())) .expect("Error writing starship config"); } @@ -291,7 +291,7 @@ pub fn edit_configuration(editor_override: Option<&str>) -> Result<(), Box) -> Vec { .collect() } -pub fn parse(format: &str) -> Result, Error> { - IdentParser::parse(Rule::expression, format).map(|pairs| { - pairs - .take_while(|pair| pair.as_rule() != Rule::EOI) - .map(parse_value) - .collect() - }) +pub fn parse(format: &str) -> Result, Box>> { + IdentParser::parse(Rule::expression, format) + .map(|pairs| { + pairs + .take_while(|pair| pair.as_rule() != Rule::EOI) + .map(parse_value) + .collect() + }) + .map_err(Box::new) } diff --git a/src/formatter/string_formatter.rs b/src/formatter/string_formatter.rs index 2b104acc..229407d3 100644 --- a/src/formatter/string_formatter.rs +++ b/src/formatter/string_formatter.rs @@ -35,14 +35,14 @@ type StyleVariableMapType<'a> = #[derive(Debug, Clone, PartialEq, Eq)] pub enum StringFormatterError { Custom(String), - Parse(PestError), + Parse(Box>), } impl fmt::Display for StringFormatterError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Custom(error) => write!(f, "{}", error), - Self::Parse(error) => write!(f, "{}", error), + Self::Custom(error) => write!(f, "{error}"), + Self::Parse(error) => write!(f, "{error}"), } } } @@ -538,7 +538,7 @@ mod tests { let formatter = StringFormatter::new(FORMAT_STR) .unwrap() - .map(|variable| Some(Ok(format!("${{{}}}", variable)))); + .map(|variable| Some(Ok(format!("${{{variable}}}")))); let result = formatter.parse(None, None).unwrap(); let mut result_iter = result.iter(); match_next!(result_iter, "${env:PWD}", None); diff --git a/src/formatter/version.rs b/src/formatter/version.rs index 400d3f06..dde5fe3e 100644 --- a/src/formatter/version.rs +++ b/src/formatter/version.rs @@ -71,7 +71,7 @@ impl<'a> VersionFormatter<'a> { Ok(formatted) => Some(formatted), Err(error) => { log::warn!("Error formatting `{}` version:\n{}", module_name, error); - Some(format!("v{}", version)) + Some(format!("v{version}")) } } } diff --git a/src/init/mod.rs b/src/init/mod.rs index e8afc970..5cbcab21 100644 --- a/src/init/mod.rs +++ b/src/init/mod.rs @@ -44,11 +44,11 @@ impl StarshipPath { fn sprint_pwsh(&self) -> io::Result { self.str_path() .map(|s| s.replace('\'', "''")) - .map(|s| format!("'{}'", s)) + .map(|s| format!("'{s}'")) } /// Command Shell specific path escaping fn sprint_cmdexe(&self) -> io::Result { - self.str_path().map(|s| format!("\"{}\"", s)) + self.str_path().map(|s| format!("\"{s}\"")) } fn sprint_posix(&self) -> io::Result { // On non-Windows platform, return directly. @@ -229,7 +229,7 @@ pub fn init_main(shell_name: &str) -> io::Result<()> { fn print_script(script: &str, path: &str) { let script = script.replace("::STARSHIP::", path); - print!("{}", script); + print!("{script}"); } /* GENERAL INIT SCRIPT NOTES diff --git a/src/logger.rs b/src/logger.rs index d7ff11f8..6a9b8062 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -29,7 +29,7 @@ impl Default for StarshipLogger { }); fs::create_dir_all(&log_dir) - .unwrap_or_else(|err| panic!("Unable to create log dir {:?}: {:?}!", log_dir, err)); + .unwrap_or_else(|err| panic!("Unable to create log dir {log_dir:?}: {err:?}!")); let session_log_file = log_dir.join(format!( "session_{}.log", env::var("STARSHIP_SESSION_KEY").unwrap_or_default() @@ -96,12 +96,12 @@ impl log::Log for StarshipLogger { }) .unwrap_or_else(|err: std::io::Error| { panic!( - "Unable to open session log file {:?}: {:?}!", - self.log_file_path, err + "Unable to open session log file {:?}: {err:?}!", + self.log_file_path ) }) .lock() - .map(|mut file| writeln!(file, "{}", to_print)) + .map(|mut file| writeln!(file, "{to_print}")) .expect("Log file writer mutex was poisoned!") .expect("Unable to write to the log file!"); } diff --git a/src/modules/aws.rs b/src/modules/aws.rs index 668d4ab2..6c5411b0 100644 --- a/src/modules/aws.rs +++ b/src/modules/aws.rs @@ -66,7 +66,7 @@ fn get_profile_config<'a>( profile: &Option, ) -> Option<&'a ini::Properties> { match profile { - Some(profile) => config.section(Some(format!("profile {}", profile))), + Some(profile) => config.section(Some(format!("profile {profile}"))), None => config.section(Some("default")), } } @@ -701,7 +701,7 @@ aws_secret_access_key=dummy "30m2s", "30m1s", "30m", "29m59s", "29m58s", "29m57s", "29m56s", "29m55s", ]; let possible_values = possible_values.map(|duration| { - let segment_colored = format!("☁️ astronauts (ap-northeast-2) [{}] ", duration); + let segment_colored = format!("☁️ astronauts (ap-northeast-2) [{duration}] "); Some(format!( "on {}", Color::Yellow.bold().paint(segment_colored) @@ -762,7 +762,7 @@ aws_secret_access_key=dummy "on {}", Color::Yellow .bold() - .paint(format!("☁️ astronauts (ap-northeast-2) [{}] ", symbol)) + .paint(format!("☁️ astronauts (ap-northeast-2) [{symbol}] ")) )); assert_eq!(expected, actual); diff --git a/src/modules/azure.rs b/src/modules/azure.rs index 5cb2b52e..31a7ccb6 100644 --- a/src/modules/azure.rs +++ b/src/modules/azure.rs @@ -89,7 +89,7 @@ fn get_config_file_location(context: &Context) -> Option { fn parse_json(json_file_path: &Path) -> Option { let mut buffer: Vec = Vec::new(); - let json_file = File::open(&json_file_path).ok()?; + let json_file = File::open(json_file_path).ok()?; let mut reader = BufReader::new(json_file); reader.read_to_end(&mut buffer).ok()?; diff --git a/src/modules/container.rs b/src/modules/container.rs index 6f550b7e..50f76956 100644 --- a/src/modules/container.rs +++ b/src/modules/container.rs @@ -141,7 +141,7 @@ mod tests { containerenv.push(".containerenv"); let mut file = std::fs::File::create(&containerenv)?; if let Some(name) = name { - file.write_all(format!("image=\"{}\"\n", name).as_bytes())?; + file.write_all(format!("image=\"{name}\"\n").as_bytes())?; } // The output of the module diff --git a/src/modules/directory.rs b/src/modules/directory.rs index 3d2fcd8b..63cce307 100644 --- a/src/modules/directory.rs +++ b/src/modules/directory.rs @@ -101,7 +101,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { String::from(config.truncation_symbol) } } else { - String::from("") + String::new() }; let path_vec = match &repo.and_then(|r| r.workdir.as_ref()) { @@ -118,10 +118,10 @@ pub fn module<'a>(context: &'a Context) -> Option> { let before = before_root_dir(&dir_string, &contracted_path); [prefix + before.as_str(), root.to_string(), after_repo_root] } else { - ["".to_string(), "".to_string(), prefix + dir_string.as_str()] + [String::new(), String::new(), prefix + dir_string.as_str()] } } - _ => ["".to_string(), "".to_string(), prefix + dir_string.as_str()], + _ => [String::new(), String::new(), prefix + dir_string.as_str()], }; let path_vec = if config.use_os_path_sep { @@ -183,7 +183,7 @@ fn remove_extended_path_prefix(path: String) -> String { } // Trim any Windows extended-path prefix from the display path if let Some(unc) = try_trim_prefix(&path, r"\\?\UNC\") { - return format!(r"\\{}", unc); + return format!(r"\\{unc}"); } if let Some(p) = try_trim_prefix(&path, r"\\?\") { return p.to_string(); @@ -328,7 +328,7 @@ fn to_fish_style(pwd_dir_length: usize, dir_string: String, truncated_dir_string .map(|word| -> String { let chars = UnicodeSegmentation::graphemes(word, true).collect::>(); match word { - "" => "".to_string(), + "" => String::new(), _ if chars.len() <= pwd_dir_length => word.to_string(), _ if word.starts_with('.') => chars[..=pwd_dir_length].join(""), _ => chars[..pwd_dir_length].join(""), @@ -501,7 +501,7 @@ mod tests { fn init_repo(path: &Path) -> io::Result<()> { create_command("git")? - .args(&["init"]) + .args(["init"]) .current_dir(path) .output() .map(|_| ()) @@ -689,7 +689,7 @@ mod tests { "{} ", Color::Cyan .bold() - .paint(convert_path_sep(&format!("/foo/bar/{}/path", strange_sub))) + .paint(convert_path_sep(&format!("/foo/bar/{strange_sub}/path"))) )); assert_eq!(expected, actual); @@ -706,7 +706,7 @@ mod tests { "{} ", Color::Cyan .bold() - .paint(convert_path_sep(&format!("~/{}/starship", name))) + .paint(convert_path_sep(&format!("~/{name}/starship"))) )); assert_eq!(expected, actual); @@ -724,7 +724,7 @@ mod tests { "{} ", Color::Cyan .bold() - .paint(convert_path_sep(&format!("{}/engine/schematics", name))) + .paint(convert_path_sep(&format!("{name}/engine/schematics"))) )); assert_eq!(expected, actual); @@ -788,7 +788,7 @@ mod tests { "{} ", Color::Cyan .bold() - .paint(convert_path_sep(&format!("{}/thrusters/rocket", name))) + .paint(convert_path_sep(&format!("{name}/thrusters/rocket"))) )); assert_eq!(expected, actual); @@ -864,7 +864,7 @@ mod tests { "{} ", Color::Cyan .bold() - .paint(convert_path_sep(&format!("{}/rocket", name))) + .paint(convert_path_sep(&format!("{name}/rocket"))) )); assert_eq!(expected, actual); @@ -1117,7 +1117,7 @@ mod tests { let src_dir = repo_dir.join("src"); let symlink_dir = tmp_dir.path().join("rocket-controls-symlink"); let symlink_src_dir = symlink_dir.join("src"); - fs::create_dir_all(&src_dir)?; + fs::create_dir_all(src_dir)?; init_repo(&repo_dir).unwrap(); symlink(&repo_dir, &symlink_dir)?; @@ -1143,7 +1143,7 @@ mod tests { let src_dir = repo_dir.join("src/meters/fuel-gauge"); let symlink_dir = tmp_dir.path().join("rocket-controls-symlink"); let symlink_src_dir = symlink_dir.join("src/meters/fuel-gauge"); - fs::create_dir_all(&src_dir)?; + fs::create_dir_all(src_dir)?; init_repo(&repo_dir).unwrap(); symlink(&repo_dir, &symlink_dir)?; @@ -1172,7 +1172,7 @@ mod tests { .join("above-repo") .join("rocket-controls-symlink"); let symlink_src_dir = symlink_dir.join("src/meters/fuel-gauge"); - fs::create_dir_all(&src_dir)?; + fs::create_dir_all(src_dir)?; init_repo(&repo_dir).unwrap(); symlink(&repo_dir, &symlink_dir)?; @@ -1207,7 +1207,7 @@ mod tests { .join("above-repo") .join("rocket-controls-symlink"); let symlink_src_dir = symlink_dir.join("src/meters/fuel-gauge"); - fs::create_dir_all(&src_dir)?; + fs::create_dir_all(src_dir)?; init_repo(&repo_dir).unwrap(); symlink(&repo_dir, &symlink_dir)?; @@ -1244,7 +1244,7 @@ mod tests { .join("above-repo") .join("rocket-controls-symlink"); let symlink_src_dir = symlink_dir.join("src/meters/fuel-gauge"); - fs::create_dir_all(&src_dir)?; + fs::create_dir_all(src_dir)?; init_repo(&repo_dir).unwrap(); symlink(&repo_dir, &symlink_dir)?; @@ -1289,7 +1289,7 @@ mod tests { .join("above-repo") .join("rocket-controls-symlink"); let symlink_src_dir = symlink_dir.join("src/meters/fuel-gauge"); - fs::create_dir_all(&src_dir)?; + fs::create_dir_all(src_dir)?; init_repo(&repo_dir).unwrap(); symlink(&repo_dir, &symlink_dir)?; @@ -1399,7 +1399,7 @@ mod tests { "{} ", Color::Cyan .bold() - .paint(convert_path_sep(&format!("…/{}/a/subpath", name))) + .paint(convert_path_sep(&format!("…/{name}/a/subpath"))) )); assert_eq!(expected, actual); tmp_dir.close() @@ -1424,7 +1424,7 @@ mod tests { "{} ", Color::Cyan .bold() - .paint(convert_path_sep(&format!("~/{}/a/subpath", name))) + .paint(convert_path_sep(&format!("~/{name}/a/subpath"))) )); assert_eq!(expected, actual); tmp_dir.close() @@ -1794,7 +1794,7 @@ mod tests { .collect(); let expected = Some(format!( "{} ", - Color::Cyan.bold().paint(format!("~/{}/starship", name)) + Color::Cyan.bold().paint(format!("~/{name}/starship")) )); assert_eq!(expected, actual); diff --git a/src/modules/docker_context.rs b/src/modules/docker_context.rs index 8ad5713d..1c30001a 100644 --- a/src/modules/docker_context.rs +++ b/src/modules/docker_context.rs @@ -119,7 +119,7 @@ mod tests { "currentContext": "starship" }); - let mut docker_config = File::create(&cfg_file)?; + let mut docker_config = File::create(cfg_file)?; docker_config.write_all(config_content.to_string().as_bytes())?; docker_config.sync_all()?; @@ -148,7 +148,7 @@ mod tests { "currentContext": "starship" }); - let mut docker_config = File::create(&cfg_file)?; + let mut docker_config = File::create(cfg_file)?; docker_config.write_all(config_content.to_string().as_bytes())?; docker_config.sync_all()?; @@ -177,7 +177,7 @@ mod tests { "currentContext": "starship" }); - let mut docker_config = File::create(&cfg_file)?; + let mut docker_config = File::create(cfg_file)?; docker_config.write_all(config_content.to_string().as_bytes())?; docker_config.sync_all()?; @@ -203,7 +203,7 @@ mod tests { "currentContext": "starship" }); - let mut docker_config = File::create(&cfg_file)?; + let mut docker_config = File::create(cfg_file)?; docker_config.write_all(config_content.to_string().as_bytes())?; docker_config.sync_all()?; @@ -227,7 +227,7 @@ mod tests { "currentContext": "starship" }); - let mut docker_config = File::create(&cfg_file)?; + let mut docker_config = File::create(cfg_file)?; docker_config.write_all(config_content.to_string().as_bytes())?; docker_config.sync_all()?; @@ -253,7 +253,7 @@ mod tests { let config_content = "not valid json"; - let mut docker_config = File::create(&cfg_file)?; + let mut docker_config = File::create(cfg_file)?; docker_config.write_all(config_content.to_string().as_bytes())?; docker_config.sync_all()?; @@ -339,7 +339,7 @@ mod tests { "currentContext": "starship" }); - let mut docker_config = File::create(&cfg_file)?; + let mut docker_config = File::create(cfg_file)?; docker_config.write_all(config_content.to_string().as_bytes())?; docker_config.sync_all()?; @@ -368,7 +368,7 @@ mod tests { "currentContext": "starship" }); - let mut docker_config = File::create(&cfg_file)?; + let mut docker_config = File::create(cfg_file)?; docker_config.write_all(config_content.to_string().as_bytes())?; docker_config.sync_all()?; @@ -400,7 +400,7 @@ mod tests { "currentContext": "starship" }); - let mut docker_config = File::create(&cfg_file)?; + let mut docker_config = File::create(cfg_file)?; docker_config.write_all(config_content.to_string().as_bytes())?; docker_config.sync_all()?; diff --git a/src/modules/dotnet.rs b/src/modules/dotnet.rs index 5902e3cf..e3c59008 100644 --- a/src/modules/dotnet.rs +++ b/src/modules/dotnet.rs @@ -120,7 +120,7 @@ fn get_tfm_from_project_file(path: &Path) -> Option { // unescape and decode the text event using the reader encoding Ok(Event::Text(e)) => { if in_tfm { - return e.unescape().ok().map(|s| s.into_owned()); + return e.unescape().ok().map(std::borrow::Cow::into_owned); } } Ok(Event::Eof) => break, // exits the loop when reaching end of file @@ -558,7 +558,7 @@ mod tests { if is_repo { create_command("git")? - .args(&["init", "--quiet"]) + .args(["init", "--quiet"]) .current_dir(repo_dir.path()) .output()?; } diff --git a/src/modules/elm.rs b/src/modules/elm.rs index 61838058..bfc1ea98 100644 --- a/src/modules/elm.rs +++ b/src/modules/elm.rs @@ -106,7 +106,7 @@ mod tests { fn folder_with_elm_stuff_directory() -> io::Result<()> { let dir = tempfile::tempdir()?; let elmstuff = dir.path().join("elm-stuff"); - fs::create_dir_all(&elmstuff)?; + fs::create_dir_all(elmstuff)?; let actual = ModuleRenderer::new("elm").path(dir.path()).collect(); let expected = Some(format!("via {}", Color::Cyan.bold().paint("🌳 v0.19.1 "))); assert_eq!(expected, actual); diff --git a/src/modules/env_var.rs b/src/modules/env_var.rs index 1e9a09d2..1dbcca13 100644 --- a/src/modules/env_var.rs +++ b/src/modules/env_var.rs @@ -194,7 +194,7 @@ mod test { .collect(); let expected = Some(format!( "with {} ", - style().paint(format!("■ {}", TEST_VAR_VALUE)) + style().paint(format!("■ {TEST_VAR_VALUE}")) )); assert_eq!(expected, actual); @@ -211,7 +211,7 @@ mod test { .collect(); let expected = Some(format!( "with {} ", - style().paint(format!("_{}", TEST_VAR_VALUE)) + style().paint(format!("_{TEST_VAR_VALUE}")) )); assert_eq!(expected, actual); @@ -228,7 +228,7 @@ mod test { .collect(); let expected = Some(format!( "with {} ", - style().paint(format!("{}_", TEST_VAR_VALUE)) + style().paint(format!("{TEST_VAR_VALUE}_")) )); assert_eq!(expected, actual); diff --git a/src/modules/gcloud.rs b/src/modules/gcloud.rs index dd8fab63..786f5129 100644 --- a/src/modules/gcloud.rs +++ b/src/modules/gcloud.rs @@ -56,7 +56,7 @@ fn get_current_config(context: &Context) -> Option<(String, PathBuf)> { let name = get_active_config(context, &config_dir)?; let path = config_dir .join("configurations") - .join(format!("config_{}", name)); + .join(format!("config_{name}")); Some((name, path)) } @@ -154,12 +154,12 @@ mod tests { fn account_set() -> io::Result<()> { let dir = tempfile::tempdir()?; let active_config_path = dir.path().join("active_config"); - let mut active_config_file = File::create(&active_config_path)?; + let mut active_config_file = File::create(active_config_path)?; active_config_file.write_all(b"default")?; create_dir(dir.path().join("configurations"))?; let config_default_path = dir.path().join("configurations").join("config_default"); - let mut config_default_file = File::create(&config_default_path)?; + let mut config_default_file = File::create(config_default_path)?; config_default_file.write_all( b"\ [core] @@ -183,12 +183,12 @@ account = foo@example.com fn account_with_custom_format_set() -> io::Result<()> { let dir = tempfile::tempdir()?; let active_config_path = dir.path().join("active_config"); - let mut active_config_file = File::create(&active_config_path)?; + let mut active_config_file = File::create(active_config_path)?; active_config_file.write_all(b"default")?; create_dir(dir.path().join("configurations"))?; let config_default_path = dir.path().join("configurations").join("config_default"); - let mut config_default_file = File::create(&config_default_path)?; + let mut config_default_file = File::create(config_default_path)?; config_default_file.write_all( b"\ [core] @@ -213,12 +213,12 @@ account = foo@example.com fn account_and_region_set() -> io::Result<()> { let dir = tempfile::tempdir()?; let active_config_path = dir.path().join("active_config"); - let mut active_config_file = File::create(&active_config_path)?; + let mut active_config_file = File::create(active_config_path)?; active_config_file.write_all(b"default")?; create_dir(dir.path().join("configurations"))?; let config_default_path = dir.path().join("configurations").join("config_default"); - let mut config_default_file = File::create(&config_default_path)?; + let mut config_default_file = File::create(config_default_path)?; config_default_file.write_all( b"\ [core] @@ -245,12 +245,12 @@ region = us-central1 fn account_and_region_set_with_alias() -> io::Result<()> { let dir = tempfile::tempdir()?; let active_config_path = dir.path().join("active_config"); - let mut active_config_file = File::create(&active_config_path)?; + let mut active_config_file = File::create(active_config_path)?; active_config_file.write_all(b"default")?; create_dir(dir.path().join("configurations"))?; let config_default_path = dir.path().join("configurations").join("config_default"); - let mut config_default_file = File::create(&config_default_path)?; + let mut config_default_file = File::create(config_default_path)?; config_default_file.write_all( b"\ [core] @@ -281,7 +281,7 @@ region = us-central1 fn active_set() -> io::Result<()> { let dir = tempfile::tempdir()?; let active_config_path = dir.path().join("active_config"); - let mut active_config_file = File::create(&active_config_path)?; + let mut active_config_file = File::create(active_config_path)?; active_config_file.write_all(b"default1")?; let actual = ModuleRenderer::new("gcloud") @@ -301,12 +301,12 @@ region = us-central1 fn project_set() -> io::Result<()> { let dir = tempfile::tempdir()?; let active_config_path = dir.path().join("active_config"); - let mut active_config_file = File::create(&active_config_path)?; + let mut active_config_file = File::create(active_config_path)?; active_config_file.write_all(b"default")?; create_dir(dir.path().join("configurations"))?; let config_default_path = dir.path().join("configurations").join("config_default"); - let mut config_default_file = File::create(&config_default_path)?; + let mut config_default_file = File::create(config_default_path)?; config_default_file.write_all( b"\ [core] @@ -331,12 +331,12 @@ project = abc fn project_set_in_env() -> io::Result<()> { let dir = tempfile::tempdir()?; let active_config_path = dir.path().join("active_config"); - let mut active_config_file = File::create(&active_config_path)?; + let mut active_config_file = File::create(active_config_path)?; active_config_file.write_all(b"default")?; create_dir(dir.path().join("configurations"))?; let config_default_path = dir.path().join("configurations").join("config_default"); - let mut config_default_file = File::create(&config_default_path)?; + let mut config_default_file = File::create(config_default_path)?; config_default_file.write_all( b"\ [core] @@ -365,12 +365,12 @@ project = abc fn project_set_with_alias() -> io::Result<()> { let dir = tempfile::tempdir()?; let active_config_path = dir.path().join("active_config"); - let mut active_config_file = File::create(&active_config_path)?; + let mut active_config_file = File::create(active_config_path)?; active_config_file.write_all(b"default")?; create_dir(dir.path().join("configurations"))?; let config_default_path = dir.path().join("configurations").join("config_default"); - let mut config_default_file = File::create(&config_default_path)?; + let mut config_default_file = File::create(config_default_path)?; config_default_file.write_all( b"\ [core] @@ -413,12 +413,12 @@ project = very-long-project-name fn active_config_manually_overridden() -> io::Result<()> { let dir = tempfile::tempdir()?; let active_config_path = dir.path().join("active_config"); - let mut active_config_file = File::create(&active_config_path)?; + let mut active_config_file = File::create(active_config_path)?; active_config_file.write_all(b"default")?; create_dir(dir.path().join("configurations"))?; let config_default_path = dir.path().join("configurations").join("config_default"); - let mut config_default_file = File::create(&config_default_path)?; + let mut config_default_file = File::create(config_default_path)?; config_default_file.write_all( b"\ [core] @@ -427,7 +427,7 @@ project = default )?; let config_overridden_path = dir.path().join("configurations").join("config_overridden"); - let mut config_overridden_file = File::create(&config_overridden_path)?; + let mut config_overridden_file = File::create(config_overridden_path)?; config_overridden_file.write_all( b"\ [core] diff --git a/src/modules/git_branch.rs b/src/modules/git_branch.rs index f6dfddbc..5d743511 100644 --- a/src/modules/git_branch.rs +++ b/src/modules/git_branch.rs @@ -269,17 +269,17 @@ mod tests { let repo_dir = tempfile::tempdir()?; create_command("git")? - .args(&["init"]) + .args(["init"]) .current_dir(&repo_dir) .output()?; create_command("git")? - .args(&["symbolic-ref", "HEAD", "refs/heads/main"]) + .args(["symbolic-ref", "HEAD", "refs/heads/main"]) .current_dir(&repo_dir) .output()?; let actual = ModuleRenderer::new("git_branch") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = Some(format!( @@ -296,7 +296,7 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; create_command("git")? - .args(&["checkout", "-b", "test_branch"]) + .args(["checkout", "-b", "test_branch"]) .current_dir(repo_dir.path()) .output()?; @@ -305,7 +305,7 @@ mod tests { [git_branch] only_attached = true }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = Some(format!( @@ -324,8 +324,8 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; create_command("git")? - .args(&["checkout", "@~1"]) - .current_dir(&repo_dir.path()) + .args(["checkout", "@~1"]) + .current_dir(repo_dir.path()) .output()?; let actual = ModuleRenderer::new("git_branch") @@ -333,7 +333,7 @@ mod tests { [git_branch] only_attached = true }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = None; @@ -347,17 +347,17 @@ mod tests { let repo_dir = tempfile::tempdir()?; create_command("git")? - .args(&["init", "--bare"]) + .args(["init", "--bare"]) .current_dir(&repo_dir) .output()?; create_command("git")? - .args(&["symbolic-ref", "HEAD", "refs/heads/main"]) + .args(["symbolic-ref", "HEAD", "refs/heads/main"]) .current_dir(&repo_dir) .output()?; let actual = ModuleRenderer::new("git_branch") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = Some(format!( @@ -374,7 +374,7 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; create_command("git")? - .args(&["checkout", "-b", "test_branch"]) + .args(["checkout", "-b", "test_branch"]) .current_dir(repo_dir.path()) .output()?; @@ -383,7 +383,7 @@ mod tests { [git_branch] ignore_branches = ["dummy", "test_branch"] }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = None; @@ -398,23 +398,23 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; create_command("git")? - .args(&["checkout", "-b", "test_branch"]) + .args(["checkout", "-b", "test_branch"]) .current_dir(repo_dir.path()) .output()?; create_command("git")? - .args(&["remote", "add", "--fetch", "remote_repo"]) + .args(["remote", "add", "--fetch", "remote_repo"]) .arg(remote_dir.path()) .current_dir(repo_dir.path()) .output()?; create_command("git")? - .args(&["branch", "--set-upstream-to", "remote_repo/master"]) + .args(["branch", "--set-upstream-to", "remote_repo/master"]) .current_dir(repo_dir.path()) .output()?; let actual = ModuleRenderer::new("git_branch") - .path(&repo_dir.path()) + .path(repo_dir.path()) .config(toml::toml! { [git_branch] format = "$branch(:$remote_name/$remote_branch)" @@ -482,7 +482,7 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; create_command("git")? - .args(&["checkout", "-b", branch_name]) + .args(["checkout", "-b", branch_name]) .current_dir(repo_dir.path()) .output()?; @@ -505,7 +505,7 @@ mod tests { "on {} ", Color::Purple .bold() - .paint(format!("\u{e0a0} {}{}", expected_name, truncation_symbol)), + .paint(format!("\u{e0a0} {expected_name}{truncation_symbol}")), )); assert_eq!(expected, actual); @@ -521,7 +521,7 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; create_command("git")? - .args(&["checkout", "-b", branch_name]) + .args(["checkout", "-b", branch_name]) .current_dir(repo_dir.path()) .output()?; diff --git a/src/modules/git_commit.rs b/src/modules/git_commit.rs index 19e5eb16..d2fdd68a 100644 --- a/src/modules/git_commit.rs +++ b/src/modules/git_commit.rs @@ -89,7 +89,7 @@ mod tests { let repo_dir = tempfile::tempdir()?; let actual = ModuleRenderer::new("git_commit") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = None; @@ -103,8 +103,8 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; let mut git_output = create_command("git")? - .args(&["rev-parse", "HEAD"]) - .current_dir(&repo_dir.path()) + .args(["rev-parse", "HEAD"]) + .current_dir(repo_dir.path()) .output()? .stdout; git_output.truncate(7); @@ -115,12 +115,12 @@ mod tests { [git_commit] only_detached = false }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = Some(format!( "{} ", - Color::Green.bold().paint(format!("({})", expected_hash)) + Color::Green.bold().paint(format!("({expected_hash})")) )); assert_eq!(expected, actual); @@ -132,8 +132,8 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; let mut git_output = create_command("git")? - .args(&["rev-parse", "HEAD"]) - .current_dir(&repo_dir.path()) + .args(["rev-parse", "HEAD"]) + .current_dir(repo_dir.path()) .output()? .stdout; git_output.truncate(14); @@ -145,12 +145,12 @@ mod tests { only_detached = false commit_hash_length = 14 }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = Some(format!( "{} ", - Color::Green.bold().paint(format!("({})", expected_hash)) + Color::Green.bold().paint(format!("({expected_hash})")) )); assert_eq!(expected, actual); @@ -162,7 +162,7 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; let actual = ModuleRenderer::new("git_commit") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = None; @@ -176,25 +176,25 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; create_command("git")? - .args(&["checkout", "@~1"]) - .current_dir(&repo_dir.path()) + .args(["checkout", "@~1"]) + .current_dir(repo_dir.path()) .output()?; let mut git_output = create_command("git")? - .args(&["rev-parse", "HEAD"]) - .current_dir(&repo_dir.path()) + .args(["rev-parse", "HEAD"]) + .current_dir(repo_dir.path()) .output()? .stdout; git_output.truncate(7); let expected_hash = str::from_utf8(&git_output).unwrap(); let actual = ModuleRenderer::new("git_commit") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = Some(format!( "{} ", - Color::Green.bold().paint(format!("({})", expected_hash)) + Color::Green.bold().paint(format!("({expected_hash})")) )); assert_eq!(expected, actual); @@ -206,21 +206,21 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; let mut git_commit = create_command("git")? - .args(&["rev-parse", "HEAD"]) - .current_dir(&repo_dir.path()) + .args(["rev-parse", "HEAD"]) + .current_dir(repo_dir.path()) .output()? .stdout; git_commit.truncate(7); let commit_output = str::from_utf8(&git_commit).unwrap().trim(); let git_tag = create_command("git")? - .args(&["describe", "--tags", "--exact-match", "HEAD"]) - .current_dir(&repo_dir.path()) + .args(["describe", "--tags", "--exact-match", "HEAD"]) + .current_dir(repo_dir.path()) .output()? .stdout; let tag_output = str::from_utf8(&git_tag).unwrap().trim(); - let expected_output = format!("{} {}", commit_output, tag_output); + let expected_output = format!("{commit_output} {tag_output}"); let actual = ModuleRenderer::new("git_commit") .config(toml::toml! { @@ -229,7 +229,7 @@ mod tests { tag_disabled = false tag_symbol = "" }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = Some(format!( @@ -248,31 +248,31 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; create_command("git")? - .args(&["checkout", "@~1"]) - .current_dir(&repo_dir.path()) + .args(["checkout", "@~1"]) + .current_dir(repo_dir.path()) .output()?; create_command("git")? - .args(&["tag", "tagOnDetached", "-m", "Testing tags on detached"]) - .current_dir(&repo_dir.path()) + .args(["tag", "tagOnDetached", "-m", "Testing tags on detached"]) + .current_dir(repo_dir.path()) .output()?; let mut git_commit = create_command("git")? - .args(&["rev-parse", "HEAD"]) - .current_dir(&repo_dir.path()) + .args(["rev-parse", "HEAD"]) + .current_dir(repo_dir.path()) .output()? .stdout; git_commit.truncate(7); let commit_output = str::from_utf8(&git_commit).unwrap().trim(); let git_tag = create_command("git")? - .args(&["describe", "--tags", "--exact-match", "HEAD"]) - .current_dir(&repo_dir.path()) + .args(["describe", "--tags", "--exact-match", "HEAD"]) + .current_dir(repo_dir.path()) .output()? .stdout; let tag_output = str::from_utf8(&git_tag).unwrap().trim(); - let expected_output = format!("{} {}", commit_output, tag_output); + let expected_output = format!("{commit_output} {tag_output}"); let actual = ModuleRenderer::new("git_commit") .config(toml::toml! { @@ -280,7 +280,7 @@ mod tests { tag_disabled = false tag_symbol = " " }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = Some(format!( @@ -301,33 +301,33 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; let mut git_commit = create_command("git")? - .args(&["rev-parse", "HEAD"]) - .current_dir(&repo_dir.path()) + .args(["rev-parse", "HEAD"]) + .current_dir(repo_dir.path()) .output()? .stdout; git_commit.truncate(7); let commit_output = str::from_utf8(&git_commit).unwrap().trim(); create_command("git")? - .args(&["tag", "v2", "-m", "Testing tags v2"]) - .current_dir(&repo_dir.path()) + .args(["tag", "v2", "-m", "Testing tags v2"]) + .current_dir(repo_dir.path()) .output()?; // Wait one second between tags thread::sleep(time::Duration::from_millis(1000)); create_command("git")? - .args(&["tag", "v0", "-m", "Testing tags v0", "HEAD~1"]) - .current_dir(&repo_dir.path()) + .args(["tag", "v0", "-m", "Testing tags v0", "HEAD~1"]) + .current_dir(repo_dir.path()) .output()?; create_command("git")? - .args(&["tag", "v1", "-m", "Testing tags v1"]) - .current_dir(&repo_dir.path()) + .args(["tag", "v1", "-m", "Testing tags v1"]) + .current_dir(repo_dir.path()) .output()?; let git_tag = create_command("git")? - .args(&[ + .args([ "for-each-ref", "--contains", "HEAD", @@ -337,12 +337,12 @@ mod tests { "%(refname:short)", "refs/tags", ]) - .current_dir(&repo_dir.path()) + .current_dir(repo_dir.path()) .output()? .stdout; let tag_output = str::from_utf8(&git_tag).unwrap().trim(); - let expected_output = format!("{} {}", commit_output, tag_output); + let expected_output = format!("{commit_output} {tag_output}"); let actual = ModuleRenderer::new("git_commit") .config(toml::toml! { @@ -351,7 +351,7 @@ mod tests { tag_disabled = false tag_symbol = " " }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = Some(format!( diff --git a/src/modules/git_metrics.rs b/src/modules/git_metrics.rs index 51229a7e..dc32660f 100644 --- a/src/modules/git_metrics.rs +++ b/src/modules/git_metrics.rs @@ -139,7 +139,7 @@ mod tests { let path = repo_dir.path(); let the_file = path.join("the_file"); - let mut the_file = OpenOptions::new().append(true).open(&the_file)?; + let mut the_file = OpenOptions::new().append(true).open(the_file)?; writeln!(the_file, "Added line")?; the_file.sync_all()?; @@ -205,7 +205,7 @@ mod tests { let path = repo_dir.path(); let the_file = path.join("the_file"); - let mut the_file = OpenOptions::new().append(true).open(&the_file)?; + let mut the_file = OpenOptions::new().append(true).open(the_file)?; writeln!(the_file, "Added line")?; the_file.sync_all()?; @@ -268,8 +268,8 @@ mod tests { .write(true) .create(true) .truncate(true) - .open(&file)?; - writeln!(file, "{}", text)?; + .open(file)?; + writeln!(file, "{text}")?; file.sync_all() } @@ -280,7 +280,7 @@ mod tests { // Initialize a new git repo run_git_cmd( - &[ + [ "init", "--quiet", path.to_str().expect("Path was not UTF-8"), @@ -291,12 +291,12 @@ mod tests { // Set local author info run_git_cmd( - &["config", "--local", "user.email", "starship@example.com"], + ["config", "--local", "user.email", "starship@example.com"], Some(path), true, )?; run_git_cmd( - &["config", "--local", "user.name", "starship"], + ["config", "--local", "user.name", "starship"], Some(path), true, )?; @@ -305,7 +305,7 @@ mod tests { // If build environment has `init.defaultBranch` global set // it will default to an unknown branch, so need to make & change branch run_git_cmd( - &["checkout", "-b", "master"], + ["checkout", "-b", "master"], Some(path), // command expected to fail if already on the expected branch false, @@ -313,9 +313,9 @@ mod tests { // Write a file on master and commit it write_file(file, "First Line\nSecond Line\nThird Line")?; - run_git_cmd(&["add", "the_file"], Some(path), true)?; + run_git_cmd(["add", "the_file"], Some(path), true)?; run_git_cmd( - &["commit", "--message", "Commit A", "--no-gpg-sign"], + ["commit", "--message", "Commit A", "--no-gpg-sign"], Some(path), true, )?; diff --git a/src/modules/git_state.rs b/src/modules/git_state.rs index 4b6cfc6d..04fd4cfc 100644 --- a/src/modules/git_state.rs +++ b/src/modules/git_state.rs @@ -137,7 +137,7 @@ fn describe_rebase<'a>(repo: &'a Repo, rebase_config: &'a str) -> StateDescripti }; let (current, total) = if let Some((c, t)) = progress { - (Some(format!("{}", c)), Some(format!("{}", t))) + (Some(format!("{c}")), Some(format!("{t}"))) } else { (None, None) }; @@ -186,7 +186,7 @@ mod tests { let repo_dir = create_repo_with_conflict()?; let path = repo_dir.path(); - run_git_cmd(&["rebase", "other-branch"], Some(path), false)?; + run_git_cmd(["rebase", "other-branch"], Some(path), false)?; let actual = ModuleRenderer::new("git_state").path(path).collect(); @@ -201,7 +201,7 @@ mod tests { let repo_dir = create_repo_with_conflict()?; let path = repo_dir.path(); - run_git_cmd(&["merge", "other-branch"], Some(path), false)?; + run_git_cmd(["merge", "other-branch"], Some(path), false)?; let actual = ModuleRenderer::new("git_state").path(path).collect(); @@ -216,7 +216,7 @@ mod tests { let repo_dir = create_repo_with_conflict()?; let path = repo_dir.path(); - run_git_cmd(&["cherry-pick", "other-branch"], Some(path), false)?; + run_git_cmd(["cherry-pick", "other-branch"], Some(path), false)?; let actual = ModuleRenderer::new("git_state").path(path).collect(); @@ -234,7 +234,7 @@ mod tests { let repo_dir = create_repo_with_conflict()?; let path = repo_dir.path(); - run_git_cmd(&["bisect", "start"], Some(path), false)?; + run_git_cmd(["bisect", "start"], Some(path), false)?; let actual = ModuleRenderer::new("git_state").path(path).collect(); @@ -249,7 +249,7 @@ mod tests { let repo_dir = create_repo_with_conflict()?; let path = repo_dir.path(); - run_git_cmd(&["revert", "--no-commit", "HEAD~1"], Some(path), false)?; + run_git_cmd(["revert", "--no-commit", "HEAD~1"], Some(path), false)?; let actual = ModuleRenderer::new("git_state").path(path).collect(); @@ -295,12 +295,12 @@ mod tests { .create(true) .truncate(true) .open(&conflicted_file)?; - write!(file, "{}", text) + write!(file, "{text}") }; // Initialize a new git repo run_git_cmd( - &[ + [ "init", "--quiet", path.to_str().expect("Path was not UTF-8"), @@ -311,12 +311,12 @@ mod tests { // Set local author info run_git_cmd( - &["config", "--local", "user.email", "starship@example.com"], + ["config", "--local", "user.email", "starship@example.com"], Some(path), true, )?; run_git_cmd( - &["config", "--local", "user.name", "starship"], + ["config", "--local", "user.name", "starship"], Some(path), true, )?; @@ -325,7 +325,7 @@ mod tests { // If build environment has `init.defaultBranch` global set // it will default to an unknown branch, so need to make & change branch run_git_cmd( - &["checkout", "-b", "master"], + ["checkout", "-b", "master"], Some(path), // command expected to fail if already on the expected branch false, @@ -333,27 +333,27 @@ mod tests { // Write a file on master and commit it write_file("Version A")?; - run_git_cmd(&["add", "the_file"], Some(path), true)?; + run_git_cmd(["add", "the_file"], Some(path), true)?; run_git_cmd( - &["commit", "--message", "Commit A", "--no-gpg-sign"], + ["commit", "--message", "Commit A", "--no-gpg-sign"], Some(path), true, )?; // Switch to another branch, and commit a change to the file - run_git_cmd(&["checkout", "-b", "other-branch"], Some(path), true)?; + run_git_cmd(["checkout", "-b", "other-branch"], Some(path), true)?; write_file("Version B")?; run_git_cmd( - &["commit", "--all", "--message", "Commit B", "--no-gpg-sign"], + ["commit", "--all", "--message", "Commit B", "--no-gpg-sign"], Some(path), true, )?; // Switch back to master, and commit a third change to the file - run_git_cmd(&["checkout", "master"], Some(path), true)?; + run_git_cmd(["checkout", "master"], Some(path), true)?; write_file("Version C")?; run_git_cmd( - &["commit", "--all", "--message", "Commit C", "--no-gpg-sign"], + ["commit", "--all", "--message", "Commit C", "--no-gpg-sign"], Some(path), true, )?; diff --git a/src/modules/git_status.rs b/src/modules/git_status.rs index ca6cedcd..92aeb770 100644 --- a/src/modules/git_status.rs +++ b/src/modules/git_status.rs @@ -437,7 +437,7 @@ fn git_status_wsl(context: &Context, conf: &GitStatusConfig) -> Option { crate::config::get_config_path().unwrap_or_else(|| "/dev/null".to_string()), ) .env("WSLENV", wslenv) - .args(&["module", "git_status", "--path", winpath]); + .args(["module", "git_status", "--path", winpath]); c }) .and_then(|mut c| c.output()) @@ -483,7 +483,7 @@ mod tests { fn format_output(symbols: &str) -> Option { Some(format!( "{} ", - Color::Red.bold().paint(format!("[{}]", symbols)) + Color::Red.bold().paint(format!("[{symbols}]")) )) } @@ -542,7 +542,7 @@ mod tests { ahead(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("⇡"); @@ -562,7 +562,7 @@ mod tests { [git_status] ahead="⇡$count" }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("⇡1"); @@ -577,7 +577,7 @@ mod tests { diverge(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("⇕"); @@ -596,7 +596,7 @@ mod tests { [git_status] diverged=r"⇕⇡$ahead_count⇣$behind_count" }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("⇕⇡1⇣1"); @@ -613,7 +613,7 @@ mod tests { [git_status] up_to_date="✓" }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("✓"); @@ -628,7 +628,7 @@ mod tests { create_conflict(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("="); @@ -647,7 +647,7 @@ mod tests { [git_status] conflicted = "=$count" }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("=1"); @@ -662,7 +662,7 @@ mod tests { create_untracked(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("?"); @@ -681,7 +681,7 @@ mod tests { [git_status] untracked = "?$count" }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("?1"); @@ -696,12 +696,12 @@ mod tests { create_untracked(repo_dir.path())?; create_command("git")? - .args(&["config", "status.showUntrackedFiles", "no"]) + .args(["config", "status.showUntrackedFiles", "no"]) .current_dir(repo_dir.path()) .output()?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = None; @@ -716,12 +716,12 @@ mod tests { create_stash(repo_dir.path())?; create_command("git")? - .args(&["reset", "--hard", "HEAD"]) + .args(["reset", "--hard", "HEAD"]) .current_dir(repo_dir.path()) .output()?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("$"); @@ -736,7 +736,7 @@ mod tests { create_stash(repo_dir.path())?; create_command("git")? - .args(&["reset", "--hard", "HEAD"]) + .args(["reset", "--hard", "HEAD"]) .current_dir(repo_dir.path()) .output()?; @@ -745,7 +745,7 @@ mod tests { [git_status] stashed = r"\$$count" }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("$1"); @@ -760,7 +760,7 @@ mod tests { create_modified(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("!"); @@ -779,7 +779,7 @@ mod tests { [git_status] modified = "!$count" }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("!1"); @@ -794,7 +794,7 @@ mod tests { create_added(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("!"); @@ -809,7 +809,7 @@ mod tests { create_staged(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("+"); @@ -828,7 +828,7 @@ mod tests { [git_status] staged = "+[$count](green)" }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = Some(format!( "{} ", @@ -850,7 +850,7 @@ mod tests { create_staged_and_modified(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("!+"); @@ -865,7 +865,7 @@ mod tests { create_renamed(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("»"); @@ -884,7 +884,7 @@ mod tests { [git_status] renamed = "»$count" }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("»1"); @@ -899,7 +899,7 @@ mod tests { create_renamed_and_modified(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("»!"); @@ -914,7 +914,7 @@ mod tests { create_deleted(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("✘"); @@ -933,7 +933,7 @@ mod tests { [git_status] deleted = "✘$count" }) - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("✘1"); @@ -948,7 +948,7 @@ mod tests { create_staged_and_ignored(repo_dir.path())?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("+"); @@ -962,7 +962,7 @@ mod tests { let repo_dir = fixture_repo(FixtureProvider::Git)?; create_command("git")? - .args(&[ + .args([ OsStr::new("config"), OsStr::new("core.worktree"), worktree_dir.path().as_os_str(), @@ -973,7 +973,7 @@ mod tests { File::create(worktree_dir.path().join("test_file"))?.sync_all()?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .collect(); let expected = format_output("✘?"); @@ -992,19 +992,19 @@ mod tests { File::create(repo_dir.path().join("a"))?.sync_all()?; File::create(repo_dir.path().join("b"))?.sync_all()?; create_command("git")? - .args(&["add", "--all"]) - .current_dir(&repo_dir.path()) + .args(["add", "--all"]) + .current_dir(repo_dir.path()) .output()?; create_command("git")? - .args(&["commit", "-m", "add new files", "--no-gpg-sign"]) - .current_dir(&repo_dir.path()) + .args(["commit", "-m", "add new files", "--no-gpg-sign"]) + .current_dir(repo_dir.path()) .output()?; fs::remove_file(repo_dir.path().join("a"))?; fs::rename(repo_dir.path().join("b"), repo_dir.path().join("c"))?; let actual = ModuleRenderer::new("git_status") - .path(&repo_dir.path()) + .path(repo_dir.path()) .config(toml::toml! { [git_status] ahead = "A" @@ -1024,8 +1024,8 @@ mod tests { File::create(repo_dir.join("readme.md"))?.sync_all()?; create_command("git")? - .args(&["commit", "-am", "Update readme", "--no-gpg-sign"]) - .current_dir(&repo_dir) + .args(["commit", "-am", "Update readme", "--no-gpg-sign"]) + .current_dir(repo_dir) .output()?; Ok(()) @@ -1033,7 +1033,7 @@ mod tests { fn behind(repo_dir: &Path) -> io::Result<()> { create_command("git")? - .args(&["reset", "--hard", "HEAD^"]) + .args(["reset", "--hard", "HEAD^"]) .current_dir(repo_dir) .output()?; @@ -1042,14 +1042,14 @@ mod tests { fn diverge(repo_dir: &Path) -> io::Result<()> { create_command("git")? - .args(&["reset", "--hard", "HEAD^"]) + .args(["reset", "--hard", "HEAD^"]) .current_dir(repo_dir) .output()?; fs::write(repo_dir.join("Cargo.toml"), " ")?; create_command("git")? - .args(&["commit", "-am", "Update readme", "--no-gpg-sign"]) + .args(["commit", "-am", "Update readme", "--no-gpg-sign"]) .current_dir(repo_dir) .output()?; @@ -1058,24 +1058,24 @@ mod tests { fn create_conflict(repo_dir: &Path) -> io::Result<()> { create_command("git")? - .args(&["reset", "--hard", "HEAD^"]) + .args(["reset", "--hard", "HEAD^"]) .current_dir(repo_dir) .output()?; fs::write(repo_dir.join("readme.md"), "# goodbye")?; create_command("git")? - .args(&["add", "."]) + .args(["add", "."]) .current_dir(repo_dir) .output()?; create_command("git")? - .args(&["commit", "-m", "Change readme", "--no-gpg-sign"]) + .args(["commit", "-m", "Change readme", "--no-gpg-sign"]) .current_dir(repo_dir) .output()?; create_command("git")? - .args(&["pull", "--rebase"]) + .args(["pull", "--rebase"]) .current_dir(repo_dir) .output()?; @@ -1086,7 +1086,7 @@ mod tests { File::create(repo_dir.join("readme.md"))?.sync_all()?; create_command("git")? - .args(&["stash", "--all"]) + .args(["stash", "--all"]) .current_dir(repo_dir) .output()?; @@ -1103,7 +1103,7 @@ mod tests { File::create(repo_dir.join("license"))?.sync_all()?; create_command("git")? - .args(&["add", "-A", "-N"]) + .args(["add", "-A", "-N"]) .current_dir(repo_dir) .output()?; @@ -1120,7 +1120,7 @@ mod tests { File::create(repo_dir.join("license"))?.sync_all()?; create_command("git")? - .args(&["add", "."]) + .args(["add", "."]) .current_dir(repo_dir) .output()?; @@ -1132,7 +1132,7 @@ mod tests { file.sync_all()?; create_command("git")? - .args(&["add", "."]) + .args(["add", "."]) .current_dir(repo_dir) .output()?; @@ -1144,12 +1144,12 @@ mod tests { fn create_renamed(repo_dir: &Path) -> io::Result<()> { create_command("git")? - .args(&["mv", "readme.md", "readme.md.bak"]) + .args(["mv", "readme.md", "readme.md.bak"]) .current_dir(repo_dir) .output()?; create_command("git")? - .args(&["add", "-A"]) + .args(["add", "-A"]) .current_dir(repo_dir) .output()?; @@ -1158,12 +1158,12 @@ mod tests { fn create_renamed_and_modified(repo_dir: &Path) -> io::Result<()> { create_command("git")? - .args(&["mv", "readme.md", "readme.md.bak"]) + .args(["mv", "readme.md", "readme.md.bak"]) .current_dir(repo_dir) .output()?; create_command("git")? - .args(&["add", "-A"]) + .args(["add", "-A"]) .current_dir(repo_dir) .output()?; @@ -1186,7 +1186,7 @@ mod tests { file.sync_all()?; create_command("git")? - .args(&["add", ".gitignore"]) + .args(["add", ".gitignore"]) .current_dir(repo_dir) .output()?; diff --git a/src/modules/golang.rs b/src/modules/golang.rs index 12ed6dbe..52c65a67 100644 --- a/src/modules/golang.rs +++ b/src/modules/golang.rs @@ -145,7 +145,7 @@ mod tests { fn folder_with_godeps() -> io::Result<()> { let dir = tempfile::tempdir()?; let godeps = dir.path().join("Godeps"); - fs::create_dir_all(&godeps)?; + fs::create_dir_all(godeps)?; let actual = ModuleRenderer::new("golang").path(dir.path()).collect(); diff --git a/src/modules/haskell.rs b/src/modules/haskell.rs index 957290b0..52f425ec 100644 --- a/src/modules/haskell.rs +++ b/src/modules/haskell.rs @@ -125,7 +125,7 @@ mod tests { let actual = ModuleRenderer::new("haskell").path(dir.path()).collect(); let expected = Some(format!( "via {}", - Color::Purple.bold().paint(format!("λ {} ", resolver)) + Color::Purple.bold().paint(format!("λ {resolver} ")) )); assert_eq!(expected, actual); dir.close()?; diff --git a/src/modules/hg_branch.rs b/src/modules/hg_branch.rs index 365983e4..0ec4873a 100644 --- a/src/modules/hg_branch.rs +++ b/src/modules/hg_branch.rs @@ -154,7 +154,7 @@ mod tests { // Create a fake corrupted mercurial repo. let hgdir = tempdir.path().join(".hg"); fs::create_dir(&hgdir)?; - fs::write(&hgdir.join("requires"), "fake-corrupted-repo")?; + fs::write(hgdir.join("requires"), "fake-corrupted-repo")?; expect_hg_branch_with_config( tempdir.path(), @@ -336,7 +336,7 @@ mod tests { fn run_hg(args: &[&str], repo_dir: &Path) -> io::Result<()> { create_command("hg")? .args(args) - .current_dir(&repo_dir) + .current_dir(repo_dir) .output()?; Ok(()) } diff --git a/src/modules/java.rs b/src/modules/java.rs index e6f4162d..da96bfd0 100644 --- a/src/modules/java.rs +++ b/src/modules/java.rs @@ -72,7 +72,7 @@ fn get_java_version(context: &Context) -> Option { }) .unwrap_or_else(|| String::from("java")); - let output = context.exec_cmd(&java_command, &["-Xinternalversion"])?; + let output = context.exec_cmd(java_command, &["-Xinternalversion"])?; let java_version_string = get_command_string_output(output); parse_java_version(&java_version_string) @@ -183,7 +183,7 @@ mod tests { File::create(dir.path().join("Main.java"))?.sync_all()?; let actual = ModuleRenderer::new("java").cmd("java -Xinternalversion", Some(CommandOutput { stdout: "OpenJDK 64-Bit Server VM (16+14) for bsd-aarch64 JRE (16+14), built on Jan 17 2021 07:19:47 by \"brew\" with clang Apple LLVM 12.0.0 (clang-1200.0.32.28)\n".to_owned(), - stderr: "".to_owned() + stderr: String::new() })).path(dir.path()).collect(); let expected = Some(format!("via {}", Color::Red.dimmed().paint("☕ v16 "))); assert_eq!(expected, actual); diff --git a/src/modules/kubernetes.rs b/src/modules/kubernetes.rs index 29deeb38..e0aee2bc 100644 --- a/src/modules/kubernetes.rs +++ b/src/modules/kubernetes.rs @@ -100,7 +100,7 @@ fn get_alias<'a>( } return aliases.iter().find_map(|(k, v)| { - let re = regex::Regex::new(&format!("^{}$", k)).ok()?; + let re = regex::Regex::new(&format!("^{k}$")).ok()?; let replaced = re.replace(alias_candidate, *v); match replaced { Cow::Owned(replaced) => Some(Cow::Owned(replaced)), diff --git a/src/modules/lua.rs b/src/modules/lua.rs index 761dcf9b..3d6fbc97 100644 --- a/src/modules/lua.rs +++ b/src/modules/lua.rs @@ -118,7 +118,7 @@ mod tests { fn folder_with_lua_folder() -> io::Result<()> { let dir = tempfile::tempdir()?; let lua_dir = dir.path().join("lua"); - fs::create_dir_all(&lua_dir)?; + fs::create_dir_all(lua_dir)?; let actual = ModuleRenderer::new("lua").path(dir.path()).collect(); let expected = Some(format!("via {}", Color::Blue.bold().paint("🌙 v5.4.0 "))); diff --git a/src/modules/memory_usage.rs b/src/modules/memory_usage.rs index 56789ae9..5e6a0d3e 100644 --- a/src/modules/memory_usage.rs +++ b/src/modules/memory_usage.rs @@ -95,7 +95,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { }) .map(|variable| match variable { "ram" => Some(Ok(format_usage_total(memory.total, memory.free))), - "ram_pct" => Some(Ok(format!("{:.0}%", used_pct))), + "ram_pct" => Some(Ok(format!("{used_pct:.0}%"))), "swap" => Some(Ok(format_usage_total( swap.as_ref()?.total, swap.as_ref()?.free, diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 06a4fe04..99952bd6 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -182,7 +182,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option> { custom::module(custom.strip_prefix("custom.").unwrap(), context) } _ => { - eprintln!("Error: Unknown module {}. Use starship module --list to list out all supported modules.", module); + eprintln!("Error: Unknown module {module}. Use starship module --list to list out all supported modules."); None } } @@ -296,7 +296,7 @@ mod test { #[test] fn all_modules_have_description() { for module in ALL_MODULES { - println!("Checking if {:?} has a description", module); + println!("Checking if {module:?} has a description"); assert_ne!(description(module), ""); } } diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs index a8c0baac..635cfb3f 100644 --- a/src/modules/nodejs.rs +++ b/src/modules/nodejs.rs @@ -147,7 +147,7 @@ mod tests { let dir = tempfile::tempdir()?; File::create(dir.path().join("package.json"))?.sync_all()?; let esy_lock = dir.path().join("esy.lock"); - fs::create_dir_all(&esy_lock)?; + fs::create_dir_all(esy_lock)?; let actual = ModuleRenderer::new("nodejs").path(dir.path()).collect(); let expected = None; @@ -225,7 +225,7 @@ mod tests { fn folder_with_node_modules() -> io::Result<()> { let dir = tempfile::tempdir()?; let node_modules = dir.path().join("node_modules"); - fs::create_dir_all(&node_modules)?; + fs::create_dir_all(node_modules)?; let actual = ModuleRenderer::new("nodejs").path(dir.path()).collect(); let expected = Some(format!("via {}", Color::Green.bold().paint(" v12.0.0 "))); diff --git a/src/modules/openstack.rs b/src/modules/openstack.rs index 253f6917..35c488ba 100644 --- a/src/modules/openstack.rs +++ b/src/modules/openstack.rs @@ -94,7 +94,7 @@ mod tests { fn parse_valid_config() -> io::Result<()> { let dir = tempfile::tempdir()?; let config_path = dir.path().join("clouds.yaml"); - let mut file = File::create(&config_path)?; + let mut file = File::create(config_path)?; file.write_all( b"--- clouds: @@ -126,7 +126,7 @@ clouds: fn parse_broken_config() -> io::Result<()> { let dir = tempfile::tempdir()?; let config_path = dir.path().join("clouds.yaml"); - let mut file = File::create(&config_path)?; + let mut file = File::create(config_path)?; file.write_all( b"--- dummy_yaml @@ -149,7 +149,7 @@ dummy_yaml fn dont_crash_on_empty_config() -> io::Result<()> { let dir = tempfile::tempdir()?; let config_path = dir.path().join("clouds.yaml"); - let mut file = File::create(&config_path)?; + let mut file = File::create(config_path)?; file.write_all(b"")?; drop(file); let actual = ModuleRenderer::new("openstack") diff --git a/src/modules/package.rs b/src/modules/package.rs index 03e787bf..7a2e88a9 100644 --- a/src/modules/package.rs +++ b/src/modules/package.rs @@ -168,7 +168,7 @@ fn get_maven_version(context: &Context, config: &PackageConfig) -> Option { - let ver = t.unescape().ok().map(|s| s.into_owned()); + let ver = t.unescape().ok().map(std::borrow::Cow::into_owned); return match ver { // Ignore version which is just a property reference Some(ref v) if !v.starts_with('$') => format_version(v, config.version_format), @@ -227,12 +227,12 @@ fn get_cargo_version(context: &Context, config: &PackageConfig) -> Option Option { /// Pulumi has no CLI option that is fast enough to get this for us, but finding /// the location is simple. We get it ourselves. fn stack_name(project_file: &Path, context: &Context) -> Option { - let mut file = File::open(&project_file).ok()?; + let mut file = File::open(project_file).ok()?; let mut contents = String::new(); file.read_to_string(&mut contents).ok()?; @@ -169,7 +169,7 @@ fn get_pulumi_workspace(context: &Context, name: &str, project_file: &Path) -> O hasher.update(project_file.to_str()?.as_bytes()); crate::utils::encode_to_hex(&hasher.finalize()) }; - let unique_file_name = format!("{}-{}-workspace.json", name, project_file); + let unique_file_name = format!("{name}-{project_file}-workspace.json"); let mut path = pulumi_home_dir(context)?; path.push("workspaces"); path.push(unique_file_name); @@ -287,7 +287,7 @@ mod tests { let workspace_path = root.join(".pulumi").join("workspaces"); std::fs::create_dir_all(&workspace_path)?; let workspace_path = &workspace_path.join("starship-test-workspace.json"); - let mut workspace = File::create(&workspace_path)?; + let mut workspace = File::create(workspace_path)?; serde_json::to_writer_pretty( &mut workspace, &serde_json::json!( @@ -301,7 +301,7 @@ mod tests { let credential_path = root.join(".pulumi"); std::fs::create_dir_all(&credential_path)?; let credential_path = &credential_path.join("credentials.json"); - let mut credential = File::create(&credential_path)?; + let mut credential = File::create(credential_path)?; serde_json::to_writer_pretty( &mut credential, &serde_json::json!( @@ -354,7 +354,7 @@ mod tests { let workspace_path = root.join(".pulumi").join("workspaces"); std::fs::create_dir_all(&workspace_path)?; let workspace_path = &workspace_path.join("starship-test-workspace.json"); - let mut workspace = File::create(&workspace_path)?; + let mut workspace = File::create(workspace_path)?; serde_json::to_writer_pretty( &mut workspace, &serde_json::json!( @@ -368,7 +368,7 @@ mod tests { let credential_path = root.join(".pulumi"); std::fs::create_dir_all(&credential_path)?; let credential_path = &credential_path.join("starship-test-credential.json"); - let mut credential = File::create(&credential_path)?; + let mut credential = File::create(credential_path)?; serde_json::to_writer_pretty( &mut credential, &serde_json::json!( diff --git a/src/modules/rlang.rs b/src/modules/rlang.rs index e0e14e15..a3902497 100644 --- a/src/modules/rlang.rs +++ b/src/modules/rlang.rs @@ -144,7 +144,7 @@ https://www.gnu.org/licenses/."#; fn folder_with_rproj_user_folder() -> io::Result<()> { let dir = tempfile::tempdir()?; let rprofile = dir.path().join(".Rproj.user"); - fs::create_dir_all(&rprofile)?; + fs::create_dir_all(rprofile)?; check_r_render(&dir); dir.close() } diff --git a/src/modules/ruby.rs b/src/modules/ruby.rs index e34e8948..498fefc3 100644 --- a/src/modules/ruby.rs +++ b/src/modules/ruby.rs @@ -76,7 +76,7 @@ fn format_ruby_version(ruby_version: &str, version_format: &str) -> Option Some(formatted), Err(error) => { log::warn!("Error formatting `ruby` version:\n{}", error); - Some(format!("v{}", version)) + Some(format!("v{version}")) } } } diff --git a/src/modules/rust.rs b/src/modules/rust.rs index 35e38d9a..b494761f 100644 --- a/src/modules/rust.rs +++ b/src/modules/rust.rs @@ -114,7 +114,7 @@ impl RustToolingEnvironmentInfo { // Depending on the source of the toolchain override, it might not have been a full toolchain name ("stable" or "nightly"). log::trace!("Running rustup {toolchain} rustc --version"); create_command("rustup").map(|mut cmd| { - cmd.args(&["run", toolchain, "rustc", "--version"]); + cmd.args(["run", toolchain, "rustc", "--version"]); cmd }) }) @@ -138,9 +138,7 @@ impl RustToolingEnvironmentInfo { .get_or_init(|| { let Output { status, stdout, .. } = create_command("rustc") .and_then(|mut cmd| { - cmd.args(&["-Vv"]) - .current_dir(&context.current_dir) - .output() + cmd.args(["-Vv"]).current_dir(&context.current_dir).output() }) .ok()?; if !status.success() { diff --git a/src/modules/status.rs b/src/modules/status.rs index d00cf19f..8d17ea40 100644 --- a/src/modules/status.rs +++ b/src/modules/status.rs @@ -79,7 +79,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { }) .flatten() .collect::(), - _ => "".to_string(), + _ => String::new(), }; let main_format = match pipestatus_status { @@ -114,7 +114,7 @@ fn format_exit_code<'a>( } }; - let hex_status = format!("0x{:X}", exit_code_int); + let hex_status = format!("0x{exit_code_int:X}"); let common_meaning = status_common_meaning(exit_code_int); @@ -323,7 +323,7 @@ mod tests { for status in &exit_values { let expected = Some(format!( "{} ", - Color::Red.bold().paint(format!("❌{}", status)) + Color::Red.bold().paint(format!("❌{status}")) )); let actual = ModuleRenderer::new("status") .config(toml::toml! { @@ -345,7 +345,7 @@ mod tests { for (exit_value, string_value) in exit_values.iter().zip(string_values) { let expected = Some(format!( "{} ", - Color::Red.bold().paint(format!("❌{}", string_value)) + Color::Red.bold().paint(format!("❌{string_value}")) )); let actual = ModuleRenderer::new("status") .config(toml::toml! { diff --git a/src/modules/sudo.rs b/src/modules/sudo.rs index 4dd0b526..d1c080f0 100644 --- a/src/modules/sudo.rs +++ b/src/modules/sudo.rs @@ -74,8 +74,8 @@ mod tests { .cmd( "sudo -n true", Some(CommandOutput { - stdout: "".to_owned(), - stderr: "".to_owned(), + stdout: String::new(), + stderr: String::new(), }), ) .config(toml::toml! { @@ -96,8 +96,8 @@ mod tests { .cmd( "sudo -n true", Some(CommandOutput { - stdout: "".to_owned(), - stderr: "".to_owned(), + stdout: String::new(), + stderr: String::new(), }), ) .config(toml::toml! { diff --git a/src/modules/terraform.rs b/src/modules/terraform.rs index 3742e48e..cb074593 100644 --- a/src/modules/terraform.rs +++ b/src/modules/terraform.rs @@ -144,7 +144,7 @@ is 0.12.14. You can update by downloading from www.terraform.io/downloads.html fn folder_with_dotterraform_with_version_no_environment() -> io::Result<()> { let dir = tempfile::tempdir()?; let tf_dir = dir.path().join(".terraform"); - fs::create_dir(&tf_dir)?; + fs::create_dir(tf_dir)?; let actual = ModuleRenderer::new("terraform") .path(dir.path()) @@ -259,7 +259,7 @@ is 0.12.14. You can update by downloading from www.terraform.io/downloads.html fn folder_with_dotterraform_no_environment() -> io::Result<()> { let dir = tempfile::tempdir()?; let tf_dir = dir.path().join(".terraform"); - fs::create_dir(&tf_dir)?; + fs::create_dir(tf_dir)?; let actual = ModuleRenderer::new("terraform").path(dir.path()).collect(); let expected = Some(format!( diff --git a/src/modules/utils/directory_win.rs b/src/modules/utils/directory_win.rs index 38e1b531..61760c8a 100644 --- a/src/modules/utils/directory_win.rs +++ b/src/modules/utils/directory_win.rs @@ -49,7 +49,7 @@ pub fn is_write_allowed(folder_path: &Path) -> std::result::Result // expect ERROR_INSUFFICIENT_BUFFER match rc.ok() { Err(e) if e.code() == ERROR_INSUFFICIENT_BUFFER.into() => (), - result => return Err(format!("GetFileSecurityW returned unexpected return value when asked for the security descriptor size: {:?}", result)), + result => return Err(format!("GetFileSecurityW returned unexpected return value when asked for the security descriptor size: {result:?}")), } let mut buf = vec![0u8; length as usize]; diff --git a/src/modules/utils/truncate.rs b/src/modules/utils/truncate.rs index 9ec920cb..0f37c07e 100644 --- a/src/modules/utils/truncate.rs +++ b/src/modules/utils/truncate.rs @@ -102,6 +102,6 @@ mod tests { ) { let actual = truncate_text(text, truncate_length as usize, truncation_symbol); - assert_eq!(format!("{}{}", expected, truncation_symbol), actual); + assert_eq!(format!("{expected}{truncation_symbol}"), actual); } } diff --git a/src/print.rs b/src/print.rs index 6bb1f1be..6a1bdc73 100644 --- a/src/print.rs +++ b/src/print.rs @@ -139,7 +139,7 @@ pub fn get_prompt(context: Context) -> String { pub fn module(module_name: &str, args: Properties) { let context = Context::new(args, Target::Main); let module = get_module(module_name, context).unwrap_or_default(); - print!("{}", module); + print!("{module}"); } pub fn get_module(module_name: &str, context: Context) -> Option { @@ -251,7 +251,7 @@ pub fn explain(args: Properties) { escaping = true; } if escaping { - print!("{}", g); + print!("{g}"); escaping = !(("a"..="z").contains(&g) || ("A"..="Z").contains(&g)); continue; } @@ -273,7 +273,7 @@ pub fn explain(args: Properties) { current_pos = 1; } - print!("{}", g); + print!("{g}"); } println!(); } else { @@ -373,7 +373,7 @@ fn should_add_implicit_custom_module( config: &toml::Value, module_list: &BTreeSet, ) -> bool { - let explicit_module_name = format!("custom.{}", custom_module); + let explicit_module_name = format!("custom.{custom_module}"); let is_explicitly_specified = module_list.contains(&explicit_module_name); if is_explicitly_specified { diff --git a/src/serde_utils.rs b/src/serde_utils.rs index 0a904ef4..c1c38384 100644 --- a/src/serde_utils.rs +++ b/src/serde_utils.rs @@ -144,7 +144,7 @@ impl<'de> Deserializer<'de> for ValueDeserializer<'de> { _ => None, }; let did_you_mean = did_you_mean - .map(|(_score, field)| format!(" (Did you mean '{}'?)", field)) + .map(|(_score, field)| format!(" (Did you mean '{field}'?)")) .unwrap_or_default(); Err(self.error(format!("Unknown key{did_you_mean}"))) @@ -312,7 +312,7 @@ mod test { let result = Sample::deserialize(deserializer).unwrap_err(); assert_eq!( - format!("{}", result), + format!("{result}"), "Error in 'Sample' at 'unknown_key': Unknown key" ); } @@ -326,7 +326,7 @@ mod test { let result = StarshipRootConfig::deserialize(deserializer).unwrap_err(); assert_eq!( - format!("{}", result), + format!("{result}"), "Error in 'StarshipRoot' at 'unknown_key': Unknown key" ); } @@ -358,7 +358,7 @@ mod test { let result = Sample::deserialize(deserializer).unwrap_err(); assert_eq!( - format!("{}", result), + format!("{result}"), "Error in 'Sample' at 'food': Unknown key (Did you mean 'foo'?)" ); } @@ -378,7 +378,7 @@ mod test { let result = Sample::deserialize(deserializer).unwrap_err(); assert_eq!( - format!("{}", result), + format!("{result}"), "Error in 'Sample' at 'foo': invalid type: integer `1`, expected a string" ); } diff --git a/src/test/mod.rs b/src/test/mod.rs index ab3f6f29..c6320226 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -174,19 +174,19 @@ pub fn fixture_repo(provider: FixtureProvider) -> io::Result { create_command("git")? .current_dir(path.path()) - .args(&["clone", "-b", "master"]) + .args(["clone", "-b", "master"]) .arg(GIT_FIXTURE.as_os_str()) - .arg(&path.path()) + .arg(path.path()) .output()?; create_command("git")? - .args(&["config", "--local", "user.email", "starship@example.com"]) - .current_dir(&path.path()) + .args(["config", "--local", "user.email", "starship@example.com"]) + .current_dir(path.path()) .output()?; create_command("git")? - .args(&["config", "--local", "user.name", "starship"]) - .current_dir(&path.path()) + .args(["config", "--local", "user.name", "starship"]) + .current_dir(path.path()) .output()?; // Prevent intermittent test failures and ensure that the result of git commands @@ -194,19 +194,19 @@ pub fn fixture_repo(provider: FixtureProvider) -> io::Result { // This is especially important on Windows. // Newer, more far-reaching git setting for `fsync`, that's not yet widely supported: create_command("git")? - .args(&["config", "--local", "core.fsync", "all"]) - .current_dir(&path.path()) + .args(["config", "--local", "core.fsync", "all"]) + .current_dir(path.path()) .output()?; // Older git setting for `fsync` for compatibility with older git versions: create_command("git")? - .args(&["config", "--local", "core.fsyncObjectFiles", "true"]) - .current_dir(&path.path()) + .args(["config", "--local", "core.fsyncObjectFiles", "true"]) + .current_dir(path.path()) .output()?; create_command("git")? - .args(&["reset", "--hard", "HEAD"]) - .current_dir(&path.path()) + .args(["reset", "--hard", "HEAD"]) + .current_dir(path.path()) .output()?; Ok(path) @@ -218,7 +218,7 @@ pub fn fixture_repo(provider: FixtureProvider) -> io::Result { .current_dir(path.path()) .arg("clone") .arg(HG_FIXTURE.as_os_str()) - .arg(&path.path()) + .arg(path.path()) .output()?; Ok(path) diff --git a/src/utils.rs b/src/utils.rs index 48d5b02e..4427cddf 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -433,17 +433,17 @@ pub fn wrap_seq_for_shell( if x == escape_begin && !escaped { escaped = true; match shell { - Shell::Bash => format!("{}{}", BASH_BEG, escape_begin), - Shell::Zsh => format!("{}{}", ZSH_BEG, escape_begin), - Shell::Tcsh => format!("{}{}", TCSH_BEG, escape_begin), + Shell::Bash => format!("{BASH_BEG}{escape_begin}"), + Shell::Zsh => format!("{ZSH_BEG}{escape_begin}"), + Shell::Tcsh => format!("{TCSH_BEG}{escape_begin}"), _ => x.to_string(), } } else if x == escape_end && escaped { escaped = false; match shell { - Shell::Bash => format!("{}{}", escape_end, BASH_END), - Shell::Zsh => format!("{}{}", escape_end, ZSH_END), - Shell::Tcsh => format!("{}{}", escape_end, TCSH_END), + Shell::Bash => format!("{escape_end}{BASH_END}"), + Shell::Zsh => format!("{escape_end}{ZSH_END}"), + Shell::Tcsh => format!("{escape_end}{TCSH_END}"), _ => x.to_string(), } } else { @@ -559,7 +559,7 @@ pub fn render_time(raw_millis: u128, show_millis: bool) -> String { fn render_time_component((component, suffix): (&u128, &&str)) -> String { match component { 0 => String::new(), - n => format!("{}{}", n, suffix), + n => format!("{n}{suffix}"), } } @@ -750,7 +750,7 @@ mod tests { }; assert_eq!(get_command_string_output(case1), "stdout"); let case2 = CommandOutput { - stdout: String::from(""), + stdout: String::new(), stderr: String::from("stderr"), }; assert_eq!(get_command_string_output(case2), "stderr");