Inconsistent SonarQube Rule Regarding role='' Usage in HTML

There’s an ongoing contradiction in SonarQube’s guidance around accessibility roles in HTML elements. Specifically:

  • SonarQube recommends using native semantic elements like <button> for interactive components, as the preferred accessible pattern.
  • However, it also acknowledges that when native elements aren’t feasible, developers may apply ARIA roles such as role="button” to non-semantic tags like <div> or <span>, provided proper keyboard and interaction handlers are implemented.

Here’s the issue: when we follow that fallback approach and use role="button” on a <div>, it still fails SonarQube checks in our CI pipeline, reporting role=‘’ as a violation.

This inconsistency creates confusion. If the fallback is acceptable, then the rule engine should not penalise it by default. Ideally, the rule should:

  • Recognise ARIA roles used appropriately as a fallback
  • Offer guidance on when the role is misused (e.g., missing keyboard handlers)
  • Avoid flagging it altogether if implemented with supporting accessibility logic

This would help enforce best practices without obstructing valid implementations.

Screenshots attached for reference. Let us know if this is a rule configuration oversight or something that needs clarification on the rule definition side.


Environment:

  • Frontend Framework: React 18+
  • Language: TypeScript (strict mode enabled)
  • Build Tool: Vite
  • ECMAScript Target: ES2022


1 Like

Hi,

Welcome to the community and thanks for this report!

Could you provide the environment in which you’re seeing this? Specifically, SonarQube Cloud or SonarQube on-prem? And if the latter, what version?

 
Thx,
Ann

I’m only guessing, but since this is a part of a self-hosted Gitlab environment, it could be an on-prem installation. The version, I’m also guessing (from the logs) it’s 25.3.0.104237

Cheers!

Hi,

Thanks for that detail. Normally we only support the very latest release of Community Build, which is currently 25.8. However, I’m not seeing anything relevant-seeming in Jira, so I’ve flagged this for the language experts.

 

Ann

Hello @vmer-p1af,

I would say this is expected behaviour for both rules.

S6848 will check that if you add a listener to a non-interactive element, that element should have a role.

S6819 will raise if the given combination of element+role can be represented by a native element.

Both are independent, and once you have fixed S6848 adding the role, then S6819 raises because now the combination div+button can indeed be replaced by a button element.

Cheers

1 Like