Skip to content

Commit 53b2c79

Browse files
author
Stephan Dilly
authored
even more clippy restrtictions (#646)
* even more clippy restrtictions
1 parent 988df89 commit 53b2c79

File tree

15 files changed

+76
-56
lines changed

15 files changed

+76
-56
lines changed

asyncgit/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ pub enum Error {
2828
Git(#[from] git2::Error),
2929

3030
#[error("utf8 error:{0}")]
31-
Utf8Error(#[from] FromUtf8Error),
31+
Utf8Conversion(#[from] FromUtf8Error),
3232

3333
#[error("TryFromInt error:{0}")]
34-
IntError(#[from] TryFromIntError),
34+
IntConversion(#[from] TryFromIntError),
3535
}
3636

3737
pub type Result<T> = std::result::Result<T, Error>;

asyncgit/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,33 @@
44
#![deny(unsafe_code)]
55
#![deny(unused_imports)]
66
#![deny(unused_must_use)]
7+
#![deny(dead_code)]
78
#![deny(clippy::all)]
9+
#![deny(clippy::cargo)]
10+
#![deny(clippy::pedantic)]
11+
//TODO:
12+
// #![deny(clippy::nursery)]
813
#![deny(clippy::unwrap_used)]
914
#![deny(clippy::panic)]
1015
#![deny(clippy::perf)]
16+
#![deny(clippy::match_like_matches_macro)]
17+
#![deny(clippy::needless_update)]
18+
#![allow(clippy::module_name_repetitions)]
1119
//TODO: get this in someday since expect still leads us to crashes sometimes
1220
// #![deny(clippy::expect_used)]
21+
//TODO:
22+
#![allow(clippy::needless_pass_by_value)]
23+
#![allow(clippy::must_use_candidate)]
24+
#![allow(clippy::missing_errors_doc)]
25+
#![allow(clippy::map_unwrap_or)]
26+
#![allow(clippy::option_if_let_else)]
27+
#![allow(clippy::manual_ok_or)]
28+
#![allow(clippy::doc_markdown)]
29+
#![allow(clippy::cast_possible_wrap)]
30+
#![allow(clippy::cast_sign_loss)]
31+
#![allow(clippy::cast_possible_truncation)]
32+
#![allow(clippy::cast_precision_loss)]
33+
#![allow(clippy::too_many_lines)]
1334

1435
pub mod cached;
1536
mod commit_files;

asyncgit/src/revlog.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,16 @@ impl AsyncLog {
156156

157157
if res_is_err || entries.len() <= 1 {
158158
break;
159-
} else {
160-
Self::notify(&sender);
161-
162-
let sleep_duration =
163-
if arc_background.load(Ordering::Relaxed) {
164-
SLEEP_BACKGROUND
165-
} else {
166-
SLEEP_FOREGROUND
167-
};
168-
thread::sleep(sleep_duration);
169159
}
160+
Self::notify(&sender);
161+
162+
let sleep_duration =
163+
if arc_background.load(Ordering::Relaxed) {
164+
SLEEP_BACKGROUND
165+
} else {
166+
SLEEP_FOREGROUND
167+
};
168+
thread::sleep(sleep_duration);
170169
}
171170

172171
Ok(())

asyncgit/src/sync/branch/merge_commit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ pub fn merge_upstream_commit(
4444

4545
repo.merge(&[&annotated_upstream], Some(&mut opt), None)?;
4646

47-
assert!(!repo.index()?.has_conflicts());
47+
if repo.index()?.has_conflicts() {
48+
return Err(Error::Generic("creates conflicts".into()));
49+
}
4850

4951
let signature =
5052
crate::sync::commit::signature_allow_undefined_name(&repo)?;

asyncgit/src/sync/branch/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn get_branches_info(
117117
.branch_upstream_remote(&reference)
118118
.ok()
119119
.as_ref()
120-
.and_then(|buf| buf.as_str())
120+
.and_then(git2::Buf::as_str)
121121
.map(String::from);
122122

123123
let details = if local {
@@ -318,11 +318,10 @@ pub fn delete_branch(
318318
let repo = utils::repo(repo_path)?;
319319
let branch_as_ref = repo.find_reference(branch_ref)?;
320320
let mut branch = git2::Branch::wrap(branch_as_ref);
321-
if !branch.is_head() {
322-
branch.delete()?;
323-
} else {
321+
if branch.is_head() {
324322
return Err(Error::Generic("You cannot be on the branch you want to delete, switch branch, then delete this branch".to_string()));
325323
}
324+
branch.delete()?;
326325
Ok(())
327326
}
328327

asyncgit/src/sync/commit_details.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl CommitMessage {
4545
};
4646

4747
let body: Vec<String> =
48-
lines.map(|line| line.to_string()).collect();
48+
lines.map(std::string::ToString::to_string).collect();
4949

5050
Self {
5151
subject,

asyncgit/src/sync/cred.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn extract_cred_from_url(url: &str) -> BasicAuthCredential {
7272
} else {
7373
Some(url.username().to_owned())
7474
},
75-
url.password().map(|pwd| pwd.to_owned()),
75+
url.password().map(std::borrow::ToOwned::to_owned),
7676
)
7777
} else {
7878
BasicAuthCredential::new(None, None)

asyncgit/src/sync/diff.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,13 @@ fn raw_diff_to_file_diff<'a>(
225225

226226
match current_hunk {
227227
None => current_hunk = Some(hunk_header),
228-
Some(h) if h != hunk_header => {
229-
adder(&h, &current_lines);
230-
current_lines.clear();
231-
current_hunk = Some(hunk_header)
228+
Some(h) => {
229+
if h != hunk_header {
230+
adder(&h, &current_lines);
231+
current_lines.clear();
232+
current_hunk = Some(hunk_header)
233+
}
232234
}
233-
_ => (),
234235
}
235236

236237
let line_type = match line.origin() {

asyncgit/src/sync/hooks.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ pub fn hooks_post_commit(repo_path: &str) -> Result<HookResult> {
7575

7676
fn work_dir_as_string(repo_path: &str) -> Result<String> {
7777
let repo = repo(repo_path)?;
78-
work_dir(&repo)?.to_str().map(|s| s.to_string()).ok_or_else(
79-
|| {
78+
work_dir(&repo)?
79+
.to_str()
80+
.map(std::string::ToString::to_string)
81+
.ok_or_else(|| {
8082
Error::Generic(
8183
"workdir contains invalid utf8".to_string(),
8284
)
83-
},
84-
)
85+
})
8586
}
8687

8788
fn hook_runable(path: &str, hook: &str) -> bool {

asyncgit/src/sync/remotes/push.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ impl AsyncProgress for ProgressNotification {
7474
current,
7575
total,
7676
} => match stage {
77-
PackBuilderStage::AddingObjects => {
78-
ProgressPercent::new(current, total)
79-
}
80-
PackBuilderStage::Deltafication => {
77+
PackBuilderStage::AddingObjects
78+
| PackBuilderStage::Deltafication => {
8179
ProgressPercent::new(current, total)
8280
}
8381
},

0 commit comments

Comments
 (0)