@@ -11,8 +11,18 @@ const SCHEMA_BASE = path.join(__dirname, '..', 'data', '_schemas')
1111const DATA_BASE = path . join ( __dirname , '..' , 'data' )
1212
1313const isDir = pth => tryBoolean ( ( ) => fs . statSync ( pth ) . isDirectory ( ) )
14- const readYaml = pth => JSON . parse ( JSON . stringify ( yaml . safeLoad ( fs . readFileSync ( pth , 'utf-8' ) , { filename : pth } ) ) )
15- const readDir = pth => fs . readdirSync ( pth ) . filter ( junk . not ) . filter ( entry => ! entry . startsWith ( '_' ) )
14+ const readYaml = pth =>
15+ JSON . parse (
16+ JSON . stringify (
17+ yaml . safeLoad ( fs . readFileSync ( pth , 'utf-8' ) , { filename : pth } ) ,
18+ ) ,
19+ )
20+
21+ const readDir = pth =>
22+ fs
23+ . readdirSync ( pth )
24+ . filter ( junk . not )
25+ . filter ( entry => ! entry . startsWith ( '_' ) )
1626
1727/// MARK: program
1828
@@ -78,20 +88,26 @@ function parseArgs(argv) {
7888 console . error ( )
7989 console . error ( 'Arguments:' )
8090 console . error ( ' <blank>: validates all schemas and data' )
81- console . error ( ' [schema-name]+: validates the schema and data for the given schema' )
91+ console . error (
92+ ' [schema-name]+: validates the schema and data for the given schema' ,
93+ )
8294 console . error ( )
8395 console . error ( 'Options:' )
8496 console . error ( ' --no-bail: continue past the first error' )
8597 console . error ( ' -d, --data: use this as the data file (requires --schema)' )
8698 console . error ( ' -s, --schema: use this as the schema (requires --data)' )
8799 console . error ( )
88- console . error ( `By default, the program looks for schema files in ${ SCHEMA_BASE } ` )
100+ console . error (
101+ `By default, the program looks for schema files in ${ SCHEMA_BASE } ` ,
102+ )
89103 process . exit ( 1 )
90104 }
91105
92106 if ( ( args . data && ! args . schema ) || ( args . schema && ! args . data ) ) {
93107 console . error ( 'Usage: node validate-compiled-data.js [options] [args]' )
94- console . error ( 'If either --data or --schema are provided, both are required' )
108+ console . error (
109+ 'If either --data or --schema are provided, both are required' ,
110+ )
95111 process . exit ( 1 )
96112 }
97113
@@ -145,7 +161,9 @@ function formatError(err, data) {
145161 const dataPath = err . dataPath . replace ( / ^ \. / , '' )
146162 switch ( err . keyword ) {
147163 case 'enum' : {
148- contents = `Given value "${ get ( data , dataPath ) } " ${ err . message } [${ err . params . allowedValues . join ( ', ' ) } ]`
164+ const value = get ( data , dataPath )
165+ const allowed = err . params . allowedValues . join ( ', ' )
166+ contents = `Given value "${ value } " ${ err . message } [${ allowed } ]`
149167 break
150168 }
151169 case 'type' : {
@@ -156,8 +174,5 @@ function formatError(err, data) {
156174 return JSON . stringify ( err , null , 2 )
157175 }
158176 }
159- return [
160- `Error at ${ err . dataPath } :` ,
161- contents ,
162- ] . join ( '\n' )
177+ return [ `Error at ${ err . dataPath } :` , contents ] . join ( '\n' )
163178}
0 commit comments