Skip to content

Commit fbdd9ed

Browse files
committed
fix: Clippy warnings: string formatting, match arms, unused imports, dead_code in tests
1 parent 5c5d30f commit fbdd9ed

17 files changed

Lines changed: 91 additions & 105 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/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: 3 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,7 @@ 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 } => { crate::ghk::commands::completions::run(shell); Ok(()) },
5656
},
5757
_ => Ok(()),
5858
}

‎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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ 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(|| reponame.split('/').next_back().unwrap_or(&reponame).to_string());
2625

2726
util::ok(&format!("Downloaded to '{dirname}'"));
2827
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn run(key: Option<String>, value: Option<String>) -> Result<()> {
2222
}
2323
// Show one setting
2424
(Some(k), None) => match cfg.get(&k) {
25-
Some(v) => println!("{}", v),
25+
Some(v) => println!("{v}"),
2626
None => util::warn(&format!("Unknown setting: {k}")),
2727
},
2828
// 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

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::ghk::{git, util};
22
use anyhow::{Result, bail};
33
use dialoguer::Select;
44
use std::fs;
5+
use std::fmt::Write as _;
56

67
const BASE_TEMPLATES: &[(&str, &str)] = &[("core-dumps", "*.core/\n")];
78

@@ -26,17 +27,14 @@ pub fn run(template: Option<String>) -> Result<()> {
2627
}
2728

2829
// Pick template name
29-
let name = match template {
30-
Some(t) => t,
31-
None => {
30+
let name = if let Some(t) = template { t } else {
3231
let names: Vec<&str> = TEMPLATES.iter().map(|(n, _)| *n).collect();
3332
let idx = Select::new()
3433
.with_prompt("Choose template")
3534
.items(&names)
3635
.default(0)
3736
.interact()?;
3837
names[idx].to_string()
39-
}
4038
};
4139

4240
// Find main template content
@@ -48,10 +46,11 @@ pub fn run(template: Option<String>) -> Result<()> {
4846
let existing = fs::read_to_string(path).unwrap_or_default();
4947

5048
// Build final template: main + all base templates
51-
let mut combined = format!("# {}\n{}", name, main_content);
49+
let mut combined = format!("# {name}\n{main_content}");
5250

51+
use std::fmt::Write as _;
5352
for (base_name, base_content) in BASE_TEMPLATES {
54-
combined.push_str(&format!("\n# base: {}\n{}", base_name, base_content));
53+
let _ = write!(combined, "\n# base: {base_name}\n{base_content}");
5554
}
5655

5756
// If .gitignore already contains the first line of the main template, skip
@@ -69,14 +68,11 @@ pub fn run(template: Option<String>) -> Result<()> {
6968
};
7069

7170
fs::write(path, new)?;
72-
util::ok(&format!(
73-
"Added {} template (with base templates) to .gitignore",
74-
name
75-
));
71+
util::ok(&format!("Added {name} template (with base templates) to .gitignore"));
7672
}
7773

7874
None => {
79-
util::err(&format!("Unknown template: {}", name));
75+
util::err(&format!("Unknown template: {name}"));
8076
util::dim("Available: node, python, rust, go, java, web, macos, windows, linux, ide");
8177
}
8278
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ pub fn run(kind: Option<LicenseKind>) -> Result<()> {
1616
return Ok(());
1717
}
1818

19-
let license = match kind {
20-
Some(ref k) => k,
21-
None => {
19+
let license = if let Some(ref k) = kind { k } else {
2220
let options = ["MIT", "Apache 2.0", "GPL 3.0", "Unlicense"];
2321
let idx = Select::new()
2422
.with_prompt("Choose license")
25-
.items(&options)
23+
.items(options)
2624
.default(0)
2725
.interact()?;
2826
&match idx {
@@ -31,15 +29,14 @@ pub fn run(kind: Option<LicenseKind>) -> Result<()> {
3129
2 => LicenseKind::Gpl,
3230
_ => LicenseKind::Unlicense,
3331
}
34-
}
3532
};
3633

3734
let year = chrono::Local::now().year();
3835
let author = gh::whoami().unwrap_or_else(|_| "Your Name".to_string());
3936

4037
let content = match license {
4138
LicenseKind::Mit => format!(
42-
"MIT License\n\nCopyright (c) {} {}\n\n\
39+
"MIT License\n\nCopyright (c) {year} {author}\n\n\
4340
Permission is hereby granted, free of charge, to any person obtaining a copy\n\
4441
of this software and associated documentation files (the \"Software\"), to deal\n\
4542
in the Software without restriction, including without limitation the rights\n\
@@ -55,7 +52,6 @@ pub fn run(kind: Option<LicenseKind>) -> Result<()> {
5552
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\
5653
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n\
5754
SOFTWARE.\n",
58-
year, author
5955
),
6056
LicenseKind::Apache => format!(
6157
"Copyright {} {}\n\n\

0 commit comments

Comments
 (0)