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

Add new rule no-invalid-aria-attributes #2276

Merged

Conversation

judithhinlung
Copy link
Collaborator

@judithhinlung judithhinlung commented Dec 14, 2021

This PR adds the new rule no-invalid-aria-attributes which fixes #2275 .

Background

Currently, Ember-template-lint does not prevent invalid ARIA attributes, or any ARIA-* properties not found in the WAI-ARIA States and Properties spec, on an element. Using invalid ARIA attributes reduces usability by failing to provide the element it belongs to with the intended accessibility function.

This proposes the authoring of a new rule that enforces that ARIA attributes should be valid, and invalid attributes will generate an error.
Reference:
Supported States and Properties | Accessible Rich Internet Applications (WAI-ARIA) 1.0

Allowed:

# examples
<input type="email" aria-required="true" />
<div role="region" aria-live="polite">Valid live region</div>

Forbidden:

# examples
<input type="text" aria-text="inaccessible text" />
<div role="alert" aria--live="polite"></div>

Testing

Test Suites: 130 passed, 130 total
Tests: 6 skipped, 7051 passed, 7057 total
Snapshots: 887 passed, 887 total
Time: 50.697 s, estimated 55 s
Ran all test suites.
✨ Done in 62.73s.

}

module.exports = class NoInvalidAriaAttributes extends Rule {
logNode({ node, message }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper doesn't seem to be necessary, can we remove it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this logNode helper since it's no better than just calling this.log directly.

lib/rules/no-invalid-aria-attributes.js Outdated Show resolved Hide resolved
lib/rules/no-invalid-aria-attributes.js Outdated Show resolved Hide resolved
docs/rule/no-invalid-aria-attributes.md Outdated Show resolved Hide resolved
@@ -0,0 +1,22 @@
# no-invalid-aria-attributes

This rule checks for the use of invalid ARIA attributes, or any aria-\* property on an element that is not included in the [WAI-ARIA States and Properties spec](https://www.w3.org/WAI/PF/aria-1.1/states_and_properties).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what happens when someone uses a non-existent aria attribute? E.g. A non-existent ARIA attribute has no effect.


## Examples

This rule **forbids** the following:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything else we can validate about ARIA attributes? Anything we validate about their values or what attributes they are used on? It's easier to make this rule comprehensive now and cover multiple things, since adding violations later will be a breaking change.

@@ -13,6 +13,7 @@ module.exports = {
'no-duplicate-landmark-elements': 'error',
'no-empty-headings': 'error',
'no-heading-inside-button': 'error',
'no-invalid-aria-attributes': 'error',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine we should add this to recommended in the upcoming v4 release right?

docs/rule/no-invalid-aria-attributes.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@judithhinlung
Copy link
Collaborator Author

aria-query is a package that contains all the existing ARIA attributes and their valid types and values, which would be very useful in implementing the attribute-value checks. However, when looking at the other lint rules, I don't see any of them using an external import. Is it preferred for ETL rules to be self-contained, or could I leverage this package in my implementation of this rule?

@bmish
Copy link
Member

bmish commented Dec 16, 2021

aria-query is a package that contains all the existing ARIA attributes and their valid types and values, which would be very useful in implementing the attribute-value checks. However, when looking at the other lint rules, I don't see any of them using an external import. Is it preferred for ETL rules to be self-contained, or could I leverage this package in my implementation of this rule?

@judithhinlung I'm open to adding this dependency, since it sounds like it will make this lint rule much more powerful. Let's give it a try.

@judithhinlung
Copy link
Collaborator Author

I have updated this PR to use the NPM package Aria-query as the source of truth for ARIA validation. This PR now also includes validation for ARIA property types and the use of permitted values. The no-invalid-aria-attribute rule is now essentially a direct port of the JSX rules aria-props and Aria-proptypes.

@bmish
Copy link
Member

bmish commented Dec 24, 2021

@judithhinlung it looks like there is missing test coverage so the tests are failing. Note that we need to ensure every line in the rule file is covered by tests.

  no-invalid-aria-attributes.js                  |   88.24 |     80.3 |     100 |   88.24 | 26-28,42,44,48,54,80,87                         

Copy link
Member

@bmish bmish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this so far.

}

module.exports = class NoInvalidAriaAttributes extends Rule {
logNode({ node, message }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this logNode helper since it's no better than just calling this.log directly.

lib/rules/no-invalid-aria-attributes.js Outdated Show resolved Hide resolved
@bmish
Copy link
Member

bmish commented Jan 4, 2022

@judithhinlung do you think we can finish this up this week? If so, we can include it as a recommended rule in the upcoming v4 release (#1908) which I'd like to release later this week.

@judithhinlung
Copy link
Collaborator Author

Hey @bmish unfortunately I don't think I will be able to finish this until sometime next week, when I return from my vacation.

@bmish bmish mentioned this pull request Jan 6, 2022
@judithhinlung
Copy link
Collaborator Author

I have updated this PR with more test coverage, removed the extraneous logNode helper, and modified the invalid-ARIA-attribute message to say that the attribute is not recognized.

package.json Outdated
@@ -61,6 +61,7 @@
]
},
"dependencies": {
"aria-query": "^5.0.0",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@judithhinlung Looks like the build is failing because the listed deps are out of alphabetical order. aria-query should come after @lint-todo/utils.

Copy link
Member

@bmish bmish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Is this still a draft or is it ready?

lib/rules/no-invalid-aria-attributes.js Show resolved Hide resolved
@judithhinlung judithhinlung marked this pull request as ready for review January 18, 2022 19:21
@bmish
Copy link
Member

bmish commented Jan 18, 2022

Thanks for your great work on this!

@bmish bmish merged commit fbf4790 into ember-template-lint:master Jan 18, 2022
@bmish bmish added this to the 4.1.0 milestone Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal for new a11y check to disallow invalid ARIA attributes
3 participants