@@ -32,6 +32,7 @@ const commander = require('commander')
32
32
. option ( '-D, --no-duplicate-keys' , 'report duplicate object keys as an error' )
33
33
. option ( '-V, --validate [file]' , 'JSON schema file to use for validation' )
34
34
. option ( '-e, --environment [env]' , 'which specification of JSON Schema the validation file uses' )
35
+ . option ( '-x, --context [num]' , 'line count used as the diff context' , 3 )
35
36
. option ( '-l, --log-files' , 'print only the parsed file names to stdout' )
36
37
. option ( '-q, --quiet' , 'do not print the parsed json to stdout' )
37
38
. option ( '-n, --continue' , 'continue with other files if an error occurs' )
@@ -218,7 +219,7 @@ function ensureLineBreak (parsed, source) {
218
219
219
220
function checkContents ( file , source , parsed ) {
220
221
const { createTwoFilesPatch, structuredPatch } = require ( 'diff' )
221
- const structured = structuredPatch ( `${ file } .orig` , file , source , parsed , '' , '' , { context : 3 } )
222
+ const structured = structuredPatch ( `${ file } .orig` , file , source , parsed , '' , '' , { context : options . context } )
222
223
const length = structured . hunks && structured . hunks . length
223
224
if ( length > 0 ) {
224
225
const hunk = length === 1 ? 'hunk differs' : 'hunks differ'
@@ -231,7 +232,7 @@ function checkContents (file, source, parsed) {
231
232
console . error ( message )
232
233
}
233
234
if ( ! options . quiet ) {
234
- const diff = createTwoFilesPatch ( `${ file } .orig` , file , source , parsed , '' , '' , { context : 3 } )
235
+ const diff = createTwoFilesPatch ( `${ file } .orig` , file , source , parsed , '' , '' , { context : options . context } )
235
236
console . log ( diff )
236
237
}
237
238
if ( options . continue ) {
@@ -253,10 +254,10 @@ function diffContents(file, source, parsed) {
253
254
const compact = options . quiet || options . compact
254
255
let diff , length
255
256
if ( compact ) {
256
- diff = structuredPatch ( `${ file } .orig` , file , source , parsed , '' , '' , { context : 3 } )
257
+ diff = structuredPatch ( `${ file } .orig` , file , source , parsed , '' , '' , { context : options . context } )
257
258
length = diff . hunks && diff . hunks . length
258
259
} else {
259
- diff = createTwoFilesPatch ( `${ file } .orig` , file , source , parsed , '' , '' , { context : 3 } )
260
+ diff = createTwoFilesPatch ( `${ file } .orig` , file , source , parsed , '' , '' , { context : options . context } )
260
261
length = diff . split ( / \r ? \n / ) . length - 4
261
262
}
262
263
if ( length > 0 ) {
0 commit comments