validating words contained in other words

pull/4750/head
André Lins 6 years ago
parent 5dcabfdad0
commit 3d8d76ca21

@ -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 <img> elements as an image.`

@ -2,4 +2,6 @@
<img src="bar" aria-hidden alt="Picture of me taking a photo of an image" />
<img src="foo" alt="Photo of foo being weird." />
<img src="bar" alt="Image of me at a bar!" />
<img src="baz" alt="Picture of baz fixing a bug." />
<img src="foo" alt="Picture of baz fixing a bug." />
<img src="bar" alt="Plant doing photosynthesis in the afternoon" />
<img src="foo" alt="Picturesque food" />
Loading…
Cancel
Save