From 8639359aa77731fc439ea095785c401ff6907c7c Mon Sep 17 00:00:00 2001 From: jpsc Date: Thu, 7 Sep 2017 23:18:26 +0200 Subject: [PATCH 1/2] feat(a11y): add warning missing lang on html tag --- src/validate/html/a11y.ts | 7 ++++++- test/validator/samples/a11y-html-has-lang/input.html | 5 +++++ .../validator/samples/a11y-html-has-lang/warnings.json | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/validator/samples/a11y-html-has-lang/input.html create mode 100644 test/validator/samples/a11y-html-has-lang/warnings.json diff --git a/src/validate/html/a11y.ts b/src/validate/html/a11y.ts index 205a6388f5..94061e9b19 100644 --- a/src/validate/html/a11y.ts +++ b/src/validate/html/a11y.ts @@ -143,6 +143,11 @@ export default function a11y( shouldHaveAttribute(['title']); } + // html-has-lang + if (node.name === 'html') { + shouldHaveAttribute(['lang']); + } + // no-distracting-elements if (node.name === 'marquee' || node.name === 'blink') { validator.warn(`A11y: Avoid <${node.name}> elements`, node.start); @@ -168,4 +173,4 @@ function getValue(attribute: Node) { if (attribute.value.length === 1 && attribute.value[0].type === 'Text') return attribute.value[0].data; return null; -} \ No newline at end of file +} diff --git a/test/validator/samples/a11y-html-has-lang/input.html b/test/validator/samples/a11y-html-has-lang/input.html new file mode 100644 index 0000000000..0fa84d90a6 --- /dev/null +++ b/test/validator/samples/a11y-html-has-lang/input.html @@ -0,0 +1,5 @@ + + + + + diff --git a/test/validator/samples/a11y-html-has-lang/warnings.json b/test/validator/samples/a11y-html-has-lang/warnings.json new file mode 100644 index 0000000000..fc1066cffe --- /dev/null +++ b/test/validator/samples/a11y-html-has-lang/warnings.json @@ -0,0 +1,10 @@ +[ + { + "loc": { + "column": 0, + "line": 5 + }, + "message": "A11y: element should have a lang attribute", + "pos": 82 + } + ] From c872234a4b7320a6db377f8df2817b8a30408201 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 7 Sep 2017 17:30:18 -0400 Subject: [PATCH 2/2] Update input.html --- test/validator/samples/a11y-html-has-lang/input.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validator/samples/a11y-html-has-lang/input.html b/test/validator/samples/a11y-html-has-lang/input.html index 0fa84d90a6..41f2fc6276 100644 --- a/test/validator/samples/a11y-html-has-lang/input.html +++ b/test/validator/samples/a11y-html-has-lang/input.html @@ -1,5 +1,5 @@ - +