Skip to content

Commit 02cc895

Browse files
authored
Run Clippy on the repo and clean up its suggestions (#27)
1 parent 9762dbb commit 02cc895

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

src/branches.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct Branches {
88

99
impl Branches {
1010
pub fn new(branches: Vec<String>) -> Branches {
11-
let trimmed_string = branches.join("\n").trim_right_matches("\n").into();
11+
let trimmed_string = branches.join("\n").trim_right_matches('\n').into();
1212

1313
Branches {
1414
string: trimmed_string,
@@ -28,7 +28,7 @@ impl Branches {
2828
};
2929

3030
let chunks = self.vec.chunks(col_count);
31-
let mut col_indices = vec![];
31+
let mut col_indices = [0; 3];
3232

3333
for i in 1..col_count {
3434
let index = i - 1;
@@ -40,7 +40,7 @@ impl Branches {
4040
}
4141
}).max().unwrap();
4242
let next_col_start = largest_col_member + COLUMN_SPACER_LENGTH;
43-
col_indices.push(next_col_start);
43+
col_indices[i-1] = next_col_start;
4444
}
4545

4646
let rows: Vec<String> = self.vec.chunks(col_count)
@@ -50,7 +50,7 @@ impl Branches {
5050
}
5151
}
5252

53-
fn make_row(chunks: &[String], col_indices: &Vec<usize>) -> String {
53+
fn make_row(chunks: &[String], col_indices: &[usize]) -> String {
5454
match chunks.len() {
5555
1 => { chunks[0].clone() },
5656
2 => { format!("{b1:0$}{b2}", col_indices[0], b1 = chunks[0], b2 = chunks[1]) },

src/commands.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn delete_local_branches(branches: &Branches) -> String {
5757
let xargs = spawn_piped(&["xargs", "git", "branch", "-D"]);
5858

5959
{
60-
xargs.stdin.unwrap().write_all(&branches.string.as_bytes()).unwrap()
60+
xargs.stdin.unwrap().write_all(branches.string.as_bytes()).unwrap()
6161
}
6262

6363
let mut branches_delete_result = String::new();
@@ -71,7 +71,7 @@ pub fn delete_remote_branches(branches: &Branches, git_options: &GitOptions) ->
7171
let remote_branches_cmd = run_command(&["git", "branch", "-r"]);
7272

7373
let s = String::from_utf8(remote_branches_cmd.stdout).unwrap();
74-
let all_remote_branches = s.split("\n").collect::<Vec<&str>>();
74+
let all_remote_branches = s.split('\n').collect::<Vec<&str>>();
7575
let origin_for_trim = &format!("{}/", &git_options.remote)[..];
7676
let b_tree_remotes = all_remote_branches
7777
.iter()
@@ -94,7 +94,7 @@ pub fn delete_remote_branches(branches: &Branches, git_options: &GitOptions) ->
9494
xargs.stderr.unwrap().read_to_string(&mut stderr).unwrap();
9595

9696
// Everything is written to stderr, so we need to process that
97-
let split = stderr.split("\n");
97+
let split = stderr.split('\n');
9898
let vec: Vec<&str> = split.collect();
9999
let mut output = vec![];
100100
for s in vec {

src/main.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn main() {
6060

6161
let branches = merged_branches(&git_options);
6262

63-
if branches.string.len() == 0 {
63+
if branches.string.is_empty() {
6464
println!("No branches to delete, you're clean!");
6565
return;
6666
}
@@ -75,9 +75,7 @@ fn main() {
7575
io::stdin().read_line(&mut input).unwrap();
7676

7777
match input.to_lowercase().as_ref() {
78-
"y\n" => (),
79-
"yes\n" => (),
80-
"\n" => (),
78+
"y\n" | "yes\n" | "\n" => (),
8179
_ => return,
8280
}
8381
}
@@ -116,7 +114,7 @@ fn merged_branches(git_options: &GitOptions) -> Branches {
116114

117115
let mut merged_branches_output = String::new();
118116
merged_branches_filter.stdout.unwrap().read_to_string(&mut merged_branches_output).unwrap();
119-
let merged_branches = merged_branches_output.split("\n").map(|b| b.trim().into()).collect::<Vec<String>>();
117+
let merged_branches = merged_branches_output.split('\n').map(|b| b.trim().into()).collect::<Vec<String>>();
120118

121119
let local_branches_regex = format!("\\*{branch}|\\s{branch}", branch = &git_options.base_branch);
122120
let local_branches_filter = spawn_piped(&["grep", "-vE", &local_branches_regex]);
@@ -128,7 +126,7 @@ fn merged_branches(git_options: &GitOptions) -> Branches {
128126

129127
let mut local_branches_output = String::new();
130128
local_branches_filter.stdout.unwrap().read_to_string(&mut local_branches_output).unwrap();
131-
let local_branches = local_branches_output.split("\n").map(|b| b.trim().into()).collect::<Vec<String>>();
129+
let local_branches = local_branches_output.split('\n').map(|b| b.trim().into()).collect::<Vec<String>>();
132130

133131
let remote_branches_regex = format!("(HEAD|{})", &git_options.base_branch);
134132
let remote_branches_filter = spawn_piped(&["grep", "-vE", &remote_branches_regex]);
@@ -140,7 +138,7 @@ fn merged_branches(git_options: &GitOptions) -> Branches {
140138

141139
let mut remote_branches_output = String::new();
142140
remote_branches_filter.stdout.unwrap().read_to_string(&mut remote_branches_output).unwrap();
143-
let remote_branches = remote_branches_output.split("\n").map(|b| b.trim().into()).collect::<Vec<String>>();
141+
let remote_branches = remote_branches_output.split('\n').map(|b| b.trim().into()).collect::<Vec<String>>();
144142

145143
for branch in local_branches {
146144
// First check if the local branch doesn't exist in the remote, it's the cheapest and easiest

src/options.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ pub use self::DeleteOption::*;
1717

1818
impl DeleteOption {
1919
pub fn new(opts: &Matches) -> DeleteOption {
20-
return if opts.opt_present("l") {
20+
if opts.opt_present("l") {
2121
Local
2222
} else if opts.opt_present("r") {
2323
Remote
2424
} else {
2525
Both
26-
};
26+
}
2727
}
2828

2929
pub fn warning_message(&self) -> String {
@@ -79,7 +79,7 @@ impl GitOptions {
7979
let mut s = String::new();
8080
grep.stdout.unwrap().read_to_string(&mut s).unwrap();
8181

82-
if s.len() == 0 {
82+
if s.is_empty() {
8383
return Err(GitCleanError::InvalidRemoteError)
8484
}
8585

tests/support.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct Project {
5151

5252
impl Project {
5353
pub fn setup_command(&self, command: &str) -> TestCommandResult {
54-
let command_pieces = command.split(" ").collect::<Vec<&str>>();
54+
let command_pieces = command.split(' ').collect::<Vec<&str>>();
5555
let result = TestCommand::new(
5656
&self.path(),
5757
command_pieces[1..].to_vec(),
@@ -66,7 +66,7 @@ impl Project {
6666
}
6767

6868
pub fn remote_setup_command(&self, command: &str) -> TestCommandResult {
69-
let command_pieces = command.split(" ").collect::<Vec<&str>>();
69+
let command_pieces = command.split(' ').collect::<Vec<&str>>();
7070
let result = TestCommand::new(
7171
&self.remote_path(),
7272
command_pieces[1..].to_vec(),
@@ -81,11 +81,13 @@ impl Project {
8181
}
8282

8383
pub fn batch_setup_commands(&self, commands: &[&str]) {
84-
commands.iter().map(|command| self.setup_command(command)).collect::<Vec<TestCommandResult>>();
84+
for command in commands.iter() {
85+
self.setup_command(command);
86+
};
8587
}
8688

8789
pub fn git_clean_command(&self, command: &str) -> TestCommand {
88-
let command_pieces = command.split(" ").collect::<Vec<&str>>();
90+
let command_pieces = command.split(' ').collect::<Vec<&str>>();
8991
TestCommand::new(&self.path(), command_pieces, path_to_git_clean())
9092
}
9193

@@ -134,7 +136,7 @@ impl TestCommand {
134136

135137
pub fn run(&self) -> TestCommandResult {
136138
let mut command = Command::new(&self.top_level_command);
137-
for &(ref k, ref v) in self.envs.iter() {
139+
for &(ref k, ref v) in &self.envs {
138140
command.env(&k, &v);
139141
}
140142
let output = command

0 commit comments

Comments
 (0)