4 * A brief assertion wrapper around html-validate.
7 const assert
= require('node:assert');
10 * @typedef {object} ConsoleLike
11 * @property {Function} debug debug
15 * @typedef {import('html-validate')} HtmlValidateModule
19 * Given an instance of html-validate, returns a function which asserts validity of some HTML.
20 * @param {ConsoleLike} logger logger
21 * @param {HtmlValidateModule.HtmlValidate} htmlValidate html-validate instance
22 * @returns {(html: string) => Promise<void>} function which lints html
24 function makeHtmlLint(logger
, htmlValidate
) {
27 * @param {any[]} violations array of violations to add to
28 * @param {any} message violation to add
30 function note(violations
, message
) {
31 violations
.push(message
.ruleId
);
32 logger
.debug('HtmlLint', message
);
34 return async
function HtmlLint(html
) {
35 const violations
= [];
36 const report
= await htmlValidate
.validateString(html
);
37 report
.results
.forEach((r
) => {
38 if (Array
.isArray(r
)) {
46 assert(report
.valid
, 'HTML violations: ' + violations
.join(', '));