Skip to content

fix(a11y): only use baseConcepts in useSemanticElements rule (#9245)#9311

Open
ruidosujeira wants to merge 3 commits intobiomejs:mainfrom
ruidosujeira:fix/9245-use-semantic-elements-status-role
Open

fix(a11y): only use baseConcepts in useSemanticElements rule (#9245)#9311
ruidosujeira wants to merge 3 commits intobiomejs:mainfrom
ruidosujeira:fix/9245-use-semantic-elements-status-role

Conversation

@ruidosujeira
Copy link
Contributor

Summary

Fixes #9245

The useSemanticElements rule treated baseConcepts and relatedConcepts as equivalent when suggesting HTML element replacements. This caused incorrect suggestions — for example, suggesting <output> for <div role="status">, when <output> is only a relatedConcept of the "status" role.

The rule now only considers baseConcepts when suggesting semantic HTML elements.

Test Plan

Added test case for <div role="status"> to verify it no longer suggests <output>. Existing tests pass — roles with valid baseConcepts (e.g. navigation<nav>) continue to work as expected.

…#9245)

The rule previously treated baseConcepts and relatedConcepts identically,
causing incorrect suggestions like `<output>` for `role="status"`. Now it
only flags roles that have direct semantic HTML equivalents (baseConcepts).
@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: aeae6e6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Mar 3, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c45c63cd-276b-4d08-9c19-5f24df5d9ccb

📥 Commits

Reviewing files that changed from the base of the PR and between c41d4f1 and aeae6e6.

⛔ Files ignored due to path filters (3)
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid_self_closing.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/valid.jsx.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (5)
  • .changeset/fix-use-semantic-elements-base-concepts.md
  • crates/biome_js_analyze/src/lint/a11y/use_semantic_elements.rs
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid.jsx
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid_self_closing.jsx
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/valid.jsx
💤 Files with no reviewable changes (2)
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid.jsx
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid_self_closing.jsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • crates/biome_js_analyze/src/lint/a11y/use_semantic_elements.rs
  • .changeset/fix-use-semantic-elements-base-concepts.md
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/valid.jsx

Walkthrough

This PR corrects the useSemanticElements lint rule to exclude "status" and "alert" roles from suggesting the <output> element. The changes recognise that <output> is only a related concept for these roles, not a base concept, aligning with upstream "prefer-tag-over-role" guidance. Updates include rule logic, documentation comments, and test cases to reflect the refined behaviour addressing issue #9245.

Possibly related PRs

Suggested reviewers

  • ematipico
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the core fix: restricting the useSemanticElements rule to only use baseConcepts instead of relatedConcepts.
Description check ✅ Passed The description clearly explains the issue, the fix, and provides test coverage details relating to the changeset.
Linked Issues check ✅ Passed The PR fully addresses issue #9245 by restricting suggestions to baseConcepts and explicitly excluding status/alert roles, eliminating the incorrect suggestion for generic status messages.
Out of Scope Changes check ✅ Passed All changes are tightly scoped to fixing the useSemanticElements rule behavior—no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/valid.jsx`:
- Around line 46-69: The test block labelled “relatedConcepts-only” incorrectly
includes role="navigation" which should be tested as a baseConcept (navigation →
<nav>); remove the <div role="navigation"></div> from this valid JSX fragment
(the fragment containing the list of <div role="checkbox"> ... ) so the
navigation case remains covered by the baseConcept tests, or replace it with a
different relatedConcept-only role if you need to keep the same number of items.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 753be72 and c41d4f1.

⛔ Files ignored due to path filters (4)
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid_self_closing.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/valid.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/valid_issue_6384.tsx.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (6)
  • .changeset/fix-use-semantic-elements-base-concepts.md
  • crates/biome_js_analyze/src/lint/a11y/use_semantic_elements.rs
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid.jsx
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid_self_closing.jsx
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/valid.jsx
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/valid_issue_6384.tsx
💤 Files with no reviewable changes (3)
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/valid_issue_6384.tsx
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid.jsx
  • crates/biome_js_analyze/tests/specs/a11y/useSemanticElements/invalid_self_closing.jsx

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 3, 2026

Merging this PR will improve performance by 22.34%

⚡ 7 improved benchmarks
✅ 51 untouched benchmarks
⏩ 156 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
js_analyzer[parser_13571644119461115204.ts] 121.4 ms 108.4 ms +11.99%
js_analyzer[css_16118272471217147034.js] 31.5 ms 26.9 ms +17.42%
js_analyzer[lint_13640784270757307929.ts] 62.3 ms 55.4 ms +12.54%
js_analyzer[statement_263793315104667298.ts] 111.2 ms 90.9 ms +22.34%
js_analyzer[typescript_3735799142832611563.ts] 171.7 ms 141.9 ms +20.99%
js_analyzer[index_3894593175024091846.js] 68.6 ms 59 ms +16.2%
js_analyzer[router_17129688031671448157.ts] 34.3 ms 29.7 ms +15.6%

Comparing ruidosujeira:fix/9245-use-semantic-elements-status-role (c41d4f1) with main (464910c)2

Open in CodSpeed

Footnotes

  1. 156 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 (f6bb010) during the generation of this report, so 464910c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Comment on lines -3 to -6
<div role="checkbox" ></div>
<div role="radio" ></div>
<div role="heading" ></div>
<div role="separator" ></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah see, these feel like they should be flagged by the rule.

We should align ourselves with the source rule's behavior: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/rules/prefer-tag-over-role.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dyc3 Do you think the best approach would be to use both baseConcepts and relatedConcepts (aligning with the source rule), but add status to the exclusion list, similar to how combobox, listbox, and option are already excluded?

@ruidosujeira
Copy link
Contributor Author

I’m currently reviewing the requested changes and comparing the current implementation against the source rule behavior to make sure we preserve the expected cases while fixing the incorrect suggestion. I’m still evaluating the best approach, but I’m actively working on it and will update the PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lint/a11y: Prefer native element rule incorrectly suggests <output> instead of role="status" for loading indicators

2 participants