fix(linter): support jsx-a11y attributes setting in anchor-is-valid rule#19808
fix(linter): support jsx-a11y attributes setting in anchor-is-valid rule#19808enesyukselx wants to merge 3 commits intooxc-project:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for the attributes setting in the anchor-is-valid jsx-a11y rule, allowing users to configure alternative attribute names (e.g., to for React Router's Link component) that should be treated as href equivalents. This brings the rule in line with other jsx-a11y rules that already support this configuration.
Changes:
- Added support for reading
settings["jsx-a11y"].attributes.hrefto determine valid href attribute names - Updated error messages to reflect configured attribute names when multiple alternatives are configured
- Added test cases for both passing (Link with valid
toprop) and failing (Link without any href-equivalent) scenarios - Fixed grammar in help messages from "an
href" to "ahref"
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/oxc_linter/src/rules/jsx_a11y/anchor_is_valid.rs | Updated missing_href_attribute function to accept valid attributes list and generate appropriate help messages; added logic to read attributes.href from settings and check all configured attribute names |
| crates/oxc_linter/src/snapshots/jsx_a11y_anchor_is_valid.snap | Updated snapshots to reflect grammar fix ("a" vs "an") and new test cases showing multi-attribute help messages |
Merging this PR will not alter performance
Comparing Footnotes
|
|
thanks! I had to pull these changes over to another branch as I wasn't able to push to your fork, unfortunately. |
Summary
The
anchor-is-validrule was not reading theattributessetting fromjsx-a11yplugin settings, even though the setting is already supported and documented for other rules.This meant users who configured alternative
hrefattribute names (e.g.tofor React Router'sLinkcomponent) would still get false positives:Changes
settings["jsx-a11y"].attributes.hrefinanchor-is-validto determine valid href attribute nameshref,tofor theaelement.)pass(validtoprop) andfail(Linkwithout any href-equivalent)