From 3a08bf8c77c5a5b360bdb477a7e8366792467866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Havl=C3=AD=C4=8Dek?= Date: Fri, 26 Jul 2024 08:15:49 +0200 Subject: [PATCH 1/2] test: Fix clippy errors in tests - Add dead_code flag to footer and raw of Message struct --- src/message.rs | 2 ++ src/rule/description_format.rs | 18 ++++++++++++------ src/rule/scope.rs | 24 ++++++++++++++++-------- src/rule/scope_format.rs | 18 ++++++++++++------ src/rule/type.rs | 24 ++++++++++++++++-------- src/rule/type_format.rs | 18 ++++++++++++------ 6 files changed, 70 insertions(+), 34 deletions(-) diff --git a/src/message.rs b/src/message.rs index 5f0dbcc..40980b6 100644 --- a/src/message.rs +++ b/src/message.rs @@ -24,9 +24,11 @@ pub struct Message { /// Description part of the commit message. pub description: Option, + #[allow(dead_code)] /// Footers part of the commit message. pub footers: Option>, + #[allow(dead_code)] /// Raw commit message (or any input from stdin) including the body and footers. pub raw: String, diff --git a/src/rule/description_format.rs b/src/rule/description_format.rs index 070d315..0b5c3db 100644 --- a/src/rule/description_format.rs +++ b/src/rule/description_format.rs @@ -78,8 +78,10 @@ mod tests { #[test] fn test_invalid_description_format() { - let mut rule = DescriptionFormat::default(); - rule.format = Some(r"^[a-z].*".to_string()); + let rule = DescriptionFormat { + format: Some(r"^[a-z].*".to_string()), + ..Default::default() + }; let message = Message { body: None, @@ -96,8 +98,10 @@ mod tests { #[test] fn test_valid_description_format() { - let mut rule = DescriptionFormat::default(); - rule.format = Some(r"^[a-z].*".to_string()); + let rule = DescriptionFormat { + format: Some(r"^[a-z].*".to_string()), + ..Default::default() + }; let message = Message { body: None, @@ -120,8 +124,10 @@ mod tests { #[test] fn test_invalid_regex() { - let mut rule = DescriptionFormat::default(); - rule.format = Some(r"(".to_string()); + let rule = DescriptionFormat { + format: Some(r"(".to_string()), + ..Default::default() + }; let message = Message { body: None, diff --git a/src/rule/scope.rs b/src/rule/scope.rs index a0fdd06..f469898 100644 --- a/src/rule/scope.rs +++ b/src/rule/scope.rs @@ -140,8 +140,10 @@ mod tests { use super::*; #[test] fn test_empty_scope() { - let mut rule = Scope::default(); - rule.options = vec!["api".to_string(), "web".to_string()]; + let rule = Scope { + options: vec!["api".to_string(), "web".to_string()], + ..Default::default() + }; let message = Message { body: None, @@ -164,8 +166,10 @@ mod tests { #[test] fn test_none_scope() { - let mut rule = Scope::default(); - rule.options = vec!["api".to_string(), "web".to_string()]; + let rule = Scope { + options: vec!["api".to_string(), "web".to_string()], + ..Default::default() + }; let message = Message { body: None, @@ -188,8 +192,10 @@ mod tests { #[test] fn test_valid_scope() { - let mut rule = Scope::default(); - rule.options = vec!["api".to_string(), "web".to_string()]; + let rule = Scope { + options: vec!["api".to_string(), "web".to_string()], + ..Default::default() + }; let message = Message { body: None, @@ -206,8 +212,10 @@ mod tests { #[test] fn test_invalid_scope() { - let mut rule = Scope::default(); - rule.options = vec!["api".to_string(), "web".to_string()]; + let rule = Scope { + options: vec!["api".to_string(), "web".to_string()], + ..Default::default() + }; let message = Message { body: None, diff --git a/src/rule/scope_format.rs b/src/rule/scope_format.rs index 9889bed..d0b0959 100644 --- a/src/rule/scope_format.rs +++ b/src/rule/scope_format.rs @@ -78,8 +78,10 @@ mod tests { #[test] fn test_invalid_description_format() { - let mut rule = ScopeFormat::default(); - rule.format = Some(r"^[a-z].*".to_string()); + let rule = ScopeFormat { + format: Some(r"^[a-z].*".to_string()), + ..Default::default() + }; let message = Message { body: None, @@ -96,8 +98,10 @@ mod tests { #[test] fn test_valid_description_format() { - let mut rule = ScopeFormat::default(); - rule.format = Some(r"^[a-z].*".to_string()); + let rule = ScopeFormat { + format: Some(r"^[a-z].*".to_string()), + ..Default::default() + }; let message = Message { body: None, @@ -120,8 +124,10 @@ mod tests { #[test] fn test_invalid_regex() { - let mut rule = ScopeFormat::default(); - rule.format = Some(r"(".to_string()); + let rule = ScopeFormat { + format: Some(r"(".to_string()), + ..Default::default() + }; let message = Message { body: None, diff --git a/src/rule/type.rs b/src/rule/type.rs index ba4f4b5..26f3e94 100644 --- a/src/rule/type.rs +++ b/src/rule/type.rs @@ -139,8 +139,10 @@ mod tests { use super::*; #[test] fn test_empty_type() { - let mut rule = Type::default(); - rule.options = vec!["feat".to_string(), "chore".to_string()]; + let rule = Type { + options: vec!["feat".to_string(), "chore".to_string()], + ..Default::default() + }; let message = Message { body: None, @@ -163,8 +165,10 @@ mod tests { #[test] fn test_none_type() { - let mut rule = Type::default(); - rule.options = vec!["feat".to_string(), "chore".to_string()]; + let rule = Type { + options: vec!["feat".to_string(), "chore".to_string()], + ..Default::default() + }; let message = Message { body: None, @@ -187,8 +191,10 @@ mod tests { #[test] fn test_valid_type() { - let mut rule = Type::default(); - rule.options = vec!["feat".to_string(), "chore".to_string()]; + let rule = Type { + options: vec!["feat".to_string(), "chore".to_string()], + ..Default::default() + }; let message = Message { body: None, @@ -205,8 +211,10 @@ mod tests { #[test] fn test_invalid_type() { - let mut rule = Type::default(); - rule.options = vec!["feat".to_string(), "chore".to_string()]; + let rule = Type { + options: vec!["feat".to_string(), "chore".to_string()], + ..Default::default() + }; let message = Message { body: None, diff --git a/src/rule/type_format.rs b/src/rule/type_format.rs index 259a3ee..672549c 100644 --- a/src/rule/type_format.rs +++ b/src/rule/type_format.rs @@ -78,8 +78,10 @@ mod tests { #[test] fn test_invalid_description_format() { - let mut rule = TypeFormat::default(); - rule.format = Some(r"^[a-z].*".to_string()); + let rule = TypeFormat { + format: Some(r"^[a-z].*".to_string()), + ..Default::default() + }; let message = Message { body: None, @@ -96,8 +98,10 @@ mod tests { #[test] fn test_valid_description_format() { - let mut rule = TypeFormat::default(); - rule.format = Some(r"^[a-z].*".to_string()); + let rule = TypeFormat { + format: Some(r"^[a-z].*".to_string()), + ..Default::default() + }; let message = Message { body: None, @@ -120,8 +124,10 @@ mod tests { #[test] fn test_invalid_regex() { - let mut rule = TypeFormat::default(); - rule.format = Some(r"(".to_string()); + let rule = TypeFormat { + format: Some(r"(".to_string()), + ..Default::default() + }; let message = Message { body: None, From 69466780e6d8ea6e956ceacde213033a30bef900 Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Fri, 26 Jul 2024 08:36:07 +0200 Subject: [PATCH 2/2] Update src/message.rs --- src/message.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/message.rs b/src/message.rs index 40980b6..f65dbfb 100644 --- a/src/message.rs +++ b/src/message.rs @@ -23,8 +23,6 @@ pub struct Message { /// Description part of the commit message. pub description: Option, - - #[allow(dead_code)] /// Footers part of the commit message. pub footers: Option>,