Skip to content

feat: implement includeRoles option for control-has-associated-label rule#1083

Open
rdcrampton wants to merge 1 commit intojsx-eslint:mainfrom
rdcrampton:feat/implement-include-roles-option
Open

feat: implement includeRoles option for control-has-associated-label rule#1083
rdcrampton wants to merge 1 commit intojsx-eslint:mainfrom
rdcrampton:feat/implement-include-roles-option

Conversation

@rdcrampton
Copy link
Copy Markdown

Summary

  • Implements the includeRoles option for the control-has-associated-label rule, which was configured in both recommended and strict configs (includeRoles: ['alert', 'dialog']) but never actually implemented in the rule logic
  • Elements with roles in includeRoles now correctly require an accessible text label

Fixes #1072

Changes

  • Added includeRoles to the rule's JSON schema
  • Destructured includeRoles from rule options with [] default
  • Added nodeIsIncludedRole check using includes(includeRoles, role) to the condition that triggers label validation
  • Updated tests: moved bare alert/dialog entries from alwaysValid to neverValid, added labeled valid cases, added no-config coverage, and added a dedicated includeRoles test section
  • Updated documentation with includeRoles option description and example

Design decisions

  • ignoreRoles takes precedence over includeRoles (checked first via early return) — explicit ignore wins
  • Not gated behind isDOMElement — custom components like <MyAlert role="alert" /> also require labels, consistent with controlComponents behavior
  • Hidden elements (aria-hidden="true") still excluded — checked before includeRoles

Test plan

  • All 1521 tests pass (npm run test)
  • Lint passes (npm run lint)
  • Flow passes (npm run flow)
  • Recommended config: alert/dialog without labels now correctly flagged
  • Strict config: same behavior as recommended
  • No-config: alert/dialog without labels remain valid (no includeRoles set)
  • Standalone includeRoles tests cover valid (labeled), invalid (unlabeled), and non-matching roles

…rule

The includeRoles option was configured in both recommended and strict
configs but never implemented in the rule logic, causing elements with
alert and dialog roles to silently skip the label check.

Fixes jsx-eslint#1072
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

includeRoles option in control-has-associated-label config is not implemented

1 participant