Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)};
});
}
}
Expand Down