From c27ac8f77b65288fb93d0c50eedd0b62f2e560ad Mon Sep 17 00:00:00 2001 From: apottere Date: Mon, 22 Sep 2014 10:53:39 -0400 Subject: [PATCH 1/2] Set exit status when quiet Right now in quiet mode the json is never parsed - this will allow it to parse and set the exit status without logging the error. --- lib/cli.js | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 981c15f..ca9923d 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -92,27 +92,29 @@ function parse (source) { return JSON.stringify(parsed, null, options.indent); } catch (e) { - if (options.forcePrettyPrint) { - /* From https://github.com/umbrae/jsonlintdotcom: - * If we failed to validate, run our manual formatter and then re-validate so that we - * can get a better line number. On a successful validate, we don't want to run our - * manual formatter because the automatic one is faster and probably more reliable. - */ - - try { - formatted = formatter.formatJson(source, options.indent); - // Re-parse so exception output gets better line numbers - parsed = parser.parse(formatted); - } catch (e) { + if (!options.quiet) { + if (options.forcePrettyPrint) { + /* From https://github.com/umbrae/jsonlintdotcom: + * If we failed to validate, run our manual formatter and then re-validate so that we + * can get a better line number. On a successful validate, we don't want to run our + * manual formatter because the automatic one is faster and probably more reliable. + */ + + try { + formatted = formatter.formatJson(source, options.indent); + // Re-parse so exception output gets better line numbers + parsed = parser.parse(formatted); + } catch (e) { + if (! options.compact) { + console.error(e); + } + // force the pretty print before exiting + console.log(formatted); + } + } else { if (! options.compact) { console.error(e); } - // force the pretty print before exiting - console.log(formatted); - } - } else { - if (! options.compact) { - console.error(e); } } process.exit(1); @@ -146,7 +148,8 @@ function main (args) { source += chunk.toString('utf8'); }); stdin.on('end', function () { - if (! options.quiet) {console.log(parse(source))}; + var parsed = parse(source) + if (! options.quiet) {console.log(parsed)}; }); } } From c94aac738d2d50f1f39f2781d59a5c4df2d64db7 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Mon, 22 Sep 2014 10:56:14 -0400 Subject: [PATCH 2/2] Add missing semi-colon. --- lib/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index ca9923d..fb3f54b 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -148,7 +148,7 @@ function main (args) { source += chunk.toString('utf8'); }); stdin.on('end', function () { - var parsed = parse(source) + var parsed = parse(source); if (! options.quiet) {console.log(parsed)}; }); }