refactor: Setup new clippy lints · gregE21/commit@0d6d0fc · GitHub
Skip to content

Commit 0d6d0fc

Browse files
committed
refactor: Setup new clippy lints
1 parent e39b8c7 commit 0d6d0fc

7 files changed

Lines changed: 41 additions & 36 deletions

File tree

‎src/commit_message/message_build/mod.rs‎

Lines changed: 2 additions & 2 deletions

‎src/commit_message/message_build/tests.rs‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::commit_message::message_build::MessageBuilder;
22
use crate::config::Config;
3-
use anyhow::Result;
43

54
fn message_with_config(config: Config) -> String {
65
let mut builder = MessageBuilder::new(config);
@@ -13,11 +12,11 @@ fn message_with_config(config: Config) -> String {
1312
}
1413

1514
#[test]
16-
fn message_builder_config_test() -> Result<()> {
15+
fn message_builder_config_test() {
1716
let mut config = Config {
18-
scope_prefix: "(".to_string(),
19-
scope_suffix: ")".to_string(),
20-
subject_separator: ": ".to_string(),
17+
scope_prefix: "(".to_owned(),
18+
scope_suffix: ")".to_owned(),
19+
subject_separator: ": ".to_owned(),
2120
type_prefix: None,
2221
type_suffix: None,
2322
};
@@ -27,36 +26,35 @@ fn message_builder_config_test() -> Result<()> {
2726
"feat(test): description\n\nbody\n\nfooter"
2827
);
2928

30-
config.type_prefix = Some("[".to_string());
31-
config.type_suffix = Some("]".to_string());
29+
config.type_prefix = Some("[".to_owned());
30+
config.type_suffix = Some("]".to_owned());
3231

3332
assert_eq!(
3433
message_with_config(config.clone()),
3534
"[feat](test): description\n\nbody\n\nfooter"
3635
);
37-
config.subject_separator = " ".to_string();
36+
config.subject_separator = " ".to_owned();
3837

3938
assert_eq!(
4039
message_with_config(config.clone()),
4140
"[feat](test) description\n\nbody\n\nfooter"
4241
);
4342

44-
config.scope_prefix = "".to_string();
45-
config.scope_suffix = "".to_string();
43+
config.scope_prefix = "".to_owned();
44+
config.scope_suffix = "".to_owned();
4645

4746
assert_eq!(
48-
message_with_config(config.clone()),
47+
message_with_config(config),
4948
"[feat]test description\n\nbody\n\nfooter"
5049
);
51-
Ok(())
5250
}
5351

5452
#[test]
55-
fn message_builder_test() -> Result<()> {
53+
fn message_builder_test() {
5654
let config = Config {
57-
scope_prefix: "(".to_string(),
58-
scope_suffix: ")".to_string(),
59-
subject_separator: ": ".to_string(),
55+
scope_prefix: "(".to_owned(),
56+
scope_suffix: ")".to_owned(),
57+
subject_separator: ": ".to_owned(),
6058
type_prefix: None,
6159
type_suffix: None,
6260
};
@@ -76,5 +74,4 @@ fn message_builder_test() -> Result<()> {
7674

7775
builder.set_footer("footer");
7876
assert_eq!(builder.message, "feat(test): description\n\nbody\n\nfooter");
79-
Ok(())
8077
}

‎src/commit_message/mod.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ use prompt::Prompt;
1010
pub fn make_message_commit(pattern: CommitPattern) -> Result<String> {
1111
let mut message_inquirer = MessageInquirer::new(pattern.clone());
1212
let skip_commit = pattern.skip_commit;
13-
if !skip_commit.contains(&"commit_type".to_string()) {
13+
if !skip_commit.contains(&"commit_type".to_owned()) {
1414
message_inquirer.type_choice()?;
1515
}
16-
if !skip_commit.contains(&"commit_scope".to_string()) {
16+
if !skip_commit.contains(&"commit_scope".to_owned()) {
1717
message_inquirer.scope_choice()?;
1818
}
19-
if !skip_commit.contains(&"commit_description".to_string()) {
19+
if !skip_commit.contains(&"commit_description".to_owned()) {
2020
message_inquirer.description()?;
2121
}
22-
if !skip_commit.contains(&"commit_body".to_string()) {
22+
if !skip_commit.contains(&"commit_body".to_owned()) {
2323
message_inquirer.body()?;
2424
}
25-
if !skip_commit.contains(&"commit_footer".to_string()) {
25+
if !skip_commit.contains(&"commit_footer".to_owned()) {
2626
message_inquirer.footer()?;
2727
}
2828
message_inquirer.message()
@@ -36,7 +36,7 @@ struct MessageInquirer {
3636

3737
impl MessageInquirer {
3838
fn new(pattern: CommitPattern) -> Self {
39-
MessageInquirer {
39+
Self {
4040
commit_builder: MessageBuilder::new(pattern.config.clone()),
4141
prompt: Prompt::new(),
4242
pattern,

‎src/commit_message/prompt.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ pub struct Prompt {
1313
}
1414

1515
impl Prompt {
16-
pub fn new() -> Prompt {
16+
pub fn new() -> Self {
1717
let default = RenderConfig::default();
1818
let prompt_prefix = Styled::new("-").with_fg(Color::LightGreen);
1919
let current_config = default.with_prompt_prefix(prompt_prefix);
20-
Prompt {
20+
Self {
2121
config: current_config,
2222
}
2323
}

‎src/config/mod.rs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ mod tests;
44
use anyhow::{anyhow, Context, Result};
55
use serde::Deserialize;
66
use std::fmt::{Display, Formatter, Result as FmtResult};
7-
use std::fs::File;
8-
use std::io::Read;
7+
use std::fs;
98
use std::path::Path;
109
use std::path::PathBuf;
1110

@@ -52,9 +51,7 @@ pub struct CommitPattern {
5251
}
5352

5453
fn get_config_path_content(config_path: impl AsRef<Path>) -> Result<String> {
55-
let mut file = File::open(config_path)?;
56-
let mut content = String::new();
57-
file.read_to_string(&mut content)?;
54+
let content = fs::read_to_string(config_path)?;
5855
Ok(content)
5956
}
6057

@@ -97,6 +94,6 @@ pub fn get_pattern(config_path: Option<PathBuf>) -> Result<CommitPattern> {
9794
let default_pattern_str = DEFAULT_CONFIG_FILE;
9895
let selected_config_path = select_custom_config_path(config_path)?;
9996
let pattern_str = get_config_path_content(&selected_config_path)
100-
.unwrap_or_else(|_| default_pattern_str.to_string());
97+
.unwrap_or_else(|_| default_pattern_str.to_owned());
10198
serde_json::from_str(&pattern_str).context("Failed to parse commit pattern from file")
10299
}

‎src/config/tests.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ fn select_custom_config_path_test() -> Result<()> {
1818
let selected_config_path = select_custom_config_path(Some(PathBuf::new()));
1919
match selected_config_path {
2020
Err(err) => assert_eq!(err.to_string(), "Config file does not exist: "),
21-
_ => assert!(false),
21+
_ => unreachable!(),
2222
}
2323
Ok(())
2424
}
2525

2626
#[test]
2727
fn get_config_path_test() -> Result<()> {
28-
let config_file = dirs::config_dir().unwrap().join("commit/commit.json");
28+
let config_file = dirs::config_dir()
29+
.ok_or(anyhow!("Could not find config directory"))?
30+
.join("commit/commit.json");
2931
let config_path = get_config_path();
30-
assert_eq!(config_file.to_str(), config_path.unwrap().to_str());
32+
assert_eq!(config_file.to_str(), config_path?.to_str());
3133
Ok(())
3234
}
3335

‎src/main.rs‎

Lines changed: 9 additions & 0 deletions

0 commit comments

Comments
 (0)