From 32a1ad6cf77d3331e95ee5d35ab723607bf88712 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Tue, 21 Jan 2025 15:07:55 +0000 Subject: [PATCH 1/3] Refactor the text_size_too_small check to try more accurately determine if the node is the one to analyse It looks now at child nodes if they exist for TEXT_NODE types --- src/pageScanner/checks/text-size-too-small.js | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/pageScanner/checks/text-size-too-small.js b/src/pageScanner/checks/text-size-too-small.js index 5bf09a25..bbea3eba 100644 --- a/src/pageScanner/checks/text-size-too-small.js +++ b/src/pageScanner/checks/text-size-too-small.js @@ -12,7 +12,25 @@ const SMALL_FONT_SIZE_THRESHOLD = 10; export default { id: 'text_size_too_small', evaluate: ( node ) => { - // fails if the font size is less than or equal to 10px. - return fontSizeInPx( node ) <= SMALL_FONT_SIZE_THRESHOLD; + // If the node has no text content then it can't have text that's too small. + if ( ! node.textContent.trim().length ) { + return false; + } + + // If the node has no child nodes, then consider it as a text node itself and check it. + if ( ! node.childNodes.length ) { + return fontSizeInPx( node ) <= SMALL_FONT_SIZE_THRESHOLD; + } + + // Check onlychild nodes of the element that are text nodes. + let isTextTooSmall = false; + node.childNodes.forEach( ( child ) => { + if ( child.nodeType === Node.TEXT_NODE ) { + if ( fontSizeInPx( node ) <= SMALL_FONT_SIZE_THRESHOLD ) { + isTextTooSmall = true; + } + } + } ); + return isTextTooSmall; }, }; From fc2f3ec77590eb37b4a4aa4a7037209b06fde766 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Tue, 21 Jan 2025 18:50:30 +0000 Subject: [PATCH 2/3] Refactor the recent changes to text-too-small check This refactors for readability and clarity as well as to make the check a little bit quicker (avoiding iterations when already detecting TEXT_NODE children) --- src/pageScanner/checks/text-size-too-small.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/pageScanner/checks/text-size-too-small.js b/src/pageScanner/checks/text-size-too-small.js index bbea3eba..52f52d70 100644 --- a/src/pageScanner/checks/text-size-too-small.js +++ b/src/pageScanner/checks/text-size-too-small.js @@ -17,20 +17,14 @@ export default { return false; } - // If the node has no child nodes, then consider it as a text node itself and check it. - if ( ! node.childNodes.length ) { + // Check only if child nodes of the element that are text nodes. Nodes with no + // text children are treated as if they are a text node themselves. + const hasTextChild = Array.from( node.childNodes ).some( ( child ) => child.nodeType === Node.TEXT_NODE ); + if ( ! node.childNodes.length || hasTextChild ) { return fontSizeInPx( node ) <= SMALL_FONT_SIZE_THRESHOLD; } - // Check onlychild nodes of the element that are text nodes. - let isTextTooSmall = false; - node.childNodes.forEach( ( child ) => { - if ( child.nodeType === Node.TEXT_NODE ) { - if ( fontSizeInPx( node ) <= SMALL_FONT_SIZE_THRESHOLD ) { - isTextTooSmall = true; - } - } - } ); - return isTextTooSmall; + // Did not find any text that was too small. + return false; }, }; From b3d1abf25ed68920fc4d5e9503cf77d9a1998fae Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Wed, 22 Jan 2025 14:38:39 +0000 Subject: [PATCH 3/3] Improve some comments in text_site_too_small check --- src/pageScanner/checks/text-size-too-small.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pageScanner/checks/text-size-too-small.js b/src/pageScanner/checks/text-size-too-small.js index 52f52d70..b7eb6e7a 100644 --- a/src/pageScanner/checks/text-size-too-small.js +++ b/src/pageScanner/checks/text-size-too-small.js @@ -17,14 +17,16 @@ export default { return false; } - // Check only if child nodes of the element that are text nodes. Nodes with no - // text children are treated as if they are a text node themselves. + // Check if the node has any direct text nodes as children. For a node with no + // children, or with TEXT_NODE children, evaluate the nodes font size. This + // handles both leaf nodes and container elements with mixed content. const hasTextChild = Array.from( node.childNodes ).some( ( child ) => child.nodeType === Node.TEXT_NODE ); if ( ! node.childNodes.length || hasTextChild ) { return fontSizeInPx( node ) <= SMALL_FONT_SIZE_THRESHOLD; } - // Did not find any text that was too small. + // No text nodes were found in direct children, and this is not a leaf node, + // so we can safely ignore font size checks. return false; }, };