From b9a537a3c1c4c475b9be09502680ab5c95039edb Mon Sep 17 00:00:00 2001 From: Zachary Carter Date: Tue, 12 Aug 2014 12:33:51 -0700 Subject: [PATCH] pretty print should exit with error code when invalid Fixes issue #38. --- lib/cli.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 0eb3a88..981c15f 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -90,9 +90,9 @@ function parse (source) { } } - return JSON.stringify(parsed,null,options.indent); + return JSON.stringify(parsed, null, options.indent); } catch (e) { - if ( options.forcePrettyPrint ) { + 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 @@ -107,16 +107,15 @@ function parse (source) { if (! options.compact) { console.error(e); } - return formatted; - process.exit(1); + // force the pretty print before exiting + console.log(formatted); } } else { if (! options.compact) { console.error(e); } - - process.exit(1); } + process.exit(1); } }