chore: fix new clippy lints (#4557)

This commit is contained in:
David Knaack 2022-11-05 12:40:46 +01:00 committed by GitHub
parent 9b64f518c9
commit 6e38683c89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 324 additions and 324 deletions

View File

@ -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": {

View File

@ -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#"

View File

@ -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 = "<unknown shell>";
@ -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(),

View File

@ -141,7 +141,7 @@ impl StarshipConfig {
fn config_from_file() -> Option<Value> {
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)

View File

@ -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> {

View File

@ -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,

View File

@ -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::<String>()
);
@ -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::<String>()
);
}
@ -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<dyn s
.status();
if let Err(e) = res {
eprintln!("Unable to launch editor {:?}", editor_cmd);
eprintln!("Unable to launch editor {editor_cmd:?}");
return Err(Box::new(e));
}
@ -352,17 +352,17 @@ mod tests {
#[test]
fn visual_empty_editor_set() {
let actual = get_editor_internal(Some("".into()), Some("bar".into()));
let actual = get_editor_internal(Some(String::new()), Some("bar".into()));
assert_eq!("bar", actual);
}
#[test]
fn visual_empty_editor_empty() {
let actual = get_editor_internal(Some("".into()), Some("".into()));
let actual = get_editor_internal(Some(String::new()), Some(String::new()));
assert_eq!(STD_EDITOR, actual);
}
#[test]
fn visual_empty_editor_not_set() {
let actual = get_editor_internal(Some("".into()), None);
let actual = get_editor_internal(Some(String::new()), None);
assert_eq!(STD_EDITOR, actual);
}
@ -373,7 +373,7 @@ mod tests {
}
#[test]
fn visual_not_set_editor_empty() {
let actual = get_editor_internal(None, Some("".into()));
let actual = get_editor_internal(None, Some(String::new()));
assert_eq!(STD_EDITOR, actual);
}
#[test]

View File

@ -631,7 +631,7 @@ fn get_remote_repository_info(
let branch_name = branch_name?;
let branch = repository
.branch_remote_ref(branch_name)
.and_then(|r| r.ok())
.and_then(std::result::Result::ok)
.map(|r| r.shorten().to_string());
let name = repository
.branch_remote_name(branch_name)
@ -849,7 +849,7 @@ mod tests {
let tmp_dir = tempfile::TempDir::new()?;
let path = tmp_dir.path().join("a/xxx/yyy");
fs::create_dir_all(&path)?;
fs::create_dir_all(path)?;
// Set up a mock symlink
let path_actual = tmp_dir.path().join("a/xxx");

View File

@ -58,11 +58,13 @@ fn parse_style(style: Pair<Rule>) -> Vec<StyleElement> {
.collect()
}
pub fn parse(format: &str) -> Result<Vec<FormatElement>, Error<Rule>> {
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<Vec<FormatElement>, Box<Error<Rule>>> {
IdentParser::parse(Rule::expression, format)
.map(|pairs| {
pairs
.take_while(|pair| pair.as_rule() != Rule::EOI)
.map(parse_value)
.collect()
})
.map_err(Box::new)
}

View File

@ -35,14 +35,14 @@ type StyleVariableMapType<'a> =
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StringFormatterError {
Custom(String),
Parse(PestError<Rule>),
Parse(Box<PestError<Rule>>),
}
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);

View File

@ -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}"))
}
}
}

View File

@ -44,11 +44,11 @@ impl StarshipPath {
fn sprint_pwsh(&self) -> io::Result<String> {
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<String> {
self.str_path().map(|s| format!("\"{}\"", s))
self.str_path().map(|s| format!("\"{s}\""))
}
fn sprint_posix(&self) -> io::Result<String> {
// 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

View File

@ -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!");
}

View File

@ -66,7 +66,7 @@ fn get_profile_config<'a>(
profile: &Option<Profile>,
) -> 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);

View File

