From 90fb2bbb72be8a371faa5f2adce728a5401b73fb Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 12 Feb 2026 16:21:38 +0000 Subject: style: apply cargo clippy and fmt fixes Reorganize imports and fix formatting issues flagged by clippy and rustfmt. --- src/bin/ngit/sub_commands/apply.rs | 32 ++++++++++++++++++-------------- src/bin/ngit/sub_commands/init.rs | 14 ++++++-------- src/bin/ngit/sub_commands/list.rs | 20 +++++++++++++------- 3 files changed, 37 insertions(+), 29 deletions(-) (limited to 'src/bin/ngit/sub_commands') diff --git a/src/bin/ngit/sub_commands/apply.rs b/src/bin/ngit/sub_commands/apply.rs index fd9eae3..4ed6caa 100644 --- a/src/bin/ngit/sub_commands/apply.rs +++ b/src/bin/ngit/sub_commands/apply.rs @@ -4,14 +4,18 @@ use std::{ }; use anyhow::{Context, Result, bail}; -use ngit::client::get_all_proposal_patch_pr_pr_update_events_from_cache; -use ngit::git_events::get_pr_tip_event_or_most_recent_patch_with_ancestors; +use ngit::{ + client::get_all_proposal_patch_pr_pr_update_events_from_cache, + git_events::get_pr_tip_event_or_most_recent_patch_with_ancestors, +}; use nostr::nips::nip19::Nip19; use nostr_sdk::{EventId, FromBech32}; -use crate::client::{Client, Connect, fetching_with_report, get_repo_ref_from_cache}; -use crate::git::{Repo, RepoActions}; -use crate::repo_ref::get_repo_coordinates_when_remote_unknown; +use crate::{ + client::{Client, Connect, fetching_with_report, get_repo_ref_from_cache}, + git::{Repo, RepoActions}, + repo_ref::get_repo_coordinates_when_remote_unknown, +}; fn run_git_fetch(remote_name: &str) -> Result<()> { println!("fetching from {remote_name}..."); @@ -55,11 +59,8 @@ pub async fn launch(id: &str, stdout: bool) -> Result<()> { let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; let proposals_and_revisions: Vec = - ngit::client::get_proposals_and_revisions_from_cache( - git_repo_path, - repo_ref.coordinates(), - ) - .await?; + ngit::client::get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) + .await?; let proposal = proposals_and_revisions .iter() @@ -79,10 +80,13 @@ pub async fn launch(id: &str, stdout: bool) -> Result<()> { let patches = get_pr_tip_event_or_most_recent_patch_with_ancestors(commits_events.clone()) .context("failed to find any PR or patch events on this proposal")?; - if patches - .iter() - .any(|e| [ngit::git_events::KIND_PULL_REQUEST, ngit::git_events::KIND_PULL_REQUEST_UPDATE].contains(&e.kind)) - { + if patches.iter().any(|e| { + [ + ngit::git_events::KIND_PULL_REQUEST, + ngit::git_events::KIND_PULL_REQUEST_UPDATE, + ] + .contains(&e.kind) + }) { bail!( "this proposal uses PR format (not patches). Use `ngit checkout {}` instead.", event_id.to_hex() diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 2f34ecb..087fa14 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -231,7 +231,10 @@ fn validate_hashtag(s: &str) -> Result { if trimmed.is_empty() { bail!("hashtag cannot be empty"); } - if !trimmed.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-') { + if !trimmed + .chars() + .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-') + { bail!("hashtag can only contain lowercase letters (a-z), digits (0-9), and hyphens (-)"); } if trimmed.starts_with('-') || trimmed.ends_with('-') { @@ -246,15 +249,10 @@ fn validate_hashtag(s: &str) -> Result { /// Resolve the `hashtags` field from args or existing announcement. fn resolve_hashtags(args_hashtag: &[String], state: &InitState) -> Result> { if !args_hashtag.is_empty() { - return args_hashtag - .iter() - .map(|h| validate_hashtag(h)) - .collect(); + return args_hashtag.iter().map(|h| validate_hashtag(h)).collect(); } if let Some(rr) = state.repo_ref() { - return Ok( - latest_event_repo_ref(rr).map_or_else(|| rr.hashtags.clone(), |lr| lr.hashtags), - ); + return Ok(latest_event_repo_ref(rr).map_or_else(|| rr.hashtags.clone(), |lr| lr.hashtags)); } Ok(vec![]) } diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs index 6d78a1f..b008cf0 100644 --- a/src/bin/ngit/sub_commands/list.rs +++ b/src/bin/ngit/sub_commands/list.rs @@ -1,5 +1,7 @@ use std::{ - collections::HashSet, io::Write, ops::Add, + collections::HashSet, + io::Write, + ops::Add, process::{Command, Stdio}, }; @@ -16,9 +18,11 @@ use ngit::{ }, repo_ref::{RepoRef, is_grasp_server_in_list}, }; -use nostr::filter::{Alphabet, SingleLetterTag}; -use nostr::nips::nip19::Nip19; -use nostr::{FromBech32, ToBech32}; +use nostr::{ + FromBech32, ToBech32, + filter::{Alphabet, SingleLetterTag}, + nips::nip19::Nip19, +}; use nostr_sdk::Kind; use crate::{ @@ -242,8 +246,7 @@ fn show_proposal_details( json: bool, ) -> Result<()> { let target_id = if event_id_or_nevent.starts_with("nevent") { - let nip19 = Nip19::from_bech32(event_id_or_nevent) - .context("failed to parse nevent")?; + let nip19 = Nip19::from_bech32(event_id_or_nevent).context("failed to parse nevent")?; match nip19 { Nip19::EventId(id) => id, Nip19::Event(event) => event.event_id, @@ -294,7 +297,10 @@ fn show_proposal_details( } println!(); - println!("To checkout: ngit checkout {}", &proposal.id.to_string()[..7]); + println!( + "To checkout: ngit checkout {}", + &proposal.id.to_string()[..7] + ); println!("To apply: ngit apply {}", &proposal.id.to_string()[..7]); Ok(()) -- cgit v1.2.3