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( @@ -17,13 +17,13 @@ pub fn create_alias(
let alias_dir = aliases_dir.join(common_name);
remove_symlink_dir(&alias_dir).ok();
symlink_dir(&version_dir, &alias_dir)?;
symlink_dir(version_dir, &alias_dir)?;
Ok(())
}
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(|x| TryInto::<StoredAlias>::try_into(x.path().as_path()).ok())
.collect();

4
src/arch.rs

@ -48,7 +48,7 @@ impl std::str::FromStr for Arch { @@ -48,7 +48,7 @@ impl std::str::FromStr for Arch {
"ppc64le" => Ok(Arch::Ppc64le),
"ppc64" => Ok(Arch::Ppc64),
"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 { @@ -65,7 +65,7 @@ impl std::fmt::Display for Arch {
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 { @@ -7,7 +7,7 @@ pub trait Command: Sized {
fn apply(self, config: &FnmConfig) -> Result<(), Self::Error>;
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());
std::process::exit(1);
}

2
src/commands/completions.rs

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

2
src/commands/current.rs

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

4
src/commands/env.rs

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

4
src/commands/ls_local.rs

@ -35,12 +35,12 @@ impl super::command::Command for LsLocal { @@ -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) {
println!("{}", version_str.cyan());
} else {
println!("{}", version_str);
println!("{version_str}");
}
}
Ok(())

2
src/commands/ls_remote.rs

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

2
src/commands/uninstall.rs

@ -92,7 +92,7 @@ pub enum Error { @@ -92,7 +92,7 @@ pub enum Error {
CantInferVersion,
#[error("Can't uninstall system version")]
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> },
#[error("Can't find a matching version")]
CantFindVersion,

2
src/directory_portal.rs

@ -57,7 +57,7 @@ mod tests { @@ -57,7 +57,7 @@ mod tests {
let tempdir = tempdir().expect("Can't generate a temp directory");
let portal = DirectoryPortal::new_in(std::env::temp_dir(), tempdir.path().join("subdir"));
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 file_exists: Vec<_> = target

3
src/downloader.rs

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

2
src/lts.rs

@ -23,7 +23,7 @@ impl Display for LtsType { @@ -23,7 +23,7 @@ impl Display for LtsType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
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 { @@ -72,7 +72,7 @@ pub struct IndexedNodeVersion {
/// use crate::remote_node_index::list;
/// ```
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 mut value: Vec<IndexedNodeVersion> = resp.json()?;
value.sort_by(|a, b| a.version.cmp(&b.version));

4
src/shell/bash.rs

@ -16,11 +16,11 @@ impl Shell for Bash { @@ -16,11 +16,11 @@ impl Shell for Bash {
let path = path
.to_str()
.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 {
format!("export {}={:?}", name, value)
format!("export {name}={value:?}")
}
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 { @@ -16,11 +16,11 @@ impl Shell for Fish {
let path = path
.to_str()
.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 {
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> {

2
src/shell/powershell.rs

@ -22,7 +22,7 @@ impl Shell for PowerShell { @@ -22,7 +22,7 @@ impl Shell for PowerShell {
}
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> {

2
src/shell/shell.rs

@ -27,7 +27,7 @@ impl std::str::FromStr for Box<dyn Shell> { @@ -27,7 +27,7 @@ impl std::str::FromStr for Box<dyn Shell> {
"bash" => Ok(Box::from(super::bash::Bash)),
"fish" => Ok(Box::from(super::fish::Fish)),
"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 { @@ -20,11 +20,11 @@ impl Shell for WindowsCmd {
let new_path = new_path
.to_str()
.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 {
format!("SET {}={}", name, value)
format!("SET {name}={value}")
}
fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String> {
@ -39,7 +39,7 @@ impl Shell for WindowsCmd { @@ -39,7 +39,7 @@ impl Shell for WindowsCmd {
let path = path
.to_str()
.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 { @@ -16,11 +16,11 @@ impl Shell for Zsh {
let path = path
.to_str()
.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 {
format!("export {}={:?}", name, value)
format!("export {name}={value:?}")
}
fn rehash(&self) -> Option<String> {

4
src/user_version.rs

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

4
src/user_version_reader.rs

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

8
src/version.rs

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

Loading…
Cancel
Save