change html linter, export as test helper
[squeep-html-template-helper] / test / lint-html.js
1 'use strict';
2
3 /**
4 * A brief wrapper around html-validate
5 */
6
7 const assert = require('node:assert');
8 const { HtmlValidate } = require('html-validate'); // eslint-disable-line node/no-unpublished-require
9 const stubLogger = require('./stub-logger');
10
11 class LintHtml {
12 constructor(logger, ...args) {
13 this.logger = logger;
14 this.htmlValidate = new HtmlValidate(...args);
15 }
16
17 async lint(html) {
18 const ruleViolations = [];
19 const report = await this.htmlValidate.validateString(html);
20 report.results.forEach((m) => {
21 ruleViolations.push(m.ruleId);
22 stubLogger?.debug('LintHtml', 'message', m);
23 })
24 assert(report.valid, '' + ruleViolations.join(', '));
25 }
26 }
27
28 module.exports = LintHtml;