Skip to content

Commit

Permalink
Create rule S6822 (#3859)
Browse files Browse the repository at this point in the history
* Add html to rule S6822

* Add relevant adoc

---------

Co-authored-by: zglicz <[email protected]>
Co-authored-by: Michal Zgliczynski <[email protected]>
  • Loading branch information
3 people authored Apr 9, 2024
1 parent d4d9b7e commit 18811ba
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 40 deletions.
7 changes: 7 additions & 0 deletions rules/S6822/common/indtroduction.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
== Why is this an issue?

include::../../../shared_content/jsts/aria-intro-1.adoc[]

In HTML, certain elements have default roles. Default roles, also known as implicit roles, are roles that are inherently associated with certain HTML elements. These roles provide information about what an element does or the type of content it contains, which is especially useful for assistive technologies like screen readers.

For example, a `<button>` element has a default role of `button`. If you explicitly define the role of a `<button>` element as `button`, it's considered redundant because it's the default role of that element.
Empty file.
2 changes: 2 additions & 0 deletions rules/S6822/html/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
23 changes: 23 additions & 0 deletions rules/S6822/html/rule.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include::../common/indtroduction.adoc[]

== How to fix it in JSX

Remove redundant ARIA role attribute.

=== Code examples

==== Noncompliant code example

[source,html,diff-id=1,diff-type=noncompliant]
----
<button role="button" onClick={handleClick}>OK</button>
----

==== Compliant solution

[source,html,diff-id=1,diff-type=compliant]
----
<button onClick={handleClick}>OK</button>
----

include::../common/resources.adoc[]
24 changes: 0 additions & 24 deletions rules/S6822/javascript/metadata.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,2 @@
{
"title": "No redundant ARIA role",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"accessibility",
"react"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-6822",
"sqKey": "S6822",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "targeted",
"code": {
"impacts": {
"MAINTAINABILITY": "LOW",
"RELIABILITY": "LOW"
},
"attribute": "CONVENTIONAL"
}
}
18 changes: 2 additions & 16 deletions rules/S6822/javascript/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
== Why is this an issue?

include::../../../shared_content/jsts/aria-intro-1.adoc[]

In HTML, certain elements have default roles. Default roles, also known as implicit roles, are roles that are inherently associated with certain HTML elements. These roles provide information about what an element does or the type of content it contains, which is especially useful for assistive technologies like screen readers.

For example, a `<button>` element has a default role of `button`. If you explicitly define the role of a `<button>` element as `button`, it's considered redundant because it's the default role of that element.
include::../common/indtroduction.adoc[]

== How to fix it in JSX

Expand All @@ -26,12 +20,4 @@ Remove redundant ARIA role attribute.
<button onClick={handleClick}>OK</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[]
24 changes: 24 additions & 0 deletions rules/S6822/metadata.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
{
"title": "No redundant ARIA role",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"accessibility",
"react"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-6822",
"sqKey": "S6822",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "targeted",
"code": {
"impacts": {
"MAINTAINABILITY": "LOW",
"RELIABILITY": "LOW"
},
"attribute": "CONVENTIONAL"
}
}

0 comments on commit 18811ba

Please sign in to comment.