Add test case for custom rule that imports an ESM module (refs #477).

This commit is contained in:
David Anson 2022-01-11 23:08:53 -08:00
parent b1aef98220
commit 23d8ed7c01
5 changed files with 87 additions and 2 deletions

View file

@ -17,10 +17,14 @@ module.exports.lettersEX = lettersEX;
const lintJavaScript = require("./lint-javascript");
module.exports.lintJavaScript = lintJavaScript;
const validateJson = require("./validate-json");
module.exports.validateJson = validateJson;
module.exports.all = [
anyBlockquote,
everyNLines,
firstLine,
lettersEX,
lintJavaScript
lintJavaScript,
validateJson
];

View file

@ -0,0 +1,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) => {
// eslint-disable-next-line max-len, node/no-unsupported-features/es-syntax
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
});
}
}
});
}
};