Create rule S6819 (#3866)

* Add html to rule S6819

* Add rule S6819 for html

* add noncompliant comments

---------

Co-authored-by: vdiez <vdiez@users.noreply.github.com>
Co-authored-by: Victor <victor.diez@sonarsource.com>
This commit is contained in:
github-actions[bot] 2024-04-12 11:18:00 +02:00 committed by GitHub
parent 4250db6bfc
commit 473c6826ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 61 additions and 46 deletions

View File

@ -0,0 +1 @@
Replace the ARIA role with an appropriate HTML tag.

View File

@ -0,0 +1,9 @@
== Resources
=== Documentation
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques[Using ARIA: Roles, states, and properties]
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles[ARIA roles (Reference)]
=== Standards
* W3C - https://www.w3.org/TR/wai-aria-1.2/[Accessible Rich Internet Applications (WAI-ARIA) 1.2]

View File

@ -0,0 +1,7 @@
== Why is this an issue?
ARIA (Accessible Rich Internet Applications) roles are used to make web content and web applications more accessible to people with disabilities. However, you should not use an ARIA role on a generic element (like `span` or `div`) if there is a semantic HTML tag with similar functionality, just use that tag instead.
For example, instead of using a div element with a button role (`<div role="button">Click me</div>`), you should just use a button element (`<button>Click me</button>`).
Semantic HTML tags are generally preferred over ARIA roles for accessibility due to their built-in functionality, universal support by browsers and assistive technologies, simplicity, and maintainability. They come with inherent behaviors and keyboard interactions, reducing the need for additional JavaScript. Semantic HTML also enhances SEO by helping search engines better understand the content and structure of web pages. While ARIA roles are useful, they should be considered a last resort when no suitable HTML element can provide the required behavior or semantics.

View File

@ -0,0 +1,2 @@
{
}

View File

@ -0,0 +1,15 @@
include::../common/why.adoc[]
[source,html,diff-id=1,diff-type=noncompliant]
----
<div role="button" onClick="myFunction()">Click me</div> <!-- Noncompliant -->
----
include::../common/fix.adoc[]
[source,html,diff-id=1,diff-type=compliant]
----
<button onClick="myFunction()">Click me</button>
----
include::../common/resources.adoc[]

View File

@ -1,25 +1,6 @@
{
"title": "Prefer tag over ARIA role",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"accessibility",
"react"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-6819",
"sqKey": "S6819",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "infeasible",
"code": {
"impacts": {
"MAINTAINABILITY": "LOW"
},
"attribute": "CONVENTIONAL"
}
]
}

View File

@ -1,37 +1,15 @@
== Why is this an issue?
ARIA (Accessible Rich Internet Applications) roles are used to make web content and web applications more accessible to people with disabilities. However, you should not use an ARIA role on a generic element (like `span` or `div`) if there is a semantic HTML tag with similar functionality, just use that tag instead.
For example, instead of using a div element with a button role (`<div role="button">Click me</div>`), you should just use a button element (`<button>Click me</button>`).
Semantic HTML tags are generally preferred over ARIA roles for accessibility due to their built-in functionality, universal support by browsers and assistive technologies, simplicity, and maintainability. They come with inherent behaviors and keyboard interactions, reducing the need for additional JavaScript. Semantic HTML also enhances SEO by helping search engines better understand the content and structure of web pages. While ARIA roles are useful, they should be considered a last resort when no suitable HTML element can provide the required behavior or semantics.
== How to fix it in JSX
Replace the ARIA role with an appropriate HTML tag.
=== Code examples
==== Noncompliant code example
include::../common/why.adoc[]
[source,javascript,diff-id=1,diff-type=noncompliant]
----
<div role="button" onClick={handleClick}>Click me</div>
<div role="button" onClick={handleClick} /* Noncompliant */>Click me</div>
----
==== Compliant solution
include::../common/fix.adoc[]
[source,javascript,diff-id=1,diff-type=compliant]
----
<button onClick={handleClick}>Click me</button>
----
== Resources
=== Documentation
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques[Using ARIA: Roles, states, and properties]
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles[ARIA roles (Reference)]
=== Standards
* W3C - https://www.w3.org/TR/wai-aria-1.2/[Accessible Rich Internet Applications (WAI-ARIA) 1.2]
include::../common/resources.adoc[]

View File

@ -1,2 +1,24 @@
{
"title": "Prefer tag over ARIA role",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"accessibility"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-6819",
"sqKey": "S6819",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "infeasible",
"code": {
"impacts": {
"MAINTAINABILITY": "LOW"
},
"attribute": "CONVENTIONAL"
}
}