From 3d8d76ca21baf94661338c1184c2757295c18f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lins?= Date: Thu, 30 Apr 2020 10:01:50 -0300 Subject: [PATCH] validating words contained in other words --- src/compiler/compile/nodes/Element.ts | 7 +------ test/validator/samples/a11y-img-redundant-alt/input.svelte | 4 +++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index b9d2672168..24bf6c8558 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -486,14 +486,9 @@ export default class Element extends Node { const aria_hidden_exist = aria_hidden_attribute && aria_hidden_attribute.get_static_value(); if (alt_attribute && !aria_hidden_exist) { - const invalid_words = ['image', 'photo', 'picture']; const alt_value = alt_attribute.get_static_value(); - const contain_invalid_word = invalid_words.some(word => - alt_value.toLowerCase().includes(word) - ); - - if (contain_invalid_word) { + if (alt_value.toLowerCase().match(/\b(image|picture|photo)\b/g)) { component.warn(this, { code: `a11y-img-redundant-alt`, message: `A11y: Screenreaders already announce elements as an image.` diff --git a/test/validator/samples/a11y-img-redundant-alt/input.svelte b/test/validator/samples/a11y-img-redundant-alt/input.svelte index 06d8ef06d1..3ba029844d 100644 --- a/test/validator/samples/a11y-img-redundant-alt/input.svelte +++ b/test/validator/samples/a11y-img-redundant-alt/input.svelte @@ -2,4 +2,6 @@ Picture of me taking a photo of an image Photo of foo being weird. Image of me at a bar! -Picture of baz fixing a bug. \ No newline at end of file +Picture of baz fixing a bug. +Plant doing photosynthesis in the afternoon +Picturesque food \ No newline at end of file