forked from DavidAnson/markdownlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate-json.js
33 lines (30 loc) · 930 Bytes
/
validate-json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// @ts-check
"use strict";
const { filterTokens } = require("../../helpers");
const { parse, printParseErrorCode } = require("jsonc-parser");
/** @type import("../../lib/markdownlint").Rule */
module.exports = {
"names": [ "validate-json" ],
"description": "Rule that validates JSON code",
"tags": [ "test", "validate", "json" ],
"parser": "markdownit",
"asynchronous": true,
"function": (params, onError) => {
filterTokens(params, "fence", (fence) => {
if (/jsonc?/i.test(fence.info)) {
const errors = [];
parse(fence.content, errors);
if (errors.length > 0) {
const detail = errors.map(
(err) => `${printParseErrorCode(err.error)} (offset ${err.offset}, length ${err.length})`
).join(", ");
onError({
// @ts-ignore
"lineNumber": fence.lineNumber,
detail
});
}
}
});
}
};