Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(a11y): add warning missing lang on html tag #828

Merged
merged 2 commits into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/validate/html/a11y.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
5 changes: 5 additions & 0 deletions test/validator/samples/a11y-html-has-lang/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html lang="en"></html>
<html lang="en-US"></html>
<html lang={{language}}></html>

<html></html>
10 changes: 10 additions & 0 deletions test/validator/samples/a11y-html-has-lang/warnings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"loc": {
"column": 0,
"line": 5
},
"message": "A11y: <html> element should have a lang attribute",
"pos": 82
}
]