Skip to content

Commit

Permalink
Added file path stdout if json is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
paulvollmer committed Nov 10, 2017
1 parent 17327c6 commit 9de0ee2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ if (options.compact) {
};
}

function parse (source) {
function parse (source, file) {
var parsed,
formatted;

Expand Down Expand Up @@ -106,13 +106,15 @@ function parse (source) {
parsed = parser.parse(formatted);
} catch (e) {
if (! options.compact) {
console.log('File:', file);
console.error(e);
}
// force the pretty print before exiting
console.log(formatted);
}
} else {
if (! options.compact) {
console.log('File:', file);
console.error(e);
}
}
Expand All @@ -132,7 +134,7 @@ function schemaError (str, err) {

function processFile(file) {
var src = path.normalize(file);
let source = parse(fs.readFileSync(src, "utf8"));
let source = parse(fs.readFileSync(src, "utf8"), src);
if (options.inplace) {
fs.writeSync(fs.openSync(src,'w+'), source, 0, "utf8");
} else {
Expand Down Expand Up @@ -173,7 +175,7 @@ function main (args) {
source += chunk.toString('utf8');
});
stdin.on('end', function () {
if (! options.quiet) {console.log(parse(source))};
if (! options.quiet) {console.log(parse(source, ''))};
});
}
}
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
"lint",
"jsonlint"
],
"version": "1.8.1",
"contributors": [
"Paul Vollmer <[email protected]> (http://paulvollmer.net)"
],
"version": "1.8.2",
"preferGlobal": true,
"repository": {
"type": "git",
"url": "git://github.com/zaach/jsonlint.git"
"url": "git://github.com/paulvollmer/jsonlint.git"
},
"bugs": {
"url": "http://github.com/zaach/jsonlint/issues"
"url": "http://github.com/paulvollmer/jsonlint/issues"
},
"main": "lib/jsonlint.js",
"bin": {
Expand Down

0 comments on commit 9de0ee2

Please sign in to comment.