mirror of
https://github.com/starship/starship.git
synced 2024-11-07 17:05:09 +01:00
chore: apply new rust 1.75 & nightly clippy fixes (#5646)
chore: apply clippy fixes
This commit is contained in:
parent
89dc19214b
commit
cd0fdb7ce0
@ -244,7 +244,7 @@ impl<'a> Context<'a> {
|
||||
.any(|env_var| self.get_env(env_var).is_some())
|
||||
}
|
||||
|
||||
/// Returns true if 'detect_env_vars' is empty,
|
||||
/// Returns true if `detect_env_vars` is empty,
|
||||
/// or if at least one environment variable is set and no negated environment variable is set
|
||||
pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool {
|
||||
if env_vars.is_empty() {
|
||||
|
@ -188,7 +188,7 @@ fn main() {
|
||||
(_, _, true) => Target::Continuation,
|
||||
(_, _, _) => Target::Main,
|
||||
};
|
||||
print::prompt(properties, target)
|
||||
print::prompt(properties, target);
|
||||
}
|
||||
Commands::Module {
|
||||
name,
|
||||
@ -211,7 +211,7 @@ fn main() {
|
||||
let context = Context::default();
|
||||
if let Some(name) = name {
|
||||
if let Some(value) = value {
|
||||
configure::update_configuration(&context, &name, &value)
|
||||
configure::update_configuration(&context, &name, &value);
|
||||
}
|
||||
} else if let Err(reason) = configure::edit_configuration(&context, None) {
|
||||
eprintln!("Could not edit configuration: {reason}");
|
||||
@ -222,7 +222,7 @@ fn main() {
|
||||
configure::print_configuration(&Context::default(), default, &name);
|
||||
}
|
||||
Commands::Toggle { name, value } => {
|
||||
configure::toggle_configuration(&Context::default(), &name, &value)
|
||||
configure::toggle_configuration(&Context::default(), &name, &value);
|
||||
}
|
||||
Commands::BugReport => bug_report::create(),
|
||||
Commands::Time => {
|
||||
|
@ -117,8 +117,8 @@ impl FromStr for AllowStatus {
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"true" => Ok(AllowStatus::Allowed),
|
||||
"false" => Ok(AllowStatus::Denied),
|
||||
"true" => Ok(Self::Allowed),
|
||||
"false" => Ok(Self::Denied),
|
||||
_ => Err(Cow::from("invalid allow status")),
|
||||
}
|
||||
}
|
||||
@ -152,7 +152,7 @@ mod tests {
|
||||
let dir = tempfile::tempdir()?;
|
||||
let rc_path = dir.path().join(".envrc");
|
||||
|
||||
std::fs::File::create(&rc_path)?.sync_all()?;
|
||||
std::fs::File::create(rc_path)?.sync_all()?;
|
||||
|
||||
let renderer = ModuleRenderer::new("direnv")
|
||||
.config(toml::toml! {
|
||||
@ -169,7 +169,7 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Some(format!("direnv not loaded/allowed ")),
|
||||
Some("direnv not loaded/allowed ".to_string()),
|
||||
renderer.collect()
|
||||
);
|
||||
|
||||
@ -180,7 +180,7 @@ mod tests {
|
||||
let dir = tempfile::tempdir()?;
|
||||
let rc_path = dir.path().join(".envrc");
|
||||
|
||||
std::fs::File::create(&rc_path)?.sync_all()?;
|
||||
std::fs::File::create(rc_path)?.sync_all()?;
|
||||
|
||||
let renderer = ModuleRenderer::new("direnv")
|
||||
.config(toml::toml! {
|
||||
@ -196,7 +196,10 @@ mod tests {
|
||||
}),
|
||||
);
|
||||
|
||||
assert_eq!(Some(format!("direnv loaded/allowed ")), renderer.collect());
|
||||
assert_eq!(
|
||||
Some("direnv loaded/allowed ".to_string()),
|
||||
renderer.collect()
|
||||
);
|
||||
|
||||
dir.close()
|
||||
}
|
||||
@ -205,7 +208,7 @@ mod tests {
|
||||
let dir = tempfile::tempdir()?;
|
||||
let rc_path = dir.path().join(".envrc");
|
||||
|
||||
std::fs::File::create(&rc_path)?.sync_all()?;
|
||||
std::fs::File::create(rc_path)?.sync_all()?;
|
||||
|
||||
let renderer = ModuleRenderer::new("direnv")
|
||||
.config(toml::toml! {
|
||||
@ -221,13 +224,16 @@ mod tests {
|
||||
}),
|
||||
);
|
||||
|
||||
assert_eq!(Some(format!("direnv loaded/denied ")), renderer.collect());
|
||||
assert_eq!(
|
||||
Some("direnv loaded/denied ".to_string()),
|
||||
renderer.collect()
|
||||
);
|
||||
|
||||
dir.close()
|
||||
}
|
||||
fn status_cmd_output_without_rc() -> String {
|
||||
String::from(
|
||||
r#"\
|
||||
r"\
|
||||
direnv exec path /usr/bin/direnv
|
||||
DIRENV_CONFIG /home/test/.config/direnv
|
||||
bash_path /usr/bin/bash
|
||||
@ -236,7 +242,7 @@ warn_timeout 5s
|
||||
whitelist.prefix []
|
||||
whitelist.exact map[]
|
||||
No .envrc or .env loaded
|
||||
No .envrc or .env found"#,
|
||||
No .envrc or .env found",
|
||||
)
|
||||
}
|
||||
fn status_cmd_output_with_rc(dir: impl AsRef<Path>, loaded: bool, allowed: bool) -> String {
|
||||
|
@ -599,13 +599,13 @@ mod tests {
|
||||
}
|
||||
|
||||
fn make_csproj_with_tfm(tfm_element: &str, tfm: &str) -> String {
|
||||
let json_text = r#"
|
||||
let json_text = r"
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<TFM_ELEMENT>TFM_VALUE</TFM_ELEMENT>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
"#;
|
||||
";
|
||||
json_text
|
||||
.replace("TFM_ELEMENT", tfm_element)
|
||||
.replace("TFM_VALUE", tfm)
|
||||
|
@ -287,10 +287,10 @@ mod tests {
|
||||
"{}{}",
|
||||
expect_added
|
||||
.map(|added| format!("{} ", expect_added_style.paint(format!("+{added}"))))
|
||||
.unwrap_or(String::from("")),
|
||||
.unwrap_or_default(),
|
||||
expect_deleted
|
||||
.map(|deleted| format!("{} ", expect_deleted_style.paint(format!("-{deleted}"))))
|
||||
.unwrap_or(String::from("")),
|
||||
.unwrap_or_default(),
|
||||
));
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ fn get_current_kube_context_name(filename: path::PathBuf) -> Option<String> {
|
||||
let contents = utils::read_file(filename).ok()?;
|
||||
|
||||
let yaml_docs = YamlLoader::load_from_str(&contents).ok()?;
|
||||
let conf = yaml_docs.get(0)?;
|
||||
let conf = yaml_docs.first()?;
|
||||
conf["current-context"]
|
||||
.as_str()
|
||||
.filter(|s| !s.is_empty())
|
||||
@ -35,7 +35,7 @@ fn get_kube_ctx_components(
|
||||
let contents = utils::read_file(filename).ok()?;
|
||||
|
||||
let yaml_docs = YamlLoader::load_from_str(&contents).ok()?;
|
||||
let conf = yaml_docs.get(0)?;
|
||||
let conf = yaml_docs.first()?;
|
||||
let contexts = conf["contexts"].as_vec()?;
|
||||
|
||||
// Find the context with the name we're looking for
|
||||
@ -118,16 +118,13 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
.any(|v| !v.is_empty());
|
||||
|
||||
let is_kube_project = have_scan_config.then(|| {
|
||||
context
|
||||
.try_begin_scan()
|
||||
.map(|scanner| {
|
||||
scanner
|
||||
.set_files(&config.detect_files)
|
||||
.set_folders(&config.detect_folders)
|
||||
.set_extensions(&config.detect_extensions)
|
||||
.is_match()
|
||||
})
|
||||
.unwrap_or(false)
|
||||
context.try_begin_scan().map_or(false, |scanner| {
|
||||
scanner
|
||||
.set_files(&config.detect_files)
|
||||
.set_folders(&config.detect_folders)
|
||||
.set_extensions(&config.detect_extensions)
|
||||
.is_match()
|
||||
})
|
||||
});
|
||||
|
||||
if !is_kube_project.unwrap_or(true) {
|
||||
|
@ -23,7 +23,7 @@ impl NixShellType {
|
||||
};
|
||||
|
||||
if use_heuristic {
|
||||
Self::in_new_nix_shell(context).map(|_| Unknown)
|
||||
Self::in_new_nix_shell(context).map(|()| Unknown)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ fn get_osp_project_from_config(context: &Context, osp_cloud: &str) -> Option<Pro
|
||||
.filter_map(|file| {
|
||||
let config = utils::read_file(file.as_ref()?).ok()?;
|
||||
let clouds = YamlLoader::load_from_str(config.as_str()).ok()?;
|
||||
clouds.get(0)?["clouds"][osp_cloud]["auth"]["project_name"]
|
||||
clouds.first()?["clouds"][osp_cloud]["auth"]["project_name"]
|
||||
.as_str()
|
||||
.map(ToOwned::to_owned)
|
||||
})
|
||||
|
@ -376,10 +376,10 @@ Python 3.7.9 (7e6e2bb30ac5fbdbd443619cae28c51d5c162a02, Nov 24 2020, 10:03:59)
|
||||
create_dir_all(dir.path().join("my_venv"))?;
|
||||
let mut venv_cfg = File::create(dir.path().join("my_venv").join("pyvenv.cfg"))?;
|
||||
venv_cfg.write_all(
|
||||
br#"
|
||||
br"
|
||||
home = something
|
||||
prompt = 'foo'
|
||||
"#,
|
||||
",
|
||||
)?;
|
||||
venv_cfg.sync_all()?;
|
||||
|
||||
@ -403,10 +403,10 @@ prompt = 'foo'
|
||||
create_dir_all(dir.path().join("my_venv"))?;
|
||||
let mut venv_cfg = File::create(dir.path().join("my_venv").join("pyvenv.cfg"))?;
|
||||
venv_cfg.write_all(
|
||||
br#"
|
||||
br"
|
||||
home = something
|
||||
prompt = '(foo)'
|
||||
"#,
|
||||
",
|
||||
)?;
|
||||
venv_cfg.sync_all()?;
|
||||
|
||||
|
@ -914,32 +914,32 @@ version = "12"
|
||||
};
|
||||
}
|
||||
|
||||
static STABLE: &str = r#"rustc 1.40.0 (73528e339 2019-12-16)
|
||||
static STABLE: &str = r"rustc 1.40.0 (73528e339 2019-12-16)
|
||||
binary: rustc
|
||||
commit-hash: 73528e339aae0f17a15ffa49a8ac608f50c6cf14
|
||||
commit-date: 2019-12-16
|
||||
host: x86_64-unknown-linux-gnu
|
||||
release: 1.40.0
|
||||
LLVM version: 9.0
|
||||
"#;
|
||||
";
|
||||
|
||||
static BETA: &str = r#"rustc 1.41.0-beta.1 (eb3f7c2d3 2019-12-17)
|
||||
static BETA: &str = r"rustc 1.41.0-beta.1 (eb3f7c2d3 2019-12-17)
|
||||
binary: rustc
|
||||
commit-hash: eb3f7c2d3aec576f47eba854cfbd3c1187b8a2a0
|
||||
commit-date: 2019-12-17
|
||||
host: x86_64-unknown-linux-gnu
|
||||
release: 1.41.0-beta.1
|
||||
LLVM version: 9.0
|
||||
"#;
|
||||
";
|
||||
|
||||
static NIGHTLY: &str = r#"rustc 1.42.0-nightly (da3629b05 2019-12-29)
|
||||
static NIGHTLY: &str = r"rustc 1.42.0-nightly (da3629b05 2019-12-29)
|
||||
binary: rustc
|
||||
commit-hash: da3629b05f8f1b425a738bfe9fe9aedd47c5417a
|
||||
commit-date: 2019-12-29
|
||||
host: x86_64-unknown-linux-gnu
|
||||
release: 1.42.0-nightly
|
||||
LLVM version: 9.0
|
||||
"#;
|
||||
";
|
||||
|
||||
test!(
|
||||
(STABLE, None) => Some(("v1.40.0", "x86_64-unknown-linux-gnu")),
|
||||
|
@ -242,7 +242,7 @@ mod tests {
|
||||
disabled = false
|
||||
threshold = threshold
|
||||
})
|
||||
.env(SHLVL_ENV_VAR, format!("{}", shlvl))
|
||||
.env(SHLVL_ENV_VAR, format!("{shlvl}"))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
@ -391,7 +391,7 @@ pub fn format_duration(duration: &Duration) -> String {
|
||||
/// Return the modules from $all that are not already in the list
|
||||
fn all_modules_uniq(module_list: &BTreeSet<String>) -> Vec<String> {
|
||||
let mut prompt_order: Vec<String> = Vec::new();
|
||||
for module in PROMPT_ORDER.iter() {
|
||||
for module in PROMPT_ORDER {
|
||||
if !module_list.contains(*module) {
|
||||
prompt_order.push(String::from(*module))
|
||||
}
|
||||
@ -452,7 +452,7 @@ fn load_formatter_and_modules<'a>(context: &'a Context) -> (StringFormatter<'a>,
|
||||
let modules = [&lf, &rf]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.flat_map(|f| f.get_variables())
|
||||
.flat_map(VariableHolder::get_variables)
|
||||
.collect();
|
||||
|
||||
let main_formatter = match context.target {
|
||||
|
@ -71,7 +71,7 @@ pub fn write_file<P: AsRef<Path>, S: AsRef<str>>(file_name: P, text: S) -> Resul
|
||||
};
|
||||
|
||||
match file.write_all(text.as_bytes()) {
|
||||
Ok(_) => {
|
||||
Ok(()) => {
|
||||
log::trace!("File {file_name:?} written successfully");
|
||||
}
|
||||
Err(err) => {
|
||||
|
Loading…
Reference in New Issue
Block a user