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:
parent
4250db6bfc
commit
473c6826ad
1
rules/S6819/common/fix.adoc
Normal file
1
rules/S6819/common/fix.adoc
Normal file
@ -0,0 +1 @@
|
||||
Replace the ARIA role with an appropriate HTML tag.
|
9
rules/S6819/common/resources.adoc
Normal file
9
rules/S6819/common/resources.adoc
Normal 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]
|
7
rules/S6819/common/why.adoc
Normal file
7
rules/S6819/common/why.adoc
Normal 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.
|
2
rules/S6819/html/metadata.json
Normal file
2
rules/S6819/html/metadata.json
Normal file
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
15
rules/S6819/html/rule.adoc
Normal file
15
rules/S6819/html/rule.adoc
Normal 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[]
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -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[]
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user