1
0
mirror of synced 2025-12-09 15:08:15 +08:00

pretty print should exit with error code when invalid

Fixes issue #38.
This commit is contained in:
Zachary Carter
2014-08-12 12:33:51 -07:00
parent 5834ccff24
commit b9a537a3c1

View File

@@ -90,9 +90,9 @@ function parse (source) {
} }
} }
return JSON.stringify(parsed,null,options.indent); return JSON.stringify(parsed, null, options.indent);
} catch (e) { } catch (e) {
if ( options.forcePrettyPrint ) { if (options.forcePrettyPrint) {
/* From https://github.com/umbrae/jsonlintdotcom: /* From https://github.com/umbrae/jsonlintdotcom:
* If we failed to validate, run our manual formatter and then re-validate so that we * 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 * 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) { if (! options.compact) {
console.error(e); console.error(e);
} }
return formatted; // force the pretty print before exiting
process.exit(1); console.log(formatted);
} }
} else { } else {
if (! options.compact) { if (! options.compact) {
console.error(e); console.error(e);
} }
process.exit(1);
} }
process.exit(1);
} }
} }