Browse Source

Fix Clippy errors (#885)

* cargo clippy --fix

* cargo fmt
remotes/origin/alias-latest
Gal Schlezinger 2 years ago committed by GitHub
parent
commit
7f9ed6668d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/alias.rs
  2. 4
      src/arch.rs
  3. 2
      src/commands/command.rs
  4. 2
      src/commands/completions.rs
  5. 2
      src/commands/current.rs
  6. 4
      src/commands/env.rs
  7. 4
      src/commands/ls_local.rs
  8. 2
      src/commands/ls_remote.rs
  9. 2
      src/commands/uninstall.rs
  10. 2
      src/directory_portal.rs
  11. 3
      src/downloader.rs
  12. 2
      src/lts.rs
  13. 2
      src/remote_node_index.rs
  14. 4
      src/shell/bash.rs
  15. 4
      src/shell/fish.rs
  16. 2
      src/shell/powershell.rs
  17. 2
      src/shell/shell.rs
  18. 6
      src/shell/windows_cmd/mod.rs
  19. 4
      src/shell/zsh.rs
  20. 4
      src/user_version.rs
  21. 4
      src/user_version_reader.rs
  22. 8
      src/version.rs

4
src/alias.rs

@ -17,13 +17,13 @@ pub fn create_alias(
let alias_dir = aliases_dir.join(common_name); let alias_dir = aliases_dir.join(common_name);
remove_symlink_dir(&alias_dir).ok(); remove_symlink_dir(&alias_dir).ok();
symlink_dir(&version_dir, &alias_dir)?; symlink_dir(version_dir, &alias_dir)?;
Ok(()) Ok(())
} }
pub fn list_aliases(config: &FnmConfig) -> std::io::Result<Vec<StoredAlias>> { pub fn list_aliases(config: &FnmConfig) -> std::io::Result<Vec<StoredAlias>> {
let vec: Vec<_> = std::fs::read_dir(&config.aliases_dir())? let vec: Vec<_> = std::fs::read_dir(config.aliases_dir())?
.filter_map(Result::ok) .filter_map(Result::ok)
.filter_map(|x| TryInto::<StoredAlias>::try_into(x.path().as_path()).ok()) .filter_map(|x| TryInto::<StoredAlias>::try_into(x.path().as_path()).ok())
.collect(); .collect();

4
src/arch.rs

@ -48,7 +48,7 @@ impl std::str::FromStr for Arch {
"ppc64le" => Ok(Arch::Ppc64le), "ppc64le" => Ok(Arch::Ppc64le),
"ppc64" => Ok(Arch::Ppc64), "ppc64" => Ok(Arch::Ppc64),
"s390x" => Ok(Arch::S390x), "s390x" => Ok(Arch::S390x),
unknown => Err(ArchError::new(&format!("Unknown Arch: {}", unknown))), unknown => Err(ArchError::new(&format!("Unknown Arch: {unknown}"))),
} }
} }
} }
@ -65,7 +65,7 @@ impl std::fmt::Display for Arch {
Arch::S390x => String::from("s390x"), Arch::S390x => String::from("s390x"),
}; };
write!(f, "{}", arch_str) write!(f, "{arch_str}")
} }
} }

2
src/commands/command.rs

@ -7,7 +7,7 @@ pub trait Command: Sized {
fn apply(self, config: &FnmConfig) -> Result<(), Self::Error>; fn apply(self, config: &FnmConfig) -> Result<(), Self::Error>;
fn handle_error(err: Self::Error, config: &FnmConfig) { fn handle_error(err: Self::Error, config: &FnmConfig) {
let err_s = format!("{}", err); let err_s = format!("{err}");
outln!(config, Error, "{} {}", "error:".red().bold(), err_s.red()); outln!(config, Error, "{} {}", "error:".red().bold(), err_s.red());
std::process::exit(1); std::process::exit(1);
} }

2
src/commands/completions.rs

@ -43,7 +43,7 @@ pub enum Error {
fn shells_as_string() -> String { fn shells_as_string() -> String {
AVAILABLE_SHELLS AVAILABLE_SHELLS
.iter() .iter()
.map(|x| format!("* {}", x)) .map(|x| format!("* {x}"))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n") .join("\n")
} }

2
src/commands/current.rs

@ -13,7 +13,7 @@ impl Command for Current {
Some(ver) => ver.v_str(), Some(ver) => ver.v_str(),
None => "none".into(), None => "none".into(),
}; };
println!("{}", version_string); println!("{version_string}");
Ok(()) Ok(())
} }
} }

