Skip to content

Commit

Permalink
Add individual tools/jsonlint.js to lint package.json files
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterDaveHello committed Dec 18, 2017
1 parent bda189b commit 0d38ef8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -36,6 +36,7 @@
"jasmine": "^2.8.0",
"jscs": "^3.0.7",
"jslint": "^0.11.0",
"jsonlint": "^1.6.2",
"rewire": "^2.5.2",
"vows-si": "^0.7.1"
},
Expand Down
36 changes: 36 additions & 0 deletions tools/jsonlint.js
@@ -0,0 +1,36 @@
#!/usr/bin/env node

var fs = require('fs');
var glob = require('glob');
var async = require('async');
var colors = require('colors');
var jsonlint = require("jsonlint");
var errorCount = 0;

var jsonfiles = glob.sync("ajax/libs/*/package.json");

console.log("Found " + jsonfiles.length + " json file(s)");

async.map(jsonfiles, function lintjson(item, cb) {
fs.readFile(item, 'utf8', (err, data) => {
if (err) throw err;
try {
jsonlint.parse(data);
} catch(e) {
errorCount++;
console.log("\n" + item.yellow + " parsing failed:\n".red);
console.log(e.toString().magenta);
}
cb();
});
}, function (err, results) {
if (err) {
console.dir(err);
}
if (errorCount > 0) {
console.log("\nYou can validate json here: https://jsonlint.com/ once you revised the file(s) with formatting problem.\n".cyan);
} else if (jsonfiles > 0) {
console.log("\nAll json parsed without problem!\n".green);
}
});

0 comments on commit 0d38ef8

Please sign in to comment.