forked from DavidAnson/markdownlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-json.js
More file actions
28 lines (25 loc) · 720 Bytes
/
validate-json.js
File metadata and controls
28 lines (25 loc) · 720 Bytes
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
// @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) => {
const { "default": stripJsonComments } =
await import("strip-json-comments");
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
});
}
}
});
}
};