Skip to content

Commit

Permalink
Fix Clippy errors (#885)
Browse files Browse the repository at this point in the history
* cargo clippy --fix

* cargo fmt
  • Loading branch information
Schniz authored Dec 16, 2022
1 parent d3841ad commit 7f9ed66
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"))),
}
}
}
Expand All @@ -65,7 +65,7 @@ impl std::fmt::Display for Arch {
Arch::S390x => String::from("s390x"),
};

write!(f, "{}", arch_str)
write!(f, "{arch_str}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 1 addition & 1 deletion src/commands/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Command for Current {
Some(ver) => ver.v_str(),
None => "none".into(),
};
println!("{}", version_string);
println!("{version_string}");
Ok(())
}
}
4 changes: 2 additions & 2 deletions src/commands/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/ls_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion src/commands/ls_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/directory_portal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion src/lts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/remote_node_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/shell/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
4 changes: 2 additions & 2 deletions src/shell/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/shell/powershell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/shell/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}",)),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/shell/windows_cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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} $*",))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/shell/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
4 changes: 2 additions & 2 deletions src/user_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/user_version_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"),
}
}
Expand Down

1 comment on commit 7f9ed66

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux Benchmarks

benchmark current value last value diff trend
fnm_basic/median 20.22ms 20.35ms -0.13ms

fnm_basic/max 22.6ms 30.63ms -8.04ms

fnm_basic/mean 20.29ms 20.45ms -0.17ms

fnm_basic/min 19.56ms 19.87ms -0.31ms

fnm_basic/stddev 0.45ms 0.95ms -0.49ms

binary size 6772kb 6788kb -16kb

Please sign in to comment.