File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Expand file tree Collapse file tree 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';
22import message from '@commitlint/message' ;
33import { TargetCaseType , SyncRule } from '@commitlint/types' ;
44
5- export const bodyCase : SyncRule < TargetCaseType > = (
5+ const negated = ( when ?: string ) => when === 'never' ;
6+
7+ export const bodyCase : SyncRule < TargetCaseType | TargetCaseType [ ] > = (
68 parsed ,
79 when = 'always' ,
8- value = undefined
10+ value = [ ]
911) => {
1012 const { body} = parsed ;
1113
1214 if ( ! body ) {
1315 return [ true ] ;
1416 }
1517
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 ( ', ' ) ;
1734
18- const result = ensureCase ( body , value ) ;
1935 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 } ` ] ) ,
2238 ] ;
2339} ;
You can’t perform that action at this time.
0 commit comments