-
Notifications
You must be signed in to change notification settings - Fork 56
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: role-supports-aria-props
rule (no aria-label
-misuse)
#362
Conversation
role-supports-aria-props
rule (no aria-label
-misuse)role-supports-aria-props
rule (no aria-label
-misuse)
@jfuchs Tests pass locally, but it looks like CI checks are failing with Node.js 12.x, but Node.js 12.x has reached end-of-life: https://nodejs.dev/en/about/releases/. Can the Node.js 12.x CI checks be removed? |
.eslintrc.js
Outdated
@@ -1,7 +1,7 @@ | |||
module.exports = { | |||
root: true, | |||
parserOptions: { | |||
ecmaVersion: 2020 | |||
ecmaVersion: 13 |
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 was added to support private fields (#data
on ObjectMap
)
@@ -0,0 +1,74 @@ | |||
# Role Supports ARIA Props |
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.
@@ -0,0 +1,180 @@ | |||
// @ts-check |
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.
Every method of ObjectMap
has at least one test in this file.
const {getElementType} = require('../utils/get-element-type') | ||
const ObjectMap = require('../utils/object-map') | ||
|
||
// Clean-up `elementRoles` from `aria-query` |
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.
eslint-plugin-jsx-a11y
(the upstream project) holds that, “[W]e don't want to store knowledge of WAI-ARIA in this plugin. That knowledge should be stored in aria-query
.”
I think that’s a good architectural principle in general, but unnecessary for temporary code like this file. Here, I’m okay mixing WAI-ARIA knowledge with rule code. It’ll get cleaned up once this custom rule is removed (replaced by the updated upstream rule).
@@ -0,0 +1,512 @@ | |||
// @ts-check | |||
|
|||
// Tests in this file were adapted from https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/__tests__/src/rules/role-supports-aria-props-test.js, which was authored by Ethan Cohen and is distributed under the MIT license as follows: |
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.
Do we have a convention for this kind of attribution?
@@ -0,0 +1,58 @@ | |||
// @ts-check | |||
const {isDeepStrictEqual} = require('util') |
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.
Shoutout to util.isDeepStrictEqual
, which I (re?)discovered while working on this.
It’s better than JSON.stringify
-based object comparison because it:
- Supports objects which can’t be serialized (e.g. due to circular references), and
- Ignores key order when determining equality
@@ -54,8 +54,8 @@ For each component, you may specify a `default` and/or `props`. `default` may ma | |||
"settings": { | |||
"github": { | |||
"components": { | |||
"Box": { "default": "p" }, | |||
"Link": { "props": {"as": { "undefined": "a", "a": "a", "button": "button"}}}, | |||
"Box": {"default": "p"}, |
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 was Prettier.
// - Get the element’s name | ||
const key = {name: getElementType(context, node)} | ||
// - Get the element’s disambiguating attributes | ||
for (const prop of ['aria-expanded', 'type', 'size', 'role', 'href', 'multiple', 'scope']) { |
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.
Originally, I’d dynamically generated this list of the attributes that are necessary for disambiguating elements with multiple roles (e.g. <input type="radio">
vs <input type="checkbox">
). But, given my nonchalance towards separation of concerns, the readability and performance gains, and the fact that this can’t lead to false positives, I opted for this simpler hardcoded list.
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.
Could we additionally configure this rule in: configs/react.js? This will ensure that the rule is enabled by default for those using this plugin's react
preset.
This otherwise looks good to me! Deferring to @github/web-systems-reviewers for final approval.
tests/role-supports-aria-props.js
Outdated
code: '<div aria-label />', | ||
errors: [getErrorMessage('aria-label', 'generic')] | ||
}, | ||
{ | ||
code: '<div aria-labelledby />', | ||
errors: [getErrorMessage('aria-labelledby', 'generic')] |
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.
🎉
…upports-aria-props' in the React config
From @khiga8 in #362 (review):
Good point! Done in e2d8376. I chose |
@smockle I just saw this comment! Lo and behold, I also just opened this PR #369 |
Awesome, thanks @theinterned! I’ll wait for #369 to be merged, then rebase here. |
The prettier config update serial commas, sorry. |
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.
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [eslint-plugin-github](https://togithub.com/github/eslint-plugin-github) | [`4.6.0` -> `4.6.1`](https://renovatebot.com/diffs/npm/eslint-plugin-github/4.6.0/4.6.1) | [![age](https://badges.renovateapi.com/packages/npm/eslint-plugin-github/4.6.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/eslint-plugin-github/4.6.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/eslint-plugin-github/4.6.1/compatibility-slim/4.6.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/eslint-plugin-github/4.6.1/confidence-slim/4.6.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>github/eslint-plugin-github</summary> ### [`v4.6.1`](https://togithub.com/github/eslint-plugin-github/releases/tag/v4.6.1) [Compare Source](https://togithub.com/github/eslint-plugin-github/compare/v4.6.0...v4.6.1) #### What's Changed - Update events handled by `no-useless-passive` and `require-passive-events` by [@​boris-petrov](https://togithub.com/boris-petrov) in [https://github.com/github/eslint-plugin-github/pull/354](https://togithub.com/github/eslint-plugin-github/pull/354) - feat: `role-supports-aria-props` rule (no `aria-label`-misuse) by [@​smockle](https://togithub.com/smockle) in [https://github.com/github/eslint-plugin-github/pull/362](https://togithub.com/github/eslint-plugin-github/pull/362) - Updated dependencies #### New Contributors - [@​boris-petrov](https://togithub.com/boris-petrov) made their first contribution in [https://github.com/github/eslint-plugin-github/pull/354](https://togithub.com/github/eslint-plugin-github/pull/354) - [@​smockle](https://togithub.com/smockle) made their first contribution in [https://github.com/github/eslint-plugin-github/pull/362](https://togithub.com/github/eslint-plugin-github/pull/362) **Full Changelog**: github/eslint-plugin-github@v4.6.0...v4.6.1 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "monthly" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/WtfJoke/setup-tectonic). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNTMuMiIsInVwZGF0ZWRJblZlciI6IjM0LjE1My4yIn0=-->
Fixes https://github.com/github/accessibility/issues/2427
From that issue:
This PR adapts the work I did in jsx-eslint/eslint-plugin-jsx-a11y#911 into a custom rule we can use until the upstream
role-suports-aria-props
is updated to flag<span aria-label="I’m a tooltip!">Info</span>
.