From a9e97181057b2ac6fe95d90e2b4c4cbe84027e7f Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Tue, 13 Feb 2024 18:25:53 +0100 Subject: [PATCH] fix(cli): ignore error on empty description Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> --- src/rule/description_max_length.rs | 33 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/rule/description_max_length.rs b/src/rule/description_max_length.rs index d67aadf..de0f01a 100644 --- a/src/rule/description_max_length.rs +++ b/src/rule/description_max_length.rs @@ -26,20 +26,12 @@ impl Rule for DescriptionMaxLength { } fn validate(&self, message: &Message) -> Option { - match &message.description { - Some(desc) => { - if desc.len() >= self.length { - return Some(Violation { - level: self.level.unwrap_or(Self::LEVEL), - message: self.message(message), - }); - } - } - None => { + if let Some(desc) = &message.description { + if desc.len() >= self.length { return Some(Violation { level: self.level.unwrap_or(Self::LEVEL), message: self.message(message), - }) + }); } } @@ -80,6 +72,25 @@ mod tests { assert!(rule.validate(&message).is_none()); } + #[test] + fn test_empty_description() { + let rule = DescriptionMaxLength { + length: 10, // Short length for testing + ..Default::default() + }; + let message = Message { + body: None, + description: None, + footers: None, + r#type: Some("feat".to_string()), + raw: "feat(scope)".to_string(), + scope: Some("scope".to_string()), + subject: None, + }; + + assert!(rule.validate(&message).is_none()); + } + #[test] fn test_short_description() { let rule = DescriptionMaxLength {