diff --git a/api/functions/queries.js b/api/functions/queries.js index 7f38fead..b0f46447 100644 --- a/api/functions/queries.js +++ b/api/functions/queries.js @@ -378,5 +378,5 @@ exports.getCustomHtmlRuleOptions = (api, url) => for await (const item of entity) { result.push(item); } - resolve(result || {}) + resolve(result || []) }) \ No newline at end of file diff --git a/docker/api.js b/docker/api.js index 422ff09a..b431d536 100644 --- a/docker/api.js +++ b/docker/api.js @@ -132,7 +132,7 @@ exports.getCustomHtmlRuleOptions = (api, url) => { headers: { "Content-Type": "application/json" }, }).then((res) => { if (res) { - return res.json(); + return res.ok ? res.json() : []; } else { throw Error("Failed to get custom html rule options"); } diff --git a/docker/customHtmlRules.js b/docker/customHtmlRules.js index 21d7354c..7c22016f 100644 --- a/docker/customHtmlRules.js +++ b/docker/customHtmlRules.js @@ -3,7 +3,7 @@ const HTMLHint = require("htmlhint").default; const findPhoneNumbersInText = require('libphonenumber-js').findPhoneNumbersInText; exports.addCustomHtmlRule = async (apiToken, url) => { - const customRuleOptions = await getCustomHtmlRuleOptions(apiToken, url) + const customRuleOptions = await getCustomHtmlRuleOptions(apiToken, url); HTMLHint.addRule({ id: "code-block-missing-language", @@ -503,9 +503,9 @@ exports.addCustomHtmlRule = async (apiToken, url) => { init: function (parser, reporter) { const self = this; let isInCodeBlock = false; + let optionValue = ''; parser.addListener("tagstart", (event) => { // Check if custom options exist in this rule - let optionValue = ''; if (customRuleOptions && customRuleOptions.length > 0 && customRuleOptions.filter(option => option.ruleId === ruleId).length > 0) { optionValue = customRuleOptions.find(option => option.ruleId === ruleId).optionValue } diff --git a/docker/index.js b/docker/index.js index e73f565a..b72ef376 100644 --- a/docker/index.js +++ b/docker/index.js @@ -233,9 +233,9 @@ const processAndUpload = async ( if (args.htmlhint) { if (args.token) { - addCustomHtmlRule(args.token, args.url); + await addCustomHtmlRule(args.token, args.url); } else { - addCustomHtmlRule(); + await addCustomHtmlRule(); }; [htmlIssuesSummary, htmlIssues] = await runHtmlHint( args.url, diff --git a/docker/test/anchor-names-must-be-valid.spec.js b/docker/test/anchor-names-must-be-valid.spec.js index 4464b969..d738ac3c 100644 --- a/docker/test/anchor-names-must-be-valid.spec.js +++ b/docker/test/anchor-names-must-be-valid.spec.js @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules') ruleOptions[ruldId] = true +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it('Anchor name starts with letter and contains no space should not result in an error', () => { const code = 'Anchor' const messages = HTMLHint.verify(code, ruleOptions) diff --git a/docker/test/code-block-missing-language.spec.js b/docker/test/code-block-missing-language.spec.js index 1f949331..b98be909 100644 --- a/docker/test/code-block-missing-language.spec.js +++ b/docker/test/code-block-missing-language.spec.js @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules') ruleOptions[ruldId] = true +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it('Code block with data language specifier should not result in an error', () => { const code = '
Some Code' const messages = HTMLHint.verify(code, ruleOptions) diff --git a/docker/test/common-spelling-mistakes.spec.js b/docker/test/common-spelling-mistakes.spec.js index 5549b574..bd4bbd66 100644 --- a/docker/test/common-spelling-mistakes.spec.js +++ b/docker/test/common-spelling-mistakes.spec.js @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules"); ruleOptions[ruleId] = true; +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruleId}`, () => { - addCustomHtmlRule(); it("terms used correctly should not result in an error", () => { const code = "
aka email cannot website username taskbar
"; const messages = HTMLHint.verify(code, ruleOptions); diff --git a/docker/test/detect-absolute-references-correctly.spec.js b/docker/test/detect-absolute-references-correctly.spec.js index dd35056f..a673f692 100644 --- a/docker/test/detect-absolute-references-correctly.spec.js +++ b/docker/test/detect-absolute-references-correctly.spec.js @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules"); ruleOptions[ruldId] = true; +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it("Bad example should result in an error", () => { const code = ''; const messages = HTMLHint.verify(code, ruleOptions); diff --git a/docker/test/figure-must-use-the-right-code.spec.js b/docker/test/figure-must-use-the-right-code.spec.js index d67c3133..16313b7a 100644 --- a/docker/test/figure-must-use-the-right-code.spec.js +++ b/docker/test/figure-must-use-the-right-code.spec.js @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules"); ruleOptions[ruldId] = true; +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it("Figures not wrapped in figcaption must result in an error", () => { const code = "Figure: Caption
"; const messages = HTMLHint.verify(code, ruleOptions); diff --git a/docker/test/font-tag-must-not-be-used.spec.js b/docker/test/font-tag-must-not-be-used.spec.js index 165e1979..9164fb1d 100644 --- a/docker/test/font-tag-must-not-be-used.spec.js +++ b/docker/test/font-tag-must-not-be-used.spec.js @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules') ruleOptions[ruldId] = true +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it('Anything that is not font tag should not result in an error', () => { const code = 'Text
' const messages = HTMLHint.verify(code, ruleOptions) diff --git a/docker/test/grammar-scrum-terms.spec.js b/docker/test/grammar-scrum-terms.spec.js index a2ccff16..3ade66f1 100644 --- a/docker/test/grammar-scrum-terms.spec.js +++ b/docker/test/grammar-scrum-terms.spec.js @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules"); ruleOptions[ruldId] = true; +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it("Scrum terms that are cased correctly should not result in an error", () => { const code = "Scrum, Sprint, Product Owner, Scrum Master, Product Backlog, Sprint Review, Sprint Planning, Sprint Retrospective, Sprint Retro, Specification Review, Spec Review
"; diff --git a/docker/test/link-must-not-show-unc.spec.js b/docker/test/link-must-not-show-unc.spec.js index 5584a133..f48998ea 100644 --- a/docker/test/link-must-not-show-unc.spec.js +++ b/docker/test/link-must-not-show-unc.spec.js @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules') ruleOptions[ruldId] = true +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it('Href that does not show UNC should not result in an error', () => { const code = 'somelink' const messages = HTMLHint.verify(code, ruleOptions) diff --git a/docker/test/meta-tags-must-not-redirect.spec.js b/docker/test/meta-tags-must-not-redirect.spec.js index f407a16a..ddecba3b 100644 --- a/docker/test/meta-tags-must-not-redirect.spec.js +++ b/docker/test/meta-tags-must-not-redirect.spec.js @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules') ruleOptions[ruldId] = true +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it('Meta tags that does not refresh should not result in an error', () => { const code = '' const messages = HTMLHint.verify(code, ruleOptions) diff --git a/docker/test/page-must-not-show-email-addresses.spec.js b/docker/test/page-must-not-show-email-addresses.spec.js index e24babbe..7121a32f 100644 --- a/docker/test/page-must-not-show-email-addresses.spec.js +++ b/docker/test/page-must-not-show-email-addresses.spec.js @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules') ruleOptions[ruldId] = true +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it('Page that does not show email addresses should not result in an error', () => { const code = 'email address' const messages = HTMLHint.verify(code, ruleOptions) diff --git a/docker/test/phone-numbers-without-links.js b/docker/test/phone-numbers-without-links.js index d497254a..e9afb783 100644 --- a/docker/test/phone-numbers-without-links.js +++ b/docker/test/phone-numbers-without-links.js @@ -26,8 +26,11 @@ const nonPhoneNumbers = [ "20231024.16" ]; +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruleId}`, () => { - addCustomHtmlRule(); phoneNumbers.forEach((phone) => { it(`text containing "${phone}" without hyperlink should error`, () => { diff --git a/docker/test/url-must-be-formatted-correctly.spec.js b/docker/test/url-must-be-formatted-correctly.spec.js index eb030877..cc0d9aaa 100644 --- a/docker/test/url-must-be-formatted-correctly.spec.js +++ b/docker/test/url-must-be-formatted-correctly.spec.js @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules"); ruleOptions[ruldId] = true; +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it("URL with full stop at the end should result in an error", () => { const code = ''; const messages = HTMLHint.verify(code, ruleOptions); diff --git a/docker/test/url-must-not-have-click-here.spec.js b/docker/test/url-must-not-have-click-here.spec.js index fe0ceef7..bf5ede55 100644 --- a/docker/test/url-must-not-have-click-here.spec.js +++ b/docker/test/url-must-not-have-click-here.spec.js @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules') ruleOptions[ruldId] = true +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it('URL text without words click here should not result in an error', () => { const code = 'Not Click Here' const messages = HTMLHint.verify(code, ruleOptions) diff --git a/docker/test/url-must-not-have-space.spec.js b/docker/test/url-must-not-have-space.spec.js index 0a85a2c0..81f909f6 100644 --- a/docker/test/url-must-not-have-space.spec.js +++ b/docker/test/url-must-not-have-space.spec.js @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules') ruleOptions[ruldId] = true +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it('URL without space should not result in an error', () => { const code = '' const messages = HTMLHint.verify(code, ruleOptions) diff --git a/docker/test/use-unicode-hex-code-for-special-html-characters.spec.js b/docker/test/use-unicode-hex-code-for-special-html-characters.spec.js index d506f70e..27041d6c 100644 --- a/docker/test/use-unicode-hex-code-for-special-html-characters.spec.js +++ b/docker/test/use-unicode-hex-code-for-special-html-characters.spec.js @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules"); ruleOptions[ruldId] = true; +before(async () => { + await addCustomHtmlRule(); +}); + describe(`Rules: ${ruldId}`, () => { - addCustomHtmlRule(); it("Non code tag with special char should result in an error", () => { const code = 'aaa>bbb