@ -89,7 +89,7 @@ fn get_config_file_location(context: &Context) -> Option<PathBuf> {
fn parse_json(json_file_path: &Path) -> Option<JValue> {
let mut buffer: Vec<u8> = 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()?;

View File

@ -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

View File

@ -101,7 +101,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
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<Module<'a>> {
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::<Vec<&str>>();
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);

View File

@ -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()?;

View File

@ -120,7 +120,7 @@ fn get_tfm_from_project_file(path: &Path) -> Option<String> {
// 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()?;
}

View File

@ -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);

View File

@ -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);

View File

@ -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]

View File

@ -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()?;

View File

@ -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!(

View File

@ -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,
)?;

View File

@ -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,
)?;

View File

@ -437,7 +437,7 @@ fn git_status_wsl(context: &Context, conf: &GitStatusConfig) -> Option<String> {
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<String> {
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()?;

View File

@ -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();

View File

@ -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()?;

View File

@ -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(())
}

View File

@ -72,7 +72,7 @@ fn get_java_version(context: &Context) -> Option<String> {
})
.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);

View File

@ -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)),

View File

@ -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 ")));

View File

@ -95,7 +95,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
})
.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,

View File

@ -182,7 +182,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
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), "<no description>");
}
}

View File

@ -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 ")));

View File

@ -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")

View File

@ -168,7 +168,7 @@ fn get_maven_version(context: &Context, config: &PackageConfig) -> Option<String
depth -= 1;
}
Ok(QXEvent::Text(t)) if in_ver => {
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<String
let mut cargo_toml: toml::Value = toml::from_str(&file_contents).ok()?;
let cargo_version = cargo_toml.get("package").and_then(|p| p.get("version"));
let raw_version = if let Some(v) = cargo_version.and_then(|v| v.as_str()) {
let raw_version = if let Some(v) = cargo_version.and_then(toml::Value::as_str) {
// regular version string
v
} else if cargo_version
.and_then(|v| v.get("workspace"))
.and_then(|w| w.as_bool())
.and_then(toml::Value::as_bool)
.unwrap_or_default()
{
// workspace version string (`package.version.worspace = true`)
@ -526,7 +526,7 @@ license = "MIT"
}
"##
.to_owned(),
stderr: "".to_owned(),
stderr: String::new(),
}),
)
.path(project_dir.path())
@ -1417,7 +1417,7 @@ environment:
let text = String::from(contains.unwrap_or(""));
let expected = Some(format!(
"is {} ",
Color::Fixed(208).bold().paint(format!("📦 {}", text))
Color::Fixed(208).bold().paint(format!("📦 {text}"))
));
if contains.is_some() {

View File

@ -123,7 +123,7 @@ fn find_package_file(path: &Path) -> Option<PathBuf> {
/// 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<String> {
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!(

View File

@ -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()
}

View File

@ -76,7 +76,7 @@ fn format_ruby_version(ruby_version: &str, version_format: &str) -> Option<Strin
Ok(formatted) => Some(formatted),
Err(error) => {
log::warn!("Error formatting `ruby` version:\n{}", error);
Some(format!("v{}", version))
Some(format!("v{version}"))
}
}
}

View File

@ -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() {

View File

@ -79,7 +79,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
})
.flatten()
.collect::<String>(),
_ => "".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! {

View File

@ -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! {

View File

@ -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!(

View File

@ -49,7 +49,7 @@ pub fn is_write_allowed(folder_path: &Path) -> std::result::Result<bool, String>
// 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];

View File

@ -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);
}
}

View File

@ -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<String> {
@ -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<String>,
) -> 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 {

View File

@ -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"
);
}

View File

@ -174,19 +174,19 @@ pub fn fixture_repo(provider: FixtureProvider) -> io::Result<TempDir> {
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<TempDir> {
// 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<TempDir> {
.current_dir(path.path())
.arg("clone")
.arg(HG_FIXTURE.as_os_str())
.arg(&path.path())
.arg(path.path())
.output()?;
Ok(path)

View File

@ -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");