Skip to content

Commit e2866d7

Browse files
committed
style(clippy): fix all clippy lints
1 parent 8fbf6df commit e2866d7

17 files changed

+273
-184
lines changed

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,14 @@ pub async fn start(config: ConfigFile) -> Result<()> {
283283
Cli::Erase => erase_handler::start(config.config).await?,
284284
Cli::List => list_handler::start(config.config).await?,
285285
Cli::Complete { shell } => {
286-
clap_complete::generate(shell, &mut Cli::command(), "bob", &mut std::io::stdout())
286+
clap_complete::generate(shell, &mut Cli::command(), "bob", &mut std::io::stdout());
287287
}
288288
Cli::Update(data) => {
289289
update_handler::start(data, &client, config).await?;
290290
}
291291
Cli::ListRemote => list_remote_handler::start(config.config, client).await?,
292292
Cli::Run { version, args } => {
293-
run_handler::start(&version, &args, &client, &config.config).await?
293+
run_handler::start(&version, &args, &client, &config.config).await?;
294294
}
295295
}
296296

src/github_requests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub async fn get_upstream_nightly(client: &Client) -> Result<UpstreamVersion> {
212212
)
213213
.await?;
214214

215-
deserialize_response(response)
215+
deserialize_response(&response)
216216
}
217217

218218
/// Fetches the commits for the nightly version from the GitHub API.
@@ -253,7 +253,7 @@ pub async fn get_commits_for_nightly(
253253
let response = make_github_request(client, format!(
254254
"https://api.github.com/repos/neovim/neovim/commits?since={since}&until={until}&per_page=100")).await?;
255255

256-
deserialize_response(response)
256+
deserialize_response(&response)
257257
}
258258

