Skip to content

Commit b9a537a

Browse files
committed
pretty print should exit with error code when invalid
Fixes issue zaach#38.
1 parent 5834ccf commit b9a537a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lib/cli.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ function parse (source) {
9090
}
9191
}
9292

93-
return JSON.stringify(parsed,null,options.indent);
93+
return JSON.stringify(parsed, null, options.indent);
9494
} catch (e) {
95-
if ( options.forcePrettyPrint ) {
95+
if (options.forcePrettyPrint) {
9696
/* From https://github.com/umbrae/jsonlintdotcom:
9797
* If we failed to validate, run our manual formatter and then re-validate so that we
9898
* can get a better line number. On a successful validate, we don't want to run our
@@ -107,16 +107,15 @@ function parse (source) {
107107
if (! options.compact) {
108108
console.error(e);
109109
}
110-
return formatted;
111-
process.exit(1);
110+
// force the pretty print before exiting
111+
console.log(formatted);
112112
}
113113
} else {
114114
if (! options.compact) {
115115
console.error(e);
116116
}
117-
118-
process.exit(1);
119117
}
118+
process.exit(1);
120119
}
121120
}
122121

0 commit comments

Comments
 (0)