Skip to content

Commit

Permalink
Create rule S6821: Implement rule in html (#3855)
Browse files Browse the repository at this point in the history
* Add html to rule S6821

* Update with html rspec

* Share rationale

* Address comments

* Comments

---------

Co-authored-by: zglicz <[email protected]>
Co-authored-by: Michal Zgliczynski <[email protected]>
Co-authored-by: Victor <[email protected]>
  • Loading branch information
4 people authored Apr 11, 2024
1 parent 582885b commit 289d34d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 41 deletions.
3 changes: 3 additions & 0 deletions rules/S6821/fix.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
== How to fix it

Check that each element with a defined ARIA role has a valid non-abstract value.
2 changes: 2 additions & 0 deletions rules/S6821/html/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
21 changes: 21 additions & 0 deletions rules/S6821/html/rule.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include::../rationale.adoc[]

include::../fix.adoc[]

[source,html,diff-id=1,diff-type=noncompliant]
----
<div role="meth" aria-label="a^{2} + b^{2} = c^{2}">
a<sup>2</sup> + b<sup>2</sup> = c<sup>2</sup>
</div>
----

To fix the code use a valid value for the ARIA role attribute.

[source,html,diff-id=1,diff-type=compliant]
----
<div role="math" aria-label="a^{2} + b^{2} = c^{2}">
a<sup>2</sup> + b<sup>2</sup> = c<sup>2</sup>
</div>
----

include::../resources.adoc[]
24 changes: 0 additions & 24 deletions rules/S6821/javascript/metadata.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,2 @@
{
"title": "DOM elements with ARIA roles should have a valid non-abstract role",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"react",
"accessibility"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-6821",
"sqKey": "S6821",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "infeasible",
"code": {
"impacts": {
"MAINTAINABILITY": "LOW",
"RELIABILITY": "MEDIUM"
},
"attribute": "LOGICAL"
}
}
20 changes: 3 additions & 17 deletions rules/S6821/javascript/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
== Why is this an issue?

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

This rule checks that when using the `role` property in DOM elements, its value is a valid non-abstract ARIA role.
include::../rationale.adoc[]

This rule does not cover non-DOM elements, such as custom components.

== How to fix it in JSX

Check that each element with a defined ARIA role has a valid non-abstract value.
include::../fix.adoc[]

[source,javascript,diff-id=1,diff-type=noncompliant]
----
Expand All @@ -26,12 +20,4 @@ To fix the code use a valid value for the ARIA role attribute.
</div>
----

== 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::../resources.adoc[]
24 changes: 24 additions & 0 deletions rules/S6821/metadata.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
{
"title": "DOM elements with ARIA roles should have a valid non-abstract role",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"react",
"accessibility"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-6821",
"sqKey": "S6821",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "infeasible",
"code": {
"impacts": {
"MAINTAINABILITY": "LOW",
"RELIABILITY": "MEDIUM"
},
"attribute": "LOGICAL"
}
}
5 changes: 5 additions & 0 deletions rules/S6821/rationale.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
== Why is this an issue?

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

This rule checks that when using the `role` property in DOM elements, its value is a valid non-abstract ARIA role.
9 changes: 9 additions & 0 deletions rules/S6821/resources.adoc
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 289d34d

Please sign in to comment.