259259
/// Deserializes a JSON response from the GitHub API.
@@ -282,8 +282,8 @@ pub async fn get_commits_for_nightly(
282282
/// Err(e) => println!("An error occurred: {:?}", e),
283283
/// }
284284
/// ```
285-
pub fn deserialize_response<T: DeserializeOwned>(response: String) -> Result<T> {
286-
let value: serde_json::Value = serde_json::from_str(&response)?;
285+
pub fn deserialize_response<T: DeserializeOwned>(response: &str) -> Result<T> {
286+
let value: serde_json::Value = serde_json::from_str(response)?;
287287

288288
if value.get("message").is_some() {
289289
let result: ErrorResponse = serde_json::from_value(value)?;

src/handlers/erase_handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use crate::{
4242
///
4343
/// * [`directories::get_downloads_directory`](src/helpers/directories.rs)
4444
/// * [`directories::get_installation_directory`](src/helpers/directories.rs)
45+
#[allow(clippy::items_after_statements)]
4546
pub async fn start(config: Config) -> Result<()> {
4647
let downloads = directories::get_downloads_directory(&config).await?;
4748
let mut installation_dir = directories::get_installation_directory(&config).await?;

src/handlers/install_handler.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use reqwest::Client;
1212
use semver::Version;
1313
use std::cmp::min;
1414
use std::env;
15+
use std::fmt::Write;
1516
use std::path::Path;
1617
use std::process::Stdio;
1718
use tokio::fs::File;
@@ -61,6 +62,7 @@ use super::{InstallResult, PostDownloadVersionType};
6162
/// let config = Config::default();
6263
/// let result = start(&mut version, &client, &config).await;
6364
/// ```
65+
#[allow(clippy::too_many_lines)]
6466
pub async fn start(
6567
version: &ParsedVersion,
6668
client: &Client,
@@ -108,7 +110,7 @@ pub async fn start(
108110

109111
match config.config.enable_nightly_info {
110112
Some(boolean) if boolean => {
111-
print_commits(client, &local_nightly, upstream_nightly).await?
113+
print_commits(client, &local_nightly, upstream_nightly).await?;
112114
}
113115
None => print_commits(client, &local_nightly, upstream_nightly).await?,
114116
_ => (),
@@ -132,7 +134,7 @@ pub async fn start(
132134

133135
if let PostDownloadVersionType::Standard(downloaded_archive) = downloaded_archive {
134136
if version.semver.is_some() && version.semver.as_ref().unwrap() <= &Version::new(0, 4, 4) {
135-
unarchive::start(downloaded_archive).await?
137+
unarchive::start(&downloaded_archive).await?;
136138
} else {
137139
let downloaded_checksum =
138140
download_version(client, version, root, &config.config, true).await?;
@@ -147,7 +149,7 @@ pub async fn start(
147149
downloaded_checksum.file_name, downloaded_checksum.file_format
148150
));
149151

150-
let platform = helpers::get_platform_name(&version.semver);
152+
let platform = helpers::get_platform_name(version.semver.as_ref());
151153

152154
if !sha256cmp(
153155
&archive_path,
@@ -161,10 +163,10 @@ pub async fn start(
161163

162164
info!("Checksum matched!");
163165
tokio::fs::remove_file(checksum_path).await?;
164-
unarchive::start(downloaded_archive).await?
166+
unarchive::start(&downloaded_archive).await?;
165167
} else if let PostDownloadVersionType::None = downloaded_checksum {
166168
warn!("No checksum provided, skipping checksum verification");
167-
unarchive::start(downloaded_archive).await?
169+
unarchive::start(&downloaded_archive).await?;
168170
}
169171
}
170172
}
@@ -250,8 +252,7 @@ async fn handle_rollback(config: &Config) -> Result<()> {
250252

251253
info!("Creating rollback: nightly-{id}");
252254
filesystem::copy_dir_async("nightly", format!("nightly-{id}")).await?;
253-
254-
json_struct.tag_name += &format!("-{id}");
255+
let _ = write!(json_struct.tag_name, "-{id}");
255256

256257
let json_file = serde_json::to_string(&json_struct)?;
257258
fs::write(format!("nightly-{id}/bob.json"), json_file).await?;
@@ -311,7 +312,7 @@ async fn print_commits(
311312
/// This function sends a request to download the specified version of Neovim based on the version type.
312313
/// If the version type is Normal, Nightly, or Latest, it sends a request to download the version.
313314
/// If the version type is Hash, it handles building from the source.
314-
/// If the version type is NightlyRollback, it does nothing.
315+
/// If the version type is `NightlyRollback`, it does nothing.
315316
///
316317
/// # Arguments
317318
///
@@ -389,7 +390,7 @@ async fn download_version(
389390
pbw.finish(root, file_type.clone().into());
390391

391392
Ok(PostDownloadVersionType::Standard(LocalVersion {
392-
file_name: version.tag_name.to_owned(),
393+
file_name: version.tag_name.clone(),
393394
file_format: file_type.to_string(),
394395
path: root.display().to_string(),
395396
semver: version.semver.clone(),
@@ -508,6 +509,7 @@ fn file_type_ext(version: &ParsedVersion, get_sha256sum: bool) -> std::borrow::C
508509
/// let config = Config::default();
509510
/// let result = handle_building_from_source(&version, &config).await;
510511
/// ```
512+
#[allow(clippy::too_many_lines)]
511513
#[rustfmt::skip]
512514
async fn handle_building_from_source(version: &ParsedVersion, config: &Config) -> Result<PostDownloadVersionType> {
513515
cfg_if::cfg_if! {
@@ -560,7 +562,7 @@ async fn handle_building_from_source(version: &ParsedVersion, config: &Config) -
560562
std::io::ErrorKind::NotFound => {
561563
fs::create_dir(dirname).await?;
562564
}
563-
_ => return Err(anyhow!("unknown error: {}", error)),
565+
_ => return Err(anyhow!("unknown error: {error}")),
564566
}
565567
}
566568

@@ -575,24 +577,24 @@ async fn handle_building_from_source(version: &ParsedVersion, config: &Config) -
575577
.await?;
576578
}
577579

578-
_ => return Err(anyhow!("unknown error: {}", error)),
580+
_ => return Err(anyhow!("unknown error: {error}")),
579581
}
580-
};
582+
}
581583

582584
{
583585

584586
// check if repo has a remote
585587
let remote = Command::new("git").arg("remote").arg("get-url").arg("origin").stdout(Stdio::null())
586588
.spawn()?.wait().await?;
587-
if !remote.success() {
588-
// add neovim's remote
589-
Command::new("git").arg("remote").arg("add").arg("origin").arg("https://github.com/neovim/neovim.git")
589+
if remote.success() {
590+
// set neovim's remote
591+
Command::new("git").arg("remote").arg("set-url").arg("origin").arg("https://github.com/neovim/neovim.git")
590592
.spawn()?.wait().await?;
591593
} else {
592-
// set neovim's remote otherwise
593-
Command::new("git").arg("remote").arg("set-url").arg("origin").arg("https://github.com/neovim/neovim.git")
594+
// add neovim's remote otherwise
595+
Command::new("git").arg("remote").arg("add").arg("origin").arg("https://github.com/neovim/neovim.git")
594596
.spawn()?.wait().await?;
595-
};
597+
}
596598
// fetch version from origin
597599
let fetch_successful = Command::new("git").arg("fetch").arg("--depth").arg("1").arg("origin").arg(&version.non_parsed_string)
598600
.spawn()?.wait().await?.success();
@@ -672,7 +674,7 @@ where
672674
///
673675
/// # Behavior
674676
///
675-
/// The function constructs the download URL based on the provided `version` and `config.github_mirror`. If `config.github_mirror` is `None`, it defaults to "https://github.com".
677+
/// The function constructs the download URL based on the provided `version` and `config.github_mirror`. If `config.github_mirror` is `None`, it defaults to `<https://github.com>`.
676678
///
677679
/// It then sends a GET request to the constructed URL with the header "user-agent" set to "bob".
678680
///
@@ -702,13 +704,13 @@ async fn send_request(
702704
version: &ParsedVersion,
703705
get_sha256sum: bool,
704706
) -> Result<reqwest::Response, reqwest::Error> {
705-
let platform = helpers::get_platform_name(&version.semver);
707+
let platform = helpers::get_platform_name(version.semver.as_ref());
706708
let file_type = crate::FILETYPE_EXT;
707709

708-
let url = config
709-
.github_mirror
710-
.as_ref()
711-
.map_or_else(|| "https://github.com".to_string(), |val| val.to_string());
710+
let url = config.github_mirror.as_ref().map_or_else(
711+
|| "https://github.com".to_string(),
712+
std::string::ToString::to_string,
713+
);
712714

713715
let version_tag = &version.tag_name;
714716
let request_url = if get_sha256sum {

src/handlers/list_remote_handler.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub async fn start(config: Config, client: Client) -> Result<()> {
6565
.map(|entry| entry.path())
6666
.collect();
6767

68-
let versions: Vec<RemoteVersion> = deserialize_response(response)?;
68+
let versions: Vec<RemoteVersion> = deserialize_response(&response)?;
6969
let filtered_versions: Vec<RemoteVersion> = versions
7070
.into_iter()
7171
.filter(|v| v.name.starts_with('v'))
@@ -109,9 +109,8 @@ pub async fn start(config: Config, client: Client) -> Result<()> {
109109
if let Err(e) = write_result {
110110
if e.kind() == io::ErrorKind::BrokenPipe {
111111
return Ok(());
112-
} else {
113-
return Err(e.into());
114112
}
113+
return Err(e.into());
115114
}
116115

117116
if version_installed {

0 commit comments

Comments
 (0)