From d7b9e99eaaa3d5df85c00274bb5f5e61e0fe85d9 Mon Sep 17 00:00:00 2001 From: Cebreus Date: Mon, 12 Jun 2023 14:19:20 +0200 Subject: [PATCH] fix: compatibility with html-validate 8.x --- index.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 71bfc6b..6abea45 100644 --- a/index.js +++ b/index.js @@ -19,27 +19,23 @@ module.exports = gulpHtmlValidate; function gulpHtmlValidate() { const htmlvalidate = htmlValidateCli.getValidator(); - return through.obj((file, encoding, callback) => { - if (file.isNull()) { - callback(null, file); - return; - } + return through.obj(async (file, encoding, callback) => { + try { + if (file.isNull() || file.isStream()) { + throw new PluginError(pluginName, 'File is null or Streaming not supported'); + } - if (file.isStream()) { - callback(new PluginError(pluginName, 'Streaming not supported')); + const result = await htmlvalidate.validateString(file.contents.toString(), file.path); + file.htmlValidateResult = result; + } catch (err) { + callback(err); return; } - - const result = htmlvalidate.validateString( - file.contents.toString(), - file.path - ); - file.htmlValidateResult = result; - callback(null, file); }); } + /** * Print a report where all errors/warnings are listed. *