From 8f217a3be7082e6dd3a99183549776a72d569a01 Mon Sep 17 00:00:00 2001 From: aidamarfuaty Date: Tue, 29 Oct 2024 16:05:57 +0100 Subject: [PATCH] Improve check --- .../assessments/readability/ListAssessment.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/yoastseo/src/scoring/assessments/readability/ListAssessment.js b/packages/yoastseo/src/scoring/assessments/readability/ListAssessment.js index ac2b9441b09..e2ecc1a587a 100644 --- a/packages/yoastseo/src/scoring/assessments/readability/ListAssessment.js +++ b/packages/yoastseo/src/scoring/assessments/readability/ListAssessment.js @@ -47,17 +47,13 @@ export default class ListAssessment extends Assessment { */ findList( paper ) { const foundLists = paper.getTree().findAll( node => node.name === "ul" || node.name === "ol" ); + /* + This is a helper function to check if a list is not empty. + A list is not empty if it has at least one
  • child with paragraph node. + */ + const isListNotEmpty = list => list.childNodes.some( child => child.name === "li" && child.childNodes.some( node => node.name === "p" ) ); - for ( const list of foundLists ) { - for ( const child of list.childNodes ) { - // A list is not empty if it has at least one
  • child with text. - if ( child.name === "li" && child.childNodes.some( node => node.name === "p" ) ) { - return true; - } - } - } - - return false; + return foundLists.some( isListNotEmpty ); } /**