a11y: implement media-has-caption rule

pull/4872/head
Arthur Denner 5 years ago
parent 4c135b0b8d
commit 954a34c0e3

@ -287,6 +287,29 @@ export default class Element extends Node {
}
}
if (this.is_media_node()) {
const has_muted_attribute = this.attributes.some(attr => attr.name === 'muted');
if (has_muted_attribute) {
return;
}
const is_track = (child: INode) => child.type === 'Element' && child.name === 'track';
const is_caption = (attr: Attribute) =>
attr.name === 'kind' &&
attr.get_static_value().toString().toLowerCase() === 'captions';
const has_captions = this.children.some(
child => !is_track(child) ? false : child.attributes.some(is_caption)
);
if (!has_captions) {
this.component.warn(this, {
code: `a11y-media-has-caption`,
message: `A11y: <${this.name}> should have a <track> for captions`
});
}
}
this.validate_attributes();
this.validate_special_cases();
this.validate_bindings();

@ -1,4 +1,8 @@
<video><track kind="captions"/></video>
<video></video>
<video><track /></video>
<audio muted></audio>
<video>
<track kind="captions" />
</video>
<video />
<video>
<track />
</video>
<audio muted />

@ -1,32 +1,32 @@
[
{
"code": "a11y-media-has-caption",
"end": {
"character": 55,
"column": 15,
"line": 2
},
"message": "A11y: Media elements must have a <track kind=\"captions\">",
"pos": 40,
"start": {
"character": 40,
"column": 0,
"line": 2
}
},
{
"code": "a11y-media-has-caption",
"end": {
"character": 80,
"column": 24,
"line": 3
},
"message": "A11y: Media elements must have a <track kind=\"captions\">",
"pos": 56,
"start": {
"character": 56,
"column": 0,
"line": 3
}
}
{
"code": "a11y-media-has-caption",
"end": {
"character": 55,
"column": 15,
"line": 2
},
"message": "A11y: Media elements must have a <track kind=\"captions\">",
"pos": 40,
"start": {
"character": 40,
"column": 0,
"line": 2
}
},
{
"code": "a11y-media-has-caption",
"end": {
"character": 80,
"column": 24,
"line": 3
},
"message": "A11y: Media elements must have a <track kind=\"captions\">",
"pos": 56,
"start": {
"character": 56,
"column": 0,
"line": 3
}
}
]

Loading…
Cancel
Save