4
src/commands/env.rs

@ -114,7 +114,7 @@ impl Command for Env {
println!("{}", shell.use_on_cd(config)?); println!("{}", shell.use_on_cd(config)?);
} }
if let Some(v) = shell.rehash() { if let Some(v) = shell.rehash() {
println!("{}", v); println!("{v}");
} }
Ok(()) Ok(())
@ -147,7 +147,7 @@ pub enum Error {
fn shells_as_string() -> String { fn shells_as_string() -> String {
AVAILABLE_SHELLS AVAILABLE_SHELLS
.iter() .iter()
.map(|x| format!("* {}", x)) .map(|x| format!("* {x}"))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n") .join("\n")
} }

4
src/commands/ls_local.rs

@ -35,12 +35,12 @@ impl super::command::Command for LsLocal {
} }
}; };
let version_str = format!("* {}{}", version, version_aliases); let version_str = format!("* {version}{version_aliases}");
if curr_version == Some(version) { if curr_version == Some(version) {
println!("{}", version_str.cyan()); println!("{}", version_str.cyan());
} else { } else {
println!("{}", version_str); println!("{version_str}");
} }
} }
Ok(()) Ok(())

2
src/commands/ls_remote.rs

@ -14,7 +14,7 @@ impl super::command::Command for LsRemote {
for version in all_versions { for version in all_versions {
print!("{}", version.version); print!("{}", version.version);
if let Some(lts) = &version.lts { if let Some(lts) = &version.lts {
print!(" ({})", lts); print!(" ({lts})");
} }
println!(); println!();
} }

2
src/commands/uninstall.rs

@ -92,7 +92,7 @@ pub enum Error {
CantInferVersion, CantInferVersion,
#[error("Can't uninstall system version")] #[error("Can't uninstall system version")]
CantUninstallSystemVersion, CantUninstallSystemVersion,
#[error("Too many versions had matched, please be more specific.\nFound {} matching versions, expected 1:\n{}", matched_versions.len(), matched_versions.iter().map(|v| format!("* {}", v)).collect::<Vec<_>>().join("\n"))] #[error("Too many versions had matched, please be more specific.\nFound {} matching versions, expected 1:\n{}", matched_versions.len(), matched_versions.iter().map(|v| format!("* {v}")).collect::<Vec<_>>().join("\n"))]
PleaseBeMoreSpecificToDelete { matched_versions: Vec<String> }, PleaseBeMoreSpecificToDelete { matched_versions: Vec<String> },
#[error("Can't find a matching version")] #[error("Can't find a matching version")]
CantFindVersion, CantFindVersion,

2
src/directory_portal.rs

@ -57,7 +57,7 @@ mod tests {
let tempdir = tempdir().expect("Can't generate a temp directory"); let tempdir = tempdir().expect("Can't generate a temp directory");
let portal = DirectoryPortal::new_in(std::env::temp_dir(), tempdir.path().join("subdir")); let portal = DirectoryPortal::new_in(std::env::temp_dir(), tempdir.path().join("subdir"));
let new_file_path = portal.to_path_buf().join("README.md"); let new_file_path = portal.to_path_buf().join("README.md");
std::fs::write(&new_file_path, "Hello world!").expect("Can't write file"); std::fs::write(new_file_path, "Hello world!").expect("Can't write file");
let target = portal.teleport().expect("Can't close directory portal"); let target = portal.teleport().expect("Can't close directory portal");
let file_exists: Vec<_> = target let file_exists: Vec<_> = target

3
src/downloader.rs

@ -171,8 +171,7 @@ mod tests {
let version = Version::parse("12.0.0").unwrap(); let version = Version::parse("12.0.0").unwrap();
let arch = Arch::X64; let arch = Arch::X64;
let node_dist_mirror = Url::parse("https://nodejs.org/dist/").unwrap(); let node_dist_mirror = Url::parse("https://nodejs.org/dist/").unwrap();
install_node_dist(&version, &node_dist_mirror, &path, &arch) install_node_dist(&version, &node_dist_mirror, path, &arch).expect("Can't install Node 12");
.expect("Can't install Node 12");
let mut location_path = path.join(version.v_str()).join("installation"); let mut location_path = path.join(version.v_str()).join("installation");

2
src/lts.rs

@ -23,7 +23,7 @@ impl Display for LtsType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Self::Latest => write!(f, "latest"), Self::Latest => write!(f, "latest"),
Self::CodeName(s) => write!(f, "{}", s), Self::CodeName(s) => write!(f, "{s}"),
} }
} }
} }

