@@ -23,14 +23,17 @@ impl Rule for DescriptionEmpty {
23
23
}
24
24
25
25
fn validate ( & self , message : & Message ) -> Option < Violation > {
26
- if message. description . is_none ( ) {
27
- return Some ( Violation {
26
+ match message. description {
27
+ None => Some ( Violation {
28
28
level : self . level . unwrap_or ( Self :: LEVEL ) ,
29
29
message : self . message ( message) ,
30
- } ) ;
30
+ } ) ,
31
+ Some ( ref desc) if desc. is_empty ( ) => Some ( Violation {
32
+ level : self . level . unwrap_or ( Self :: LEVEL ) ,
33
+ message : self . message ( message) ,
34
+ } ) ,
35
+ _ => None ,
31
36
}
32
-
33
- None
34
37
}
35
38
}
36
39
@@ -84,4 +87,26 @@ mod tests {
84
87
"description is empty or missing space in the beginning" . to_string( )
85
88
) ;
86
89
}
90
+
91
+ #[ test]
92
+ fn test_blank_description ( ) {
93
+ let rule = DescriptionEmpty :: default ( ) ;
94
+ let message = Message {
95
+ body : None ,
96
+ description : Some ( "" . to_string ( ) ) ,
97
+ footers : None ,
98
+ r#type : Some ( "feat" . to_string ( ) ) ,
99
+ raw : "(scope):" . to_string ( ) ,
100
+ scope : Some ( "scope" . to_string ( ) ) ,
101
+ subject : None ,
102
+ } ;
103
+
104
+ let violation = rule. validate ( & message) ;
105
+ assert ! ( violation. is_some( ) ) ;
106
+ assert_eq ! ( violation. clone( ) . unwrap( ) . level, Level :: Error ) ;
107
+ assert_eq ! (
108
+ violation. unwrap( ) . message,
109
+ "description is empty or missing space in the beginning" . to_string( )
110
+ ) ;
111
+ }
87
112
}
0 commit comments