File tree Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -62,15 +62,9 @@ async function validateAndMerge() {
6262 const yamlDocuments = yaml . loadAll ( content ) ;
6363
6464 for ( const document of yamlDocuments ) {
65- const isValid = requiredKeys . every ( key => key in document ) ;
66-
65+ const isValid = validateSubdocument ( document ) ;
6766 if ( ! isValid ) {
68- console . log ( JSON . parse ( document ) + ' is missing required keys' ) ;
69- return ;
70- }
71-
72- if ( ! Array . isArray ( document . categories ) || document . categories . length === 0 ) {
73- console . log ( 'Categories must be a non-empty array' ) ;
67+ console . log ( `Invalid subdocument: ${ JSON . stringify ( document ) } ` ) ;
7468 return ;
7569 }
7670 }
@@ -88,4 +82,20 @@ async function validateAndMerge() {
8882 }
8983}
9084
85+ function validateSubdocument ( subdocument ) {
86+ const isValid = requiredKeys . every ( key => key in subdocument ) ;
87+
88+ if ( ! isValid ) {
89+ console . log ( `Subdocument is missing required keys: ${ JSON . stringify ( subdocument ) } ` ) ;
90+ return false ;
91+ }
92+
93+ if ( ! Array . isArray ( subdocument . categories ) || subdocument . categories . length === 0 ) {
94+ console . log ( 'Categories must be a non-empty array' ) ;
95+ return false ;
96+ }
97+
98+ return true ;
99+ }
100+
91101validateAndMerge ( ) ;
You can’t perform that action at this time.
0 commit comments