2
src/remote_node_index.rs

@ -72,7 +72,7 @@ pub struct IndexedNodeVersion {
/// use crate::remote_node_index::list; /// use crate::remote_node_index::list;
/// ``` /// ```
pub fn list(base_url: &Url) -> Result<Vec<IndexedNodeVersion>, crate::http::Error> { pub fn list(base_url: &Url) -> Result<Vec<IndexedNodeVersion>, crate::http::Error> {
let index_json_url = format!("{}/index.json", base_url); let index_json_url = format!("{base_url}/index.json");
let resp = crate::http::get(&index_json_url)?; let resp = crate::http::get(&index_json_url)?;
let mut value: Vec<IndexedNodeVersion> = resp.json()?; let mut value: Vec<IndexedNodeVersion> = resp.json()?;
value.sort_by(|a, b| a.version.cmp(&b.version)); value.sort_by(|a, b| a.version.cmp(&b.version));

4
src/shell/bash.rs

@ -16,11 +16,11 @@ impl Shell for Bash {
let path = path let path = path
.to_str() .to_str()
.ok_or_else(|| anyhow::anyhow!("Can't convert path to string"))?; .ok_or_else(|| anyhow::anyhow!("Can't convert path to string"))?;
Ok(format!("export PATH={:?}:$PATH", path)) Ok(format!("export PATH={path:?}:$PATH"))
} }
fn set_env_var(&self, name: &str, value: &str) -> String { fn set_env_var(&self, name: &str, value: &str) -> String {
format!("export {}={:?}", name, value) format!("export {name}={value:?}")
} }
fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> { fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> {

4
src/shell/fish.rs

@ -16,11 +16,11 @@ impl Shell for Fish {
let path = path let path = path
.to_str() .to_str()
.ok_or_else(|| anyhow::anyhow!("Can't convert path to string"))?; .ok_or_else(|| anyhow::anyhow!("Can't convert path to string"))?;
Ok(format!("set -gx PATH {:?} $PATH;", path)) Ok(format!("set -gx PATH {path:?} $PATH;"))
} }
fn set_env_var(&self, name: &str, value: &str) -> String { fn set_env_var(&self, name: &str, value: &str) -> String {
format!("set -gx {name} {value:?};", name = name, value = value) format!("set -gx {name} {value:?};")
} }
fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> { fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> {

2
src/shell/powershell.rs

@ -22,7 +22,7 @@ impl Shell for PowerShell {
} }
fn set_env_var(&self, name: &str, value: &str) -> String { fn set_env_var(&self, name: &str, value: &str) -> String {
format!(r#"$env:{} = "{}""#, name, value) format!(r#"$env:{name} = "{value}""#)
} }
fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> { fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> {

2
src/shell/shell.rs

@ -27,7 +27,7 @@ impl std::str::FromStr for Box<dyn Shell> {
"bash" => Ok(Box::from(super::bash::Bash)), "bash" => Ok(Box::from(super::bash::Bash)),
"fish" => Ok(Box::from(super::fish::Fish)), "fish" => Ok(Box::from(super::fish::Fish)),
"powershell" => Ok(Box::from(super::powershell::PowerShell)), "powershell" => Ok(Box::from(super::powershell::PowerShell)),
shell_type => Err(format!("I don't know the shell type of {:?}", shell_type)), shell_type => Err(format!("I don't know the shell type of {shell_type:?}",)),
} }
} }
} }

6
src/shell/windows_cmd/mod.rs

@ -20,11 +20,11 @@ impl Shell for WindowsCmd {
let new_path = new_path let new_path = new_path
.to_str() .to_str()
.ok_or_else(|| anyhow::anyhow!("Can't convert path to string"))?; .ok_or_else(|| anyhow::anyhow!("Can't convert path to string"))?;
Ok(format!("SET PATH={}", new_path)) Ok(format!("SET PATH={new_path}"))
} }
fn set_env_var(&self, name: &str, value: &str) -> String { fn set_env_var(&self, name: &str, value: &str) -> String {
format!("SET {}={}", name, value) format!("SET {name}={value}")
} }
fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> { fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> {
@ -39,7 +39,7 @@ impl Shell for WindowsCmd {
let path = path let path = path
.to_str() .to_str()
.ok_or_else(|| anyhow::anyhow!("Can't read path to cd.cmd"))?; .ok_or_else(|| anyhow::anyhow!("Can't read path to cd.cmd"))?;
Ok(format!("doskey cd={} $*", path,)) Ok(format!("doskey cd={path} $*",))
} }
} }

