@prantlf/jsonlint 11.5.0 → 11.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/lib/cli.js +5 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -136,6 +136,7 @@ Usage: `jsonlint [options] [<file, directory, pattern> ...]`
136
136
  -V, --validate [file] JSON schema file to use for validation
137
137
  -e, --environment [env] which specification of JSON Schema the
138
138
  validation file uses
139
+ -x, --context [num] line count used as the diff context (default: 3)
139
140
  -l, --log-files print only the parsed file names to stdout
140
141
  -q, --quiet do not print the parsed json to stdout
141
142
  -n, --continue continue with other files if an error occurs
package/lib/cli.js CHANGED
@@ -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,9 +219,8 @@ 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
- const diff = createTwoFilesPatch(`${file}.orig`, file, source, parsed, '', '', { context: 3 })
224
224
  if (length > 0) {
225
225
  const hunk = length === 1 ? 'hunk differs' : 'hunks differ'
226
226
  const message = `${length} ${hunk}`
@@ -232,6 +232,7 @@ function checkContents (file, source, parsed) {
232
232
  console.error(message)
233
233
  }
234
234
  if (!options.quiet) {
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prantlf/jsonlint",
3
- "version": "11.5.0",
3
+ "version": "11.6.0",
4
4
  "description": "JSON/CJSON/JSON5 parser, syntax and schema validator and pretty-printer.",
5
5
  "author": "Ferdinand Prantl <prantlf@gmail.com> (http://prantl.tk)",
6
6
  "contributors": [