From 3cd558bca5a964bcd113999252c4c5139ed0bcc5 Mon Sep 17 00:00:00 2001 From: xieyongbin Date: Tue, 19 Aug 2025 13:32:46 +0800 Subject: [PATCH] fix(rule): report error message when type scope or body empty This commit to fix follow rules report error message: - type ```shell $> echo -n "add new flag" | commitlint type is longer than 4 characters ``` Config rules see below: ```yaml rules: type-max-length: level: error length: 4 ``` - scope ```shell $> echo -n "feat: add new flag" | commitlint scope is longer than 5 characters ``` Config rules see below: ```yaml rules: scope-max-length: level: error length: 5 ``` - body ```shell $> echo -n "feat(cli): add new flag" | commitlint body is longer than 72 characters ``` Config rules see below ```yaml rules: body-empty: level: ignore body-max-length: level: error length: 72 ``` Signed-off-by: xieyongbin --- cli/src/rule/body_max_length.rs | 14 +++----------- cli/src/rule/scope_max_length.rs | 14 +++----------- cli/src/rule/type_max_length.rs | 14 +++----------- 3 files changed, 9 insertions(+), 33 deletions(-) diff --git a/cli/src/rule/body_max_length.rs b/cli/src/rule/body_max_length.rs index ea8b869..2bd910f 100644 --- a/cli/src/rule/body_max_length.rs +++ b/cli/src/rule/body_max_length.rs @@ -27,20 +27,12 @@ impl Rule for BodyMaxLength { } fn validate(&self, message: &Message) -> Option { - match &message.body { - Some(body) => { - if body.len() >= self.length { - return Some(Violation { - level: self.level.unwrap_or(Self::LEVEL), - message: self.message(message), - }); - } - } - None => { + if let Some(body) = &message.body { + if body.len() >= self.length { return Some(Violation { level: self.level.unwrap_or(Self::LEVEL), message: self.message(message), - }) + }); } } diff --git a/cli/src/rule/scope_max_length.rs b/cli/src/rule/scope_max_length.rs index f33da11..dacc15f 100644 --- a/cli/src/rule/scope_max_length.rs +++ b/cli/src/rule/scope_max_length.rs @@ -27,20 +27,12 @@ impl Rule for ScopeMaxLength { } fn validate(&self, message: &Message) -> Option { - match &message.scope { - Some(scope) => { - if scope.len() >= self.length { - return Some(Violation { - level: self.level.unwrap_or(Self::LEVEL), - message: self.message(message), - }); - } - } - None => { + if let Some(scope) = &message.scope { + if scope.len() >= self.length { return Some(Violation { level: self.level.unwrap_or(Self::LEVEL), message: self.message(message), - }) + }); } } diff --git a/cli/src/rule/type_max_length.rs b/cli/src/rule/type_max_length.rs index 1df8dbb..fdf65e9 100644 --- a/cli/src/rule/type_max_length.rs +++ b/cli/src/rule/type_max_length.rs @@ -27,20 +27,12 @@ impl Rule for TypeMaxLength { } fn validate(&self, message: &Message) -> Option { - match &message.r#type { - Some(t) => { - if t.len() >= self.length { - return Some(Violation { - level: self.level.unwrap_or(Self::LEVEL), - message: self.message(message), - }); - } - } - None => { + if let Some(t) = &message.r#type { + if t.len() >= self.length { return Some(Violation { level: self.level.unwrap_or(Self::LEVEL), message: self.message(message), - }) + }); } }