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
Add new rule no-invalid-aria-attributes
#2276
Conversation
5bd7274
to
0763126
Compare
} | ||
|
||
module.exports = class NoInvalidAriaAttributes extends Rule { | ||
logNode({ node, message }) { |
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.
This helper doesn't seem to be necessary, can we remove it?
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.
Let's remove this logNode
helper since it's no better than just calling this.log
directly.
@@ -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). |
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.
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: |
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.
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', |
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 imagine we should add this to recommended
in the upcoming v4 release right?
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. |
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. |
@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.
|
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.
Nice work on this so far.
} | ||
|
||
module.exports = class NoInvalidAriaAttributes extends Rule { | ||
logNode({ node, message }) { |
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.
Let's remove this logNode
helper since it's no better than just calling this.log
directly.
@judithhinlung do you think we can finish this up this week? If so, we can include it as a |
Hey @bmish unfortunately I don't think I will be able to finish this until sometime next week, when I return from my vacation. |
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", |
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.
@judithhinlung Looks like the build is failing because the listed deps are out of alphabetical order. aria-query
should come after @lint-todo/utils
.
…he aria-query dependency
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.
Looks good. Is this still a draft or is it ready?
Thanks for your great work on this! |
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:
Forbidden:
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.