Skip to content

Commit 94c92ed

Browse files
committed
refactor(cli): 🚨 fix lint warnings
1 parent a2d4a22 commit 94c92ed

11 files changed

Lines changed: 37 additions & 43 deletions

File tree

src/config/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn load_config(path: Option<PathBuf>, config: &mut SimpleCommitsConfig) -> C
4141

4242
if let Ok(content) = std::fs::read_to_string(&global_path) {
4343
let mut global_config: SimpleCommitsConfig = toml::from_str(&content).unwrap();
44-
config.config = global_path.clone();
44+
config.config.clone_from(&global_path);
4545
config.scopes = Some(Scope::default());
4646
config.merge(&mut global_config);
4747
}
@@ -51,7 +51,7 @@ pub fn load_config(path: Option<PathBuf>, config: &mut SimpleCommitsConfig) -> C
5151
if let Ok(local_path_ok) = &local_path {
5252
if let Ok(content) = std::fs::read_to_string(local_path_ok) {
5353
let mut local_config: SimpleCommitsConfig = toml::from_str(&content).unwrap();
54-
config.config = local_path_ok.clone();
54+
config.config.clone_from(local_path_ok);
5555
config.scopes = Some(Scope::default());
5656
config.merge(&mut local_config);
5757
}

src/config/mod.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@ pub fn get_config() -> (cli::SimpleCommitsConfig, Option<Command>) {
1010
let mut args = cli::CliConfig::parse();
1111
let mut config = cli::SimpleCommitsConfig::default();
1212

13-
match args.mode {
14-
Some(Command::Init(option)) => {
15-
let path = helpers::create_config(option);
16-
config.config = path;
17-
}
18-
_ => {
19-
let (global_path, local_path) = helpers::load_config(args.config, &mut config);
13+
if let Some(Command::Init(option)) = args.mode {
14+
let path = helpers::create_config(option);
15+
config.config = path;
16+
} else {
17+
let (global_path, local_path) = helpers::load_config(args.config, &mut config);
2018

21-
if let Some(local_path) = local_path {
22-
config.config = local_path;
23-
} else {
24-
config.config = global_path;
25-
}
26-
config.merge(&mut args.sc_config);
19+
if let Some(local_path) = local_path {
20+
config.config = local_path;
21+
} else {
22+
config.config = global_path;
2723
}
24+
config.merge(&mut args.sc_config);
2825
}
2926
(config, args.mode)
3027
}

src/gen/emojis.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// This code is autogenerated by pipeline on GitHub Actions
33
// Version of emoji based: v3.14.0
44
// This generation is based from https://raw.githubusercontent.com/carloscuesta/gitmoji/v3.14.0/packages/gitmojis/src/gitmojis.json
5-
use colored::*;
5+
use colored::Colorize;
66
use serde::Deserialize;
77

88
#[derive(Deserialize, Clone)]
99
pub struct Emoji {
10+
#[allow(clippy::struct_field_names)]
1011
pub emoji: &'static str,
1112
pub description: &'static str,
1213
pub name: &'static str,
@@ -16,8 +17,8 @@ impl Emoji {
1617
const fn new(emoji: &'static str, name: &'static str, description: &'static str) -> Self {
1718
Self {
1819
emoji,
19-
name,
2020
description,
21+
name,
2122
}
2223
}
2324
}

src/tui/config_prompt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn init(
1414

1515
info("")?;
1616
info("Succesfully created.")?;
17-
info(format!("Path: {config:?}"))?;
17+
info(format!("Path: {}", config.display()))?;
1818
info("")?;
1919

2020
outro(concat!(

src/tui/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ impl Action {
4242
match self {
4343
Self::DryRun(msg) => println!("{msg}"),
4444
Self::Commit(cmd, args) => {
45-
std::process::Command::new(cmd)
45+
let _ = std::process::Command::new(cmd)
4646
.args(&args[..])
4747
.spawn()
48-
.unwrap();
48+
.expect("The child failed for some reason")
49+
.wait();
4950
}
50-
_ => {}
51+
Self::None => {}
5152
}
5253
}
5354
}
5455

5556
pub type StepResult = Result<(), AppError>;
5657

5758
/// A trait to setup steps along the TUI app.
58-
5959
pub trait Step {
6060
fn before_run(
6161
&mut self,
@@ -154,7 +154,7 @@ impl CommitBuilder {
154154
if r#type.is_none() {
155155
log::error!("Type of commit required");
156156
return Err(BuildError::TypeRequired);
157-
};
157+
}
158158

159159
if title.is_none() {
160160
log::error!("Title of the commit required");
@@ -170,7 +170,7 @@ impl CommitBuilder {
170170
let exclamation = if let Some(true) = is_breaking_change {
171171
"!".to_owned()
172172
} else {
173-
"".to_owned()
173+
String::new()
174174
};
175175
let breaking_change_message = breaking_change_message.map_or(String::new(), |m| {
176176
format!("BREAKING CHANGE: {m}").trim().to_string()

src/tui/steps/breaking_change.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Step for Message {
3636
fn run(&mut self, state: &mut crate::tui::AppData, _: &mut SimpleCommitsConfig) -> StepResult {
3737
if !self.execute {
3838
return Ok(());
39-
};
39+
}
4040

4141
let breaking_change_msg: String = input("Expand the breaking change description")
4242
.required(false)

src/tui/steps/content.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Step for Title {
1818
config: &mut SimpleCommitsConfig,
1919
) -> StepResult {
2020
self.skip = config.message.as_ref().is_some();
21-
self.title = config.message.clone();
21+
self.title.clone_from(&config.message);
2222
Ok(())
2323
}
2424

src/tui/steps/exec.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ impl Step for Execute {
2121
state: &mut crate::tui::AppData,
2222
config: &mut SimpleCommitsConfig,
2323
) -> StepResult {
24-
self.skip = config
25-
.git
26-
.as_ref()
27-
.map(|cfg| cfg.skip_preview)
28-
.unwrap_or(false);
24+
self.skip = config.git.as_ref().is_some_and(|cfg| cfg.skip_preview);
2925

3026
let commit = state.commit.clone().build().unwrap();
3127

@@ -66,14 +62,14 @@ impl Step for Execute {
6662
let execute = confirm("Do you want to execute this command?")
6763
.initial_value(true)
6864
.interact()?;
69-
if !execute {
65+
if execute {
66+
let (head, tail) = self.cmd.split_first().unwrap();
67+
self.action = Action::Commit(head.clone(), tail.to_vec());
68+
} else {
7069
step("Commit preview")?;
7170
info(commit.0)?;
7271
info(BLANK_CHARACTER)?;
73-
} else {
74-
let (head, tail) = self.cmd.split_first().unwrap();
75-
self.action = Action::Commit(head.clone(), tail.to_vec());
76-
};
72+
}
7773

7874
Ok(())
7975
}

src/tui/steps/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ pub fn init(config: &mut SimpleCommitsConfig) -> Result<(), AppError> {
2929

3030
intro("Simple Commit")?;
3131

32-
for step in steps.iter_mut() {
32+
for step in &mut steps {
3333
let _before = step.before_run(&mut state, config);
3434
let res = step.run(&mut state, config);
3535
if let Err(err) = res {
36-
let msg = format!("❌ Error: {:?}", err);
36+
let msg = format!("❌ Error: {err:?}");
3737
error!(target: "tui::steps", "{}", msg.bright_red());
3838
return Err(AppError::Step(msg));
3939
}

src/tui/steps/scopes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Step for Scope {
2727
(
2828
scope.name(),
2929
scope.name(),
30-
scope.description().clone().unwrap_or_default(),
30+
scope.description().map_or(String::new(), Clone::clone),
3131
)
3232
})
3333
.collect::<Vec<_>>();
@@ -49,7 +49,7 @@ impl Step for Scope {
4949
config
5050
.update()
5151
.inspect_err(|err| {
52-
error!(target: "step::scope", "error updating the scopes: {}", err);
52+
error!(target: "step::scope", "error updating the scopes: {err}");
5353
})
5454
.unwrap();
5555
}

0 commit comments

Comments
 (0)