fix(linter): no-redundant-roles false positives for <header>, <footer>, and <input>#22745
Open
12122J wants to merge 3 commits into
Open
fix(linter): no-redundant-roles false positives for <header>, <footer>, and <input>#2274512122J wants to merge 3 commits into
12122J wants to merge 3 commits into
Conversation
…>, and <input> `<header>` and `<footer>` have ancestor-dependent implicit roles: they are only "banner"/"contentinfo" when *not* inside article/aside/main/ nav/section. Without traversing ancestors we cannot know the correct role, so we skip them entirely — matching eslint-plugin-jsx-a11y. For `<input>`, the static element-role map listed all *possible* input roles (combobox, checkbox, radio, etc.). The rule was treating any of those as redundant, so `<input role="combobox">` without a `list` attribute was wrongly flagged even though a plain text input's implicit role is `textbox`, not `combobox`. The fix computes the concrete implicit role from the element's actual `type` and `list` attributes using the HTML-AAM mapping. Fixes oxc-project#22743
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #22743
Root cause
Two separate issues caused false positives:
<header>and<footer>: Their implicit roles ("banner" / "contentinfo") are ancestor-dependent — they only apply when the element is not insidearticle,aside,main,nav, orsection. The rule cannot determine the correct role without ancestor traversal, so it was always treating the role as redundant. This matches the same approach taken byeslint-plugin-jsx-a11y, which omits these elements for the same reason.<input>: The staticELEMENT_ROLE_MAPlists all possible roles for<input>(combobox, checkbox, radio, textbox, etc.). The rule was accepting any of them as implicit, so<input role="combobox">with nolistattribute was flagged even though a plain text input's implicit role istextbox, notcombobox— thecomboboxrole only applies when alistattribute points to a<datalist>(HTML-AAM §3.5.77).Fix
<header>and<footer>in the rule entirely.<input>, compute the concrete implicit role from the element's actualtypeandlistattributes instead of accepting every role from the static map.Tests
<header role="banner">and<footer role="contentinfo">to the pass set (moved from fail).<input role="combobox">(no list) and<input role="combobox" type="text">(no list) to the pass set.<input>with roles that correctly match the element's attributes.AI disclosure
I used Claude Code to locate the relevant files and assist with writing the fix. The solution was reviewed and validated by running the test suite locally (
cargo test --lib -p oxc_linter -- no_redundant_rolespasses).