Skip to content

fix(linter): support jsx-a11y attributes setting in anchor-is-valid rule#19808

Closed
enesyukselx wants to merge 3 commits intooxc-project:mainfrom
enesyukselx:main
Closed

fix(linter): support jsx-a11y attributes setting in anchor-is-valid rule#19808
enesyukselx wants to merge 3 commits intooxc-project:mainfrom
enesyukselx:main

Conversation

@enesyukselx
Copy link
Copy Markdown

Summary

The anchor-is-valid rule was not reading the attributes setting from jsx-a11y plugin settings, even though the setting is already supported and documented for other rules.

This meant users who configured alternative href attribute names (e.g. to for React Router's Link component) would still get false positives:

// oxlint.config.js
defineConfig({
  settings: {
    "jsx-a11y": {
      components: { Link: "a" },
      attributes: { href: ["href", "to"] }, // was ignored by anchor-is-valid
    },
  },
});
// false positive before this fix
<Link to="https://example.com">click</Link>
//  ⚠ anchor-is-valid: Missing `href` attribute for the `a` element.

Changes

  • Read settings["jsx-a11y"].attributes.href in anchor-is-valid to determine valid href attribute names
  • Error message now reflects the configured attribute names (e.g. Provide one of href, to for the a element.)
  • Added test cases for both pass (valid to prop) and fail (Link without any href-equivalent)

@enesyukselx enesyukselx requested a review from camc314 as a code owner February 27, 2026 08:16
Copilot AI review requested due to automatic review settings February 27, 2026 08:16
@github-actions github-actions Bot added A-linter Area - Linter C-bug Category - Bug labels Feb 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.href to 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 to prop) and failing (Link without any href-equivalent) scenarios
  • Fixed grammar in help messages from "an href" to "a href"

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

@camc314 camc314 self-assigned this Feb 27, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 1, 2026

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 51 skipped benchmarks1


Comparing enesyukselx:main (27a3dd9) with main (1b7a937)2

Open in CodSpeed

Footnotes

  1. 51 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (ca1169f) during the generation of this report, so 1b7a937 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Comment thread crates/oxc_linter/src/rules/jsx_a11y/anchor_is_valid.rs Outdated
@camchenry
Copy link
Copy Markdown
Member

thanks! I had to pull these changes over to another branch as I wasn't able to push to your fork, unfortunately.

#21665

@camchenry camchenry closed this Apr 23, 2026
graphite-app Bot pushed a commit that referenced this pull request Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants