Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions bin/validate-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env node
const fs = require('fs');

const files = process.argv.slice(2);
let hadError = false;

files.forEach((file) => {
const content = fs.readFileSync(file, 'utf8');
const regex = /```json\n([\s\S]*?)```/gm;
let match;
while ((match = regex.exec(content)) !== null) {
try {
JSON.parse(match[1]);
} catch (err) {
console.error(`Invalid JSON in ${file}: ${err.message}`);
hadError = true;
}
}
});

if (hadError) {
process.exit(1);
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"private": true,
"scripts": {
"validate": "node_modules/.bin/mdv ./spec.md ./README.md ./build/markdown/*.md",
"validate:json": "./bin/validate-json.js ./spec.md",
"lint": "./node_modules/.bin/markdownlint ./spec.md ./README.md ./build/markdown/*.md",
"build": "./bin/build.sh",
"test": "npm run build && npm run validate && npm run lint"
"test": "npm run build && npm run validate && npm run lint && npm run validate:json"
},
"repository": {
"type": "git",
Expand Down