From 143a8c6feaedc01b053b1fd90089cf96a758ad57 Mon Sep 17 00:00:00 2001 From: taku10101 Date: Sun, 6 Oct 2024 20:53:18 +0900 Subject: [PATCH] fix: string null determination --- src/rules/alt-text.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rules/alt-text.js b/src/rules/alt-text.js index 495774563..f22b7014b 100644 --- a/src/rules/alt-text.js +++ b/src/rules/alt-text.js @@ -39,7 +39,7 @@ const ariaLabelHasValue = (prop) => { if (value === undefined) { return false; } - if (typeof value === 'string' && value.length === 0) { + if (typeof value === 'string' && value.length === 0 && value === '') { return false; } return true; @@ -62,7 +62,7 @@ const ruleByElement = { // Don't create an error if the attribute is used correctly. But if it // isn't, suggest that the developer use `alt` instead. const ariaLabelProp = getProp(node.attributes, 'aria-label'); - if (ariaLabelProp !== undefined) { + if (ariaLabelProp !== undefined || ariaLabelProp !== '') { if (!ariaLabelHasValue(ariaLabelProp)) { context.report({ node, @@ -134,7 +134,7 @@ const ruleByElement = { } const altProp = getProp(node.attributes, 'alt'); - if (altProp === undefined) { + if (altProp === undefined || altProp === '') { context.report({ node, message: 'Each area of an image map must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.', @@ -170,7 +170,7 @@ const ruleByElement = { } const altProp = getProp(node.attributes, 'alt'); - if (altProp === undefined) { + if (altProp === undefined || altProp === '') { context.report({ node, message: ' elements with type="image" must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.',