File tree 1 file changed +22
-6
lines changed
1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -2,22 +2,38 @@ import {case as ensureCase} from '@commitlint/ensure';
2
2
import message from '@commitlint/message' ;
3
3
import { TargetCaseType , SyncRule } from '@commitlint/types' ;
4
4
5
- export const bodyCase : SyncRule < TargetCaseType > = (
5
+ const negated = ( when ?: string ) => when === 'never' ;
6
+
7
+ export const bodyCase : SyncRule < TargetCaseType | TargetCaseType [ ] > = (
6
8
parsed ,
7
9
when = 'always' ,
8
- value = undefined
10
+ value = [ ]
9
11
) => {
10
12
const { body} = parsed ;
11
13
12
14
if ( ! body ) {
13
15
return [ true ] ;
14
16
}
15
17
16
- const negated = when === 'never' ;
18
+ const checks = ( Array . isArray ( value ) ? value : [ value ] ) . map ( ( check ) => {
19
+ if ( typeof check === 'string' ) {
20
+ return {
21
+ when : 'always' ,
22
+ case : check ,
23
+ } ;
24
+ }
25
+ return check ;
26
+ } ) ;
27
+
28
+ const result = checks . some ( ( check ) => {
29
+ const r = ensureCase ( body , check . case ) ;
30
+ return negated ( check . when ) ? ! r : r ;
31
+ } ) ;
32
+
33
+ const list = checks . map ( ( c ) => c . case ) . join ( ', ' ) ;
17
34
18
- const result = ensureCase ( body , value ) ;
19
35
return [
20
- negated ? ! result : result ,
21
- message ( [ `body must` , negated ? `not` : null , `be ${ value } ` ] ) ,
36
+ negated ( when ) ? ! result : result ,
37
+ message ( [ `body must` , negated ( when ) ? `not` : null , `be ${ list } ` ] ) ,
22
38
] ;
23
39
} ;
You can’t perform that action at this time.
0 commit comments