@@ -4,27 +4,19 @@ import { SyncRule } from "@commitlint/types";
44export const headerTrim : SyncRule = ( parsed ) => {
55 const { header } = parsed ;
66
7- if ( ! header ) {
8- return [ true ] ;
9- }
7+ if ( ! header ) return [ true ] ;
108
11- const startsWithWhiteSpace = header !== header . trimStart ( ) ;
12- const endsWithWhiteSpace = header !== header . trimEnd ( ) ;
9+ const startsWithWhiteSpace = header . length > header . trimStart ( ) . length ;
10+ const endsWithWhiteSpace = header . length > header . trimEnd ( ) . length ;
1311
14- switch ( true ) {
15- case startsWithWhiteSpace && endsWithWhiteSpace :
16- return [
17- false ,
18- message ( [ "header" , "must not be surrounded by whitespace" ] ) ,
19- ] ;
12+ if ( startsWithWhiteSpace && endsWithWhiteSpace )
13+ return [ false , message ( [ "header" , "must not be surrounded by whitespace" ] ) ] ;
2014
21- case startsWithWhiteSpace :
22- return [ false , message ( [ "header" , "must not start with whitespace" ] ) ] ;
15+ if ( startsWithWhiteSpace )
16+ return [ false , message ( [ "header" , "must not start with whitespace" ] ) ] ;
2317
24- case endsWithWhiteSpace :
25- return [ false , message ( [ "header" , "must not end with whitespace" ] ) ] ;
18+ if ( endsWithWhiteSpace )
19+ return [ false , message ( [ "header" , "must not end with whitespace" ] ) ] ;
2620
27- default :
28- return [ true ] ;
29- }
21+ return [ true ] ;
3022} ;
0 commit comments