diff --git a/fast_htmlcs/HTMLCS.Util.ts b/fast_htmlcs/HTMLCS.Util.ts index 39fedc18..d7583f34 100644 --- a/fast_htmlcs/HTMLCS.Util.ts +++ b/fast_htmlcs/HTMLCS.Util.ts @@ -814,10 +814,13 @@ _global.HTMLCS.util = { * * @return void */ - eachParentNode: function (node, cb) { + eachParentNode: function (node, cb: (node: Element) => boolean) { while (node && node.parentNode) { - cb(node); + const c = cb(node); node = node.parentNode as Element; + if (c) { + break; + } } }, diff --git a/fast_htmlcs/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.ts b/fast_htmlcs/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.ts index 82d4521c..ec31b1f8 100755 --- a/fast_htmlcs/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.ts +++ b/fast_htmlcs/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.ts @@ -221,9 +221,9 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = { * @param {DOMNode} top The top element of the tested code. */ testLabelsOnInputs: function (element, _, muteErrors) { - let inputType = element.nodeName.toLowerCase(); + let inputType = element.nodeName; - if (inputType === "input") { + if (inputType === "INPUT") { if (element.hasAttribute("type")) { inputType = element.getAttribute("type").toLowerCase(); } else { @@ -233,7 +233,8 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = { let hasLabel: boolean | Record = false; - let addToLabelList = function (found) { + // this isnt really needed as an object + const addToLabelList = function (found) { if (!hasLabel) { hasLabel = {}; } @@ -256,33 +257,31 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = { } // Find an explicit label. - let explicitLabel = element.ownerDocument.querySelector( - 'label[for="' + element.id + '"]' - ); - if (explicitLabel) { + if ( + element.ownerDocument.querySelector('label[for="' + element.id + '"]') + ) { addToLabelList("explicit"); } // Find an implicit label. let foundImplicit = false; + if (element.parentNode) { HTMLCS.util.eachParentNode(element, function (parent) { - if (parent.nodeName.toLowerCase() === "label") { + if (parent.nodeName === "LABEL") { foundImplicit = true; } + return foundImplicit; }); } - // @ts-ignore - if (foundImplicit === true) { + if (foundImplicit) { addToLabelList("implicit"); } // Find a title attribute. - let title = element.getAttribute("title"); - - if (title !== null) { - if (/^\s*$/.test(title) === true && needsLabel === true) { + if (element.hasAttribute("title")) { + if (/^\s*$/.test(element.getAttribute("title")) === true && needsLabel) { HTMLCS.addMessage( HTMLCS.WARNING, element, @@ -295,8 +294,8 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = { } // Find an aria-label attribute. - if (element.hasAttribute("aria-label") === true) { - if (HTMLCS.util.hasValidAriaLabel(element) === false) { + if (element.hasAttribute("aria-label")) { + if (!HTMLCS.util.hasValidAriaLabel(element)) { HTMLCS.addMessage( HTMLCS.WARNING, element, @@ -309,8 +308,8 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = { } // Find an aria-labelledby attribute. - if (element.hasAttribute("aria-labelledby") === true) { - if (HTMLCS.util.hasValidAriaLabel(element) === false) { + if (element.hasAttribute("aria-labelledby")) { + if (!HTMLCS.util.hasValidAriaLabel(element)) { HTMLCS.addMessage( HTMLCS.WARNING, element, @@ -326,7 +325,7 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = { } if (!(muteErrors === true)) { - if (hasLabel !== false && needsLabel === false) { + if (hasLabel !== false && !needsLabel) { // Note that it is okay for buttons to have aria-labelledby or // aria-label, or title. The former two override the button text, // while title is a lower priority than either: the button text, @@ -348,7 +347,7 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = { "F68.HiddenAttr" ); } - } else if (hasLabel === false && needsLabel === true) { + } else if (hasLabel === false && needsLabel) { // Needs label. HTMLCS.addMessage( HTMLCS.ERROR, diff --git a/fast_htmlcs/globals.d.ts b/fast_htmlcs/globals.d.ts index 1d41e556..09a1b947 100644 --- a/fast_htmlcs/globals.d.ts +++ b/fast_htmlcs/globals.d.ts @@ -66,7 +66,7 @@ type HTMLCS = { HSVtosRGB(colour: HSV): RGB; getElementTextContent(element: Element, hasAlt?: boolean): string; findParentNode(node: Element, selector: string): Node; - eachParentNode(node: Element, cb: (node: Element) => void): void; + eachParentNode(node: Element, cb: (node: Element) => boolean): void; getChildrenForTable(table: Element, childNodeName: string): Element[]; testTableHeaders(table: Element): RetVal; getCellHeaders(tableCell: Element): Element[]; diff --git a/fast_htmlcs/package.json b/fast_htmlcs/package.json index fc09fca8..46992833 100644 --- a/fast_htmlcs/package.json +++ b/fast_htmlcs/package.json @@ -1,6 +1,6 @@ { "name": "fast_htmlcs", - "version": "0.0.65", + "version": "0.0.66", "description": "A high performance fork of HTML_CodeSniffer.", "license": "BSD-3-Clause", "main": "index.js", diff --git a/kayle/package.json b/kayle/package.json index 37487ed2..0589c35f 100644 --- a/kayle/package.json +++ b/kayle/package.json @@ -1,6 +1,6 @@ { "name": "kayle", - "version": "0.5.30", + "version": "0.5.31", "description": "Extremely fast and accurate accessibility testing using CDP", "main": "./build/index.js", "keywords": [