diff --git a/asyncgit/src/error.rs b/asyncgit/src/error.rs index 0e70c8f8..608b5cc9 100644 --- a/asyncgit/src/error.rs +++ b/asyncgit/src/error.rs @@ -28,10 +28,10 @@ pub enum Error { Git(#[from] git2::Error), #[error("utf8 error:{0}")] - Utf8Error(#[from] FromUtf8Error), + Utf8Conversion(#[from] FromUtf8Error), #[error("TryFromInt error:{0}")] - IntError(#[from] TryFromIntError), + IntConversion(#[from] TryFromIntError), } pub type Result = std::result::Result; diff --git a/asyncgit/src/lib.rs b/asyncgit/src/lib.rs index 40ba1424..6c635f21 100644 --- a/asyncgit/src/lib.rs +++ b/asyncgit/src/lib.rs @@ -4,12 +4,33 @@ #![deny(unsafe_code)] #![deny(unused_imports)] #![deny(unused_must_use)] +#![deny(dead_code)] #![deny(clippy::all)] +#![deny(clippy::cargo)] +#![deny(clippy::pedantic)] +//TODO: +// #![deny(clippy::nursery)] #![deny(clippy::unwrap_used)] #![deny(clippy::panic)] #![deny(clippy::perf)] +#![deny(clippy::match_like_matches_macro)] +#![deny(clippy::needless_update)] +#![allow(clippy::module_name_repetitions)] //TODO: get this in someday since expect still leads us to crashes sometimes // #![deny(clippy::expect_used)] +//TODO: +#![allow(clippy::needless_pass_by_value)] +#![allow(clippy::must_use_candidate)] +#![allow(clippy::missing_errors_doc)] +#![allow(clippy::map_unwrap_or)] +#![allow(clippy::option_if_let_else)] +#![allow(clippy::manual_ok_or)] +#![allow(clippy::doc_markdown)] +#![allow(clippy::cast_possible_wrap)] +#![allow(clippy::cast_sign_loss)] +#![allow(clippy::cast_possible_truncation)] +#![allow(clippy::cast_precision_loss)] +#![allow(clippy::too_many_lines)] pub mod cached; mod commit_files; diff --git a/asyncgit/src/revlog.rs b/asyncgit/src/revlog.rs index ffb11218..87958ecf 100644 --- a/asyncgit/src/revlog.rs +++ b/asyncgit/src/revlog.rs @@ -156,17 +156,16 @@ impl AsyncLog { if res_is_err || entries.len() <= 1 { break; - } else { - Self::notify(&sender); - - let sleep_duration = - if arc_background.load(Ordering::Relaxed) { - SLEEP_BACKGROUND - } else { - SLEEP_FOREGROUND - }; - thread::sleep(sleep_duration); } + Self::notify(&sender); + + let sleep_duration = + if arc_background.load(Ordering::Relaxed) { + SLEEP_BACKGROUND + } else { + SLEEP_FOREGROUND + }; + thread::sleep(sleep_duration); } Ok(()) diff --git a/asyncgit/src/sync/branch/merge_commit.rs b/asyncgit/src/sync/branch/merge_commit.rs index 186c731a..40e436c6 100644 --- a/asyncgit/src/sync/branch/merge_commit.rs +++ b/asyncgit/src/sync/branch/merge_commit.rs @@ -44,7 +44,9 @@ pub fn merge_upstream_commit( repo.merge(&[&annotated_upstream], Some(&mut opt), None)?; - assert!(!repo.index()?.has_conflicts()); + if repo.index()?.has_conflicts() { + return Err(Error::Generic("creates conflicts".into())); + } let signature = crate::sync::commit::signature_allow_undefined_name(&repo)?; diff --git a/asyncgit/src/sync/branch/mod.rs b/asyncgit/src/sync/branch/mod.rs index 8bbbc652..c46318f4 100644 --- a/asyncgit/src/sync/branch/mod.rs +++ b/asyncgit/src/sync/branch/mod.rs @@ -117,7 +117,7 @@ pub fn get_branches_info( .branch_upstream_remote(&reference) .ok() .as_ref() - .and_then(|buf| buf.as_str()) + .and_then(git2::Buf::as_str) .map(String::from); let details = if local { @@ -318,11 +318,10 @@ pub fn delete_branch( let repo = utils::repo(repo_path)?; let branch_as_ref = repo.find_reference(branch_ref)?; let mut branch = git2::Branch::wrap(branch_as_ref); - if !branch.is_head() { - branch.delete()?; - } else { + if branch.is_head() { return Err(Error::Generic("You cannot be on the branch you want to delete, switch branch, then delete this branch".to_string())); } + branch.delete()?; Ok(()) } diff --git a/asyncgit/src/sync/commit_details.rs b/asyncgit/src/sync/commit_details.rs index f9620005..104d5f62 100644 --- a/asyncgit/src/sync/commit_details.rs +++ b/asyncgit/src/sync/commit_details.rs @@ -45,7 +45,7 @@ impl CommitMessage { }; let body: Vec = - lines.map(|line| line.to_string()).collect(); + lines.map(std::string::ToString::to_string).collect(); Self { subject, diff --git a/asyncgit/src/sync/cred.rs b/asyncgit/src/sync/cred.rs index c7690823..4d841d49 100644 --- a/asyncgit/src/sync/cred.rs +++ b/asyncgit/src/sync/cred.rs @@ -72,7 +72,7 @@ pub fn extract_cred_from_url(url: &str) -> BasicAuthCredential { } else { Some(url.username().to_owned()) }, - url.password().map(|pwd| pwd.to_owned()), + url.password().map(std::borrow::ToOwned::to_owned), ) } else { BasicAuthCredential::new(None, None) diff --git a/asyncgit/src/sync/diff.rs b/asyncgit/src/sync/diff.rs index 0ddc469b..4f47d9b4 100644 --- a/asyncgit/src/sync/diff.rs +++ b/asyncgit/src/sync/diff.rs @@ -225,12 +225,13 @@ fn raw_diff_to_file_diff<'a>( match current_hunk { None => current_hunk = Some(hunk_header), - Some(h) if h != hunk_header => { - adder(&h, ¤t_lines); - current_lines.clear(); - current_hunk = Some(hunk_header) + Some(h) => { + if h != hunk_header { + adder(&h, ¤t_lines); + current_lines.clear(); + current_hunk = Some(hunk_header) + } } - _ => (), } let line_type = match line.origin() { diff --git a/asyncgit/src/sync/hooks.rs b/asyncgit/src/sync/hooks.rs index b81bca1b..a74e51f4 100644 --- a/asyncgit/src/sync/hooks.rs +++ b/asyncgit/src/sync/hooks.rs @@ -75,13 +75,14 @@ pub fn hooks_post_commit(repo_path: &str) -> Result { fn work_dir_as_string(repo_path: &str) -> Result { let repo = repo(repo_path)?; - work_dir(&repo)?.to_str().map(|s| s.to_string()).ok_or_else( - || { + work_dir(&repo)? + .to_str() + .map(std::string::ToString::to_string) + .ok_or_else(|| { Error::Generic( "workdir contains invalid utf8".to_string(), ) - }, - ) + }) } fn hook_runable(path: &str, hook: &str) -> bool { diff --git a/asyncgit/src/sync/remotes/push.rs b/asyncgit/src/sync/remotes/push.rs index a7672028..dc8d85f9 100644 --- a/asyncgit/src/sync/remotes/push.rs +++ b/asyncgit/src/sync/remotes/push.rs @@ -74,10 +74,8 @@ impl AsyncProgress for ProgressNotification { current, total, } => match stage { - PackBuilderStage::AddingObjects => { - ProgressPercent::new(current, total) - } - PackBuilderStage::Deltafication => { + PackBuilderStage::AddingObjects + | PackBuilderStage::Deltafication => { ProgressPercent::new(current, total) } }, diff --git a/asyncgit/src/sync/staging/mod.rs b/asyncgit/src/sync/staging/mod.rs index 6e66c38e..355685fa 100644 --- a/asyncgit/src/sync/staging/mod.rs +++ b/asyncgit/src/sync/staging/mod.rs @@ -57,7 +57,7 @@ impl NewFromOldContent { fn finish(mut self, old_lines: &[&str]) -> String { for line in old_lines.iter().skip(self.old_index) { - self.lines.push(line.to_string()); + self.lines.push((*line).to_string()); } let lines = self.lines.join("\n"); if lines.ends_with(NEWLINE) { diff --git a/asyncgit/src/sync/status.rs b/asyncgit/src/sync/status.rs index 891079d6..b2318552 100644 --- a/asyncgit/src/sync/status.rs +++ b/asyncgit/src/sync/status.rs @@ -116,7 +116,7 @@ pub fn get_status( Some(diff) => diff .new_file() .path() - .and_then(|x| x.to_str()) + .and_then(Path::to_str) .map(String::from) .ok_or_else(|| { Error::Generic( diff --git a/asyncgit/src/sync/utils.rs b/asyncgit/src/sync/utils.rs index 944ea00a..70266afa 100644 --- a/asyncgit/src/sync/utils.rs +++ b/asyncgit/src/sync/utils.rs @@ -161,10 +161,10 @@ pub fn get_config_string( Err(_) => return Ok(None), }; - if !entry.has_value() { - Ok(None) + if entry.has_value() { + Ok(entry.value().map(std::string::ToString::to_string)) } else { - Ok(entry.value().map(|s| s.to_string())) + Ok(None) } } diff --git a/src/components/diff.rs b/src/components/diff.rs index 3cf7632e..373f0f60 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -252,25 +252,21 @@ impl DiffComponent { fn copy_selection(&self) { if let Some(diff) = &self.diff { - let lines_to_copy: Vec<&str> = diff - .hunks - .iter() - .flat_map(|hunk| hunk.lines.iter()) - .enumerate() - .filter_map(|(i, line)| { - if self.selection.contains(i) { - Some( - line.content - .trim_matches(|c| { - c == '\n' || c == '\r' - }) - .as_ref(), - ) - } else { - None - } - }) - .collect(); + let lines_to_copy: Vec<&str> = + diff.hunks + .iter() + .flat_map(|hunk| hunk.lines.iter()) + .enumerate() + .filter_map(|(i, line)| { + if self.selection.contains(i) { + Some(line.content.trim_matches(|c| { + c == '\n' || c == '\r' + })) + } else { + None + } + }) + .collect(); try_or_popup!( self, diff --git a/src/main.rs b/src/main.rs index cfae967f..8bb0ffa1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ #![forbid(unsafe_code)] #![deny(unused_imports)] #![deny(unused_must_use)] +#![deny(dead_code)] +#![deny(clippy::all)] #![deny(clippy::cargo)] #![deny(clippy::pedantic)] #![deny(clippy::perf)] @@ -8,6 +10,7 @@ #![deny(clippy::unwrap_used)] #![deny(clippy::panic)] #![deny(clippy::match_like_matches_macro)] +#![deny(clippy::needless_update)] #![allow(clippy::module_name_repetitions)] #![allow(clippy::multiple_crate_versions)]