@@ -4,27 +4,19 @@ import { SyncRule } from "@commitlint/types";
4
4
export const headerTrim : SyncRule = ( parsed ) => {
5
5
const { header } = parsed ;
6
6
7
- if ( ! header ) {
8
- return [ true ] ;
9
- }
7
+ if ( ! header ) return [ true ] ;
10
8
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 ;
13
11
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" ] ) ] ;
20
14
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" ] ) ] ;
23
17
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" ] ) ] ;
26
20
27
- default :
28
- return [ true ] ;
29
- }
21
+ return [ true ] ;
30
22
} ;
0 commit comments