Skip to content

Commit 4cf582e

Browse files
authored
fix: Clippy warnings: string formatting, match arms, unused imports, dead_code in tests (#24)
1 parent ecd9bc3 commit 4cf582e

20 files changed

Lines changed: 128 additions & 130 deletions

File tree

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ coverage/
2828

2929
# Crash dumps
3030
**/*.core
31+
32+
# coverage data
33+
**/*.profraw

‎backpack/cli/src/commands/maintain/mod.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ use clap::Parser;
22
use rootcause::hooks::Hooks;
33
use rootcause_backtrace::BacktraceCollector;
44
use tracing::instrument;
5-
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
65

76
use github_bot_lib::cli::Args;
87
use github_bot_lib::github;
9-
use github_bot_lib::log::{LogFormat, Printer, ScreenLogger, SimpleLogger, Verbosity};
108

119
#[instrument(level = "debug", target = "errors::rootcause", name = "run")]
1210
pub fn run(repo: String, action: &Option<String>) -> anyhow::Result<()> {

‎backpack/cli/src/main.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ async fn main() -> anyhow::Result<()> {
193193
)
194194
.await;
195195

196-
wip::run(*no_push, *no_diff, *rewind);
196+
if let Err(e) = wip::run(*no_push, *no_diff, *rewind) {
197+
logger.err(&format!("{e}"));
198+
}
197199

198200
plugins::broadcast_event(&plugins, Event::CliCommandExecutionEnd).await;
199201

‎backpack/lib/src/cli/mod.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub struct Args {
3232
impl Args {
3333
/// The "Smart Default" logic.
3434
/// Priority: 1. CLI Argument, 2. Git Discovery, 3. Hardcoded Fallback
35+
#[must_use]
3536
pub fn resolve_repo(provided: &Option<String>) -> String {
3637
if let Some(repo) = provided {
3738
return repo.clone();
@@ -58,7 +59,7 @@ impl Args {
5859
if parts.len() >= 2 {
5960
let repo_name = parts.last()?;
6061
let owner = parts.get(parts.len() - 2)?;
61-
return Some(format!("{}/{}", owner, repo_name));
62+
return Some(format!("{owner}/{repo_name}"));
6263
}
6364
}
6465
None

‎backpack/lib/src/ghk/app.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ pub fn run(cli: Args) -> Result<()> {
2121

2222
// Save config to mark first run complete
2323
let cfg = config::Config::default();
24-
if let Err(_e) = cfg.save() {
24+
if let Err(e) = cfg.save() {
2525
// In production, we might want to log this differently.
2626
#[cfg(debug_assertions)]
27-
eprintln!("Debug: Failed to save config: {}", _e);
27+
eprintln!("Debug: Failed to save config: {e}");
2828
}
2929
}
3030

@@ -52,7 +52,10 @@ pub fn run(cli: Args) -> Result<()> {
5252
GitCommands::Ignore { template } => crate::ghk::commands::ignore::run(template),
5353
GitCommands::License { kind } => crate::ghk::commands::license::run(kind),
5454
GitCommands::Branch { name } => crate::ghk::commands::branch::run(name),
55-
GitCommands::Completions { shell } => crate::ghk::commands::completions::run(shell),
55+
GitCommands::Completions { shell } => {
56+
crate::ghk::commands::completions::run(shell);
57+
Ok(())
58+
}
5659
},
5760
_ => Ok(()),
5861
}

‎backpack/lib/src/ghk/commands/branch.rs‎

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,46 @@ pub fn run(name: Option<String>) -> Result<()> {
88
bail!("Not a git repository");
99
}
1010

11-
match name {
11+
if let Some(branch) = name {
1212
// Switch to branch
13-
Some(branch) => {
14-
util::info(&format!("Switching to {branch}..."));
13+
util::info(&format!("Switching to {branch}..."));
1514

16-
let status = Command::new("git").args(["checkout", &branch]).status()?;
15+
let status = Command::new("git").args(["checkout", &branch]).status()?;
16+
17+
if status.success() {
18+
util::ok(&format!("Now on {branch}"));
19+
} else {
20+
// Maybe it's a new branch?
21+
util::info("Branch not found, creating it...");
22+
let status = Command::new("git")
23+
.args(["checkout", "-b", &branch])
24+
.status()?;
1725

1826
if status.success() {
19-
util::ok(&format!("Now on {branch}"));
27+
util::ok(&format!("Created and switched to {branch}"));
2028
} else {
21-
// Maybe it's a new branch?
22-
util::info("Branch not found, creating it...");
23-
let status = Command::new("git")
24-
.args(["checkout", "-b", &branch])
25-
.status()?;
26-
27-
if status.success() {
28-
util::ok(&format!("Created and switched to {branch}"));
29-
} else {
30-
util::err("Could not switch branch");
31-
}
29+
util::err("Could not switch branch");
3230
}
3331
}
32+
} else {
3433
// List branches
35-
None => {
36-
let current = git::currentbranch().unwrap_or_default();
37-
38-
let output = Command::new("git").args(["branch", "--list"]).output()?;
39-
40-
let text = String::from_utf8_lossy(&output.stdout);
41-
42-
println!();
43-
util::info("Branches:");
44-
for line in text.lines() {
45-
let name = line.trim().trim_start_matches("* ");
46-
if name == current {
47-
println!(" \x1b[32m▶ {}\x1b[0m (current)", name);
48-
} else {
49-
util::dim(&format!(" {name}"));
50-
}
34+
let current = git::currentbranch().unwrap_or_default();
35+
36+
let output = Command::new("git").args(["branch", "--list"]).output()?;
37+
38+
let text = String::from_utf8_lossy(&output.stdout);
39+
40+
println!();
41+
util::info("Branches:");
42+
for line in text.lines() {
43+
let name = line.trim().trim_start_matches("* ");
44+
if name == current {
45+
println!(" \x1b[32m▶ {name}\x1b[0m (current)");
46+
} else {
47+
util::dim(&format!(" {name}"));
5148
}
52-
println!();
5349
}
50+
println!();
5451
}
5552

5653
Ok(())

‎backpack/lib/src/ghk/commands/clone.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ pub fn run(repo: Option<String>, dir: Option<String>) -> Result<()> {
2121
util::info(&format!("Cloning {reponame}..."));
2222
gh::clonerepo(&reponame, dir.as_deref())?;
2323

24-
let dirname =
25-
dir.unwrap_or_else(|| reponame.split('/').last().unwrap_or(&reponame).to_string());
24+
let dirname = dir.unwrap_or_else(|| {
25+
reponame
26+
.split('/')
27+
.next_back()
28+
.unwrap_or(&reponame)
29+
.to_string()
30+
});
2631

2732
util::ok(&format!("Downloaded to '{dirname}'"));
2833
util::dim(&format!("cd {dirname} to start working"));
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use crate::cli::Args;
2-
use anyhow::Result;
2+
33
use clap::CommandFactory;
44
use clap_complete::{Shell, generate};
55
use std::io;
66

7-
pub fn run(shell: Shell) -> Result<()> {
7+
pub fn run(shell: Shell) {
88
let mut cmd = Args::command();
99
generate(shell, &mut cmd, "github-bot", &mut io::stdout());
10-
Ok(())
1110
}

‎backpack/lib/src/ghk/commands/config.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ pub fn run(key: Option<String>, value: Option<String>) -> Result<()> {
1515
" editor = {editor}",
1616
editor = cfg.editor.as_deref().unwrap_or("(default)")
1717
));
18-
util::dim(&format!(" org = {org}", org = cfg.org.as_deref().unwrap_or("")));
18+
util::dim(&format!(
19+
" org = {org}",
20+
org = cfg.org.as_deref().unwrap_or("")
21+
));
1922
println!();
2023
util::dim(&format!("Config file: {}", Config::path().display()));
2124
println!();
2225
}
2326
// Show one setting
2427
(Some(k), None) => match cfg.get(&k) {
25-
Some(v) => println!("{}", v),
28+
Some(v) => println!("{v}"),
2629
None => util::warn(&format!("Unknown setting: {k}")),
2730
},
2831
// Set a value

‎backpack/lib/src/ghk/commands/diff.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub fn run() -> Result<()> {
2727
match origin {
2828
'+' => print!("\x1b[32m{text}\x1b[0m"), // addition
2929
'-' => print!("\x1b[31m{text}\x1b[0m"), // deletion
30-
' ' => print!("{text}"), // context
3130

3231
// hunk header
3332
'H' => print!("\x1b[1;36m{text}\x1b[0m"),
@@ -38,7 +37,7 @@ pub fn run() -> Result<()> {
3837
// metadata (index, mode changes, etc.)
3938
'B' | 'M' => print!("\x1b[33m{text}\x1b[0m"),
4039

41-
// fallback
40+
// context or fallback
4241
_ => print!("{text}"),
4342
}
4443

0 commit comments

Comments
 (0)