-
Notifications
You must be signed in to change notification settings - Fork 235
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
Lint compiled HTML #2569
Lint compiled HTML #2569
Conversation
✅ You can preview this change here:
To edit notification comments on pull requests, go to your Netlify site settings. |
Do you have a sample of what problems it's finding? Nearly 2000 issues seems like an excessive number! Also I imagine there are examples of invalid code where things are wrong-on-purpose because they have better outcomes for the end user (e.g. our use of aria-attributes on conditional checkboxes/radios). We probably want to treat those exceptionally. |
I swiped the config for this from the govuk-frontend component tests, so hopefully most of the special cases are already accounted for, but I haven't delved too deeply yet. Rules broken:
There's a lot of what I'm pretty sure is noise:
Probably legit errors include:
🤷
Etc, etc. So I'm assuming 90% of the errors could (safely) be ignored, but haven't really had a close look. |
@domoscargin I think this it great 🙌 Gives us more confidence that Markdown/Nunjucks is outputting what we want |
4fccffc
to
64571aa
Compare
64571aa
to
53a6c34
Compare
45f4cd2
to
7ee9ec6
Compare
I've created an issue to deal with some invalid HTML here: #2606 Down to 65 errors to check. |
I've added another issue to deal with nested form elements here: #2609 In addition, #2260 is causing Once #2606, #2609 and #2260 are fixed, we can remove some of the changes made here. |
88d500d
to
5a03989
Compare
e4573d2
to
958e5a9
Compare
@@ -11,7 +11,7 @@ | |||
<button hidden class="app-navigation__button js-app-navigation__button"> | |||
{{ item.label }} | |||
</button> | |||
|
|||
<!-- [html-validate-disable-next aria-label-misuse --- inline fix for html-validate rule, rather than disable it entirely] --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we got an issue for this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a deliberate choice for accessibility: 4ff06e4
@36degrees dya reckon I should make an issue to review this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure where the list of 'allowed elements' on https://html-validate.org/rules/aria-label-misuse.html comes from… according to https://www.w3.org/TR/html-aria/#el-li li
is not listed as 'Naming Prohibited' and the listitem
role inherits the aria-label
property… 🤔
The rationale in the linked commit makes sense to me, but I think given it's been flagged it might be worth asking @davidc-gds to review it just in case? Whether or not we need an issue for that I'm unsure – maybe ask David?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Might dig about a bit in the html-validate
source code and figure out if it's worth filing a bug. Will speak to David as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so the <ul>
text reads:
Global aria-* attributes and any aria-* attributes applicable to the allowed roles.
Which is sort of ambiguous, but I think basically means we need to apply a role to the <ul>
element - if we do that, then html-validate
is happy.
By default, the <ul>
has the list
role, which is:
allowed, but NOT RECOMMENDED.
I guess the menu
role or navigation
feels most appropriate here? Though it's already contained within a nav
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, I think this could do with an issue 😂
I'll make one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aah, of course – not sure why I was looking at <li>
!
By default, the
<ul>
has thelist
role, which is:allowed, but NOT RECOMMENDED.
I believe when they say it's 'allowed but not recommended' they mean it's not recommended to set this role explicitly – if you take a look at the headings for the table it says "Implicit ARIA semantics (explicitly assigning these in markup is NOT RECOMMENDED)".
I guess the
menu
role ornavigation
feels most appropriate here? Though it's already contained within anav
.
We should avoid the navigation role for exactly that reason – it's already in a nav region. The menu
role is designed for interfaces that mimic desktop app style interfaces where you have menus with lists of items, like in a 'menu bar' and wouldn't be appropriate here.
list
still feels like the appropriate role – I think if we changed it, we'd lose the information like 'List, 10 items' that screen reader users get which helps them understand how many links there are, for example.
Still worth having an issue to explore further, but I think either 1) having an aria-label
is fine on a <ul>
and is useful for users or 2) we should just remove the aria-label
. I don't think changing the role makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an issue and linked to this discussion.
0dad696
to
8d9c836
Compare
f01d5af
to
f8447a6
Compare
The `frameborder` attribute is deprecated, but we use it to make things look a bit better on IE8, so for now we can tell html-validate to treat it as undeprecated.
The self-closing / has no effect on the start tags of void elements in HTML5. For this reason, we should standardise on omitting them. https://html.spec.whatwg.org/dev/syntax.html#start-tags #1122
This technique relates to providing descriptive link text to anchor elements. Our anchor for the Back To Top button is flagged, but automated tests don't flag it, so I think we can probably ignore this.
We use double quotes for strings in our Nunjucks macros, and occasionally this means we need to use single quotes for the text content within them.
There doesn't appear to be any easy way to hook into the rule via config, and it's worth having to catch cases where we DIDN'T intend it, but in our case we've added it purposefully: #1038
The first govukCheckboxes (named "checkbox") gets items id'd checkbox, checkbox-2, checkbox-3. The second govukCheckboxes (named "checkbox-2" gets items id'd checkbox-2, checkbox-2-2, checkbox-2-3. So we get a duplicate "checkbox-2" id unless we change the names.
8097466
to
e6b9853
Compare
Previously, we didn't actually need to build, since the tests didn't use the compiled files. Now, the HTML linting does require a build, but that's handled within `npm test`
d409df5
to
ffd0391
Compare
We currently have no built-in way of ensuring our compiled HTML changes in the way we expect, and doesn't break.
This PR adds HTML linting using
html-validate
. There are quite a few commits, but they're all really small, promise!There are some issues to consider:
<h1>
tags, which introduces invalid child elements. See Status tags in headings are invalid HTML #2606<form>
elements, but it's still messy