4
src/shell/zsh.rs

@ -16,11 +16,11 @@ impl Shell for Zsh {
let path = path let path = path
.to_str() .to_str()
.ok_or_else(|| anyhow::anyhow!("Path is not valid UTF-8"))?; .ok_or_else(|| anyhow::anyhow!("Path is not valid UTF-8"))?;
Ok(format!("export PATH={:?}:$PATH", path)) Ok(format!("export PATH={path:?}:$PATH"))
} }
fn set_env_var(&self, name: &str, value: &str) -> String { fn set_env_var(&self, name: &str, value: &str) -> String {
format!("export {}={:?}", name, value) format!("export {name}={value:?}")
} }
fn rehash(&self) -> Option<String> { fn rehash(&self) -> Option<String> {

4
src/user_version.rs

@ -59,8 +59,8 @@ impl std::fmt::Display for UserVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Self::Full(x) => x.fmt(f), Self::Full(x) => x.fmt(f),
Self::OnlyMajor(major) => write!(f, "v{}.x.x", major), Self::OnlyMajor(major) => write!(f, "v{major}.x.x"),
Self::MajorMinor(major, minor) => write!(f, "v{}.{}.x", major, minor), Self::MajorMinor(major, minor) => write!(f, "v{major}.{minor}.x"),
} }
} }
} }

4
src/user_version_reader.rs

@ -14,8 +14,8 @@ impl UserVersionReader {
pub fn into_user_version(self, config: &FnmConfig) -> Option<UserVersion> { pub fn into_user_version(self, config: &FnmConfig) -> Option<UserVersion> {
match self { match self {
Self::Direct(uv) => Some(uv), Self::Direct(uv) => Some(uv),
Self::Path(pathbuf) if pathbuf.is_file() => get_user_version_for_file(&pathbuf), Self::Path(pathbuf) if pathbuf.is_file() => get_user_version_for_file(pathbuf),
Self::Path(pathbuf) => get_user_version_for_directory(&pathbuf, config), Self::Path(pathbuf) => get_user_version_for_directory(pathbuf, config),
} }
} }
} }

8
src/version.rs

@ -53,7 +53,7 @@ impl Version {
} }
pub fn v_str(&self) -> String { pub fn v_str(&self) -> String {
format!("{}", self) format!("{self}")
} }
pub fn installation_path(&self, config: &config::FnmConfig) -> std::path::PathBuf { pub fn installation_path(&self, config: &config::FnmConfig) -> std::path::PathBuf {
@ -91,9 +91,9 @@ impl std::fmt::Display for Version {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Self::Bypassed => write!(f, "{}", system_version::display_name()), Self::Bypassed => write!(f, "{}", system_version::display_name()),
Self::Lts(lts) => write!(f, "lts-{}", lts), Self::Lts(lts) => write!(f, "lts-{lts}"),
Self::Semver(semver) => write!(f, "v{}", semver), Self::Semver(semver) => write!(f, "v{semver}"),
Self::Alias(alias) => write!(f, "{}", alias), Self::Alias(alias) => write!(f, "{alias}"),
Self::Latest => write!(f, "latest"), Self::Latest => write!(f, "latest"),
} }
} }

Loading…
Cancel
Save