2022-01-11 23:08:53 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const { filterTokens } = require("markdownlint-rule-helpers");
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "validate-json" ],
|
|
|
|
"description": "Rule that validates JSON code",
|
|
|
|
"tags": [ "test", "validate", "json" ],
|
|
|
|
"asynchronous": true,
|
|
|
|
"function": async(params, onError) => {
|
2022-10-26 03:26:59 +00:00
|
|
|
const { "default": stripJsonComments } =
|
|
|
|
await import("strip-json-comments");
|
2022-01-11 23:08:53 -08:00
|
|
|
filterTokens(params, "fence", (fence) => {
|
|
|
|
if (/jsonc?/i.test(fence.info)) {
|
|
|
|
try {
|
|
|
|
JSON.parse(stripJsonComments(fence.content));
|
|
|
|
} catch (error) {
|
|
|
|
onError({
|
|
|
|
"lineNumber": fence.lineNumber,
|
|
|
|
"detail": error.message
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|