Skip to content

Commit

Permalink
Create rule S5264 (#3889)
Browse files Browse the repository at this point in the history
* Add javascript to rule S5264

* Add rule S5264 to JS

---------

Co-authored-by: vdiez <vdiez@users.noreply.github.com>
Co-authored-by: Victor <victor.diez@sonarsource.com>
  • Loading branch information
3 people authored Apr 17, 2024
1 parent 491634b commit 2e71406
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 96 deletions.
5 changes: 2 additions & 3 deletions rules/S5260/html/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ This rule raises an issue when the ``++headers++`` attribute of a ``++<td>++`` c
<th id="paris" class="span" colspan="3" scope="colgroup">
Paris
</th>
</tr>
<tr>
</tr>
<tr>
<th headers="paris" id="day1">
1 day
</th>
Expand All @@ -47,7 +47,6 @@ This rule raises an issue when the ``++headers++`` attribute of a ``++<td>++`` c
<td headers="berlin day1 big"> <!-- Noncompliant, there is no header with id "berlin" -->
50 euros
</td>
</tr>
</tr>
</tbody>
</table>
Expand Down
16 changes: 16 additions & 0 deletions rules/S5264/fix.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Provide alternative content to ``++<object>++`` elements.

[source,html,diff-id=1,diff-type=compliant]
----
<object>This application shows the simulation of two particles colliding</object>
<object>
<img src="flower.png" alt="Flower growing in a pot" />
</object>
<object>
<object>
This application shows the simulation of two particles colliding
</object>
</object>
----
33 changes: 0 additions & 33 deletions rules/S5264/html/metadata.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,2 @@
{
"title": "\"<object>\" tags should provide an alternative content",
"type": "CODE_SMELL",
"code": {
"impacts": {
"MAINTAINABILITY": "LOW"
},
"attribute": "COMPLETE"
},
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "2min"
},
"tags": [
"accessibility",
"wcag2-a"
],
"extra": {
"replacementRules": [

],
"legacyKeys": [

]
},
"defaultSeverity": "Minor",
"ruleSpecification": "RSPEC-5264",
"sqKey": "S5264",
"scope": "All",
"defaultQualityProfiles": [
"Sonar way"
],
"quickfix": "unknown"
}
63 changes: 3 additions & 60 deletions rules/S5264/html/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,62 +1,5 @@
== Why is this an issue?
include::../why.adoc[]

Assistive technologies, such as screen readers, will not be able to render ``++<object>++`` elements, in such cases it is the content of the ``++<object>++`` which is provided to the user. This alternative content needs to be accessible or the screen readers won't be able to use it. For example, if an ``++<img>++`` is used it must contain an ``++alt++`` attribute (see corresponding rule Web:ImgWithoutAltCheck).
include::../fix.adoc[]


This rule raises an issue when an ``++<object>++`` tag does not have any alternative content.


=== Noncompliant code example

[source,html]
----
<object></object> <!-- Noncompliant -->
<object>
<object></object> <!-- Noncompliant -->
</object>
----


=== Compliant solution

[source,html]
----
<object>This application shows the simulation of two particles colliding</object>
<object>
<img src="flower.png" alt="Flower growing in a pot" />
</object>
<object>
<object>
This application shows the simulation of two particles colliding
</object>
</object>
----


== Resources

* https://www.w3.org/TR/WCAG20-TECHS/H53.html[WCAG2, H53] - Using the body of the object element
* https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-text-equiv-all[WCAG2, 1.1.1] - Non-text Content
* https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-media-equiv-audio-desc[WCAG2, 1.2.3] - Audio Description or Media Alternative (Prerecorded)
* https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-media-equiv-text-doc[WCAG2, 1.2.8] - Media Alternative (Prerecorded)

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Add an accessible content to this "<object>" tag.


=== Highlighting

The opening <object> tag without its content


endif::env-github,rspecator-view[]
include::../resources.adoc[]
7 changes: 7 additions & 0 deletions rules/S5264/javascript/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tags": [
"accessibility",
"wcag2-a",
"react"
]
}
5 changes: 5 additions & 0 deletions rules/S5264/javascript/rule.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include::../why.adoc[]

include::../fix.adoc[]

include::../resources.adoc[]
33 changes: 33 additions & 0 deletions rules/S5264/metadata.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
{
"title": "\"<object>\" tags should provide an alternative content",
"type": "CODE_SMELL",
"code": {
"impacts": {
"MAINTAINABILITY": "LOW"
},
"attribute": "COMPLETE"
},
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "2min"
},
"tags": [
"accessibility",
"wcag2-a"
],
"extra": {
"replacementRules": [

],
"legacyKeys": [

]
},
"defaultSeverity": "Minor",
"ruleSpecification": "RSPEC-5264",
"sqKey": "S5264",
"scope": "All",
"defaultQualityProfiles": [
"Sonar way"
],
"quickfix": "unknown"
}
10 changes: 10 additions & 0 deletions rules/S5264/resources.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
== Resources

* https://www.w3.org/TR/WCAG20-TECHS/H53.html[WCAG2, H53] - Using the body of the object element
* https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-text-equiv-all[WCAG2, 1.1.1] - Non-text Content
* https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-media-equiv-audio-desc[WCAG2, 1.2.3] - Audio Description or Media Alternative (Prerecorded)
* https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-media-equiv-text-doc[WCAG2, 1.2.8] - Media Alternative (Prerecorded)
=== Related rules

* Web:ImgWithoutAltCheck
16 changes: 16 additions & 0 deletions rules/S5264/why.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
== Why is this an issue?

The ``++<object>++`` HTML element represents an external resource, which can be treated as an image, a nested browsing context, or a resource to be handled by a plugin. The element's children are the fallback content. This allows multiple object elements to be nested inside each other, targeting multiple user agents with different capabilities, with the user agent picking the first one it supports.

Assistive technologies, such as screen readers, will not be able to render ``++<object>++`` elements, in such cases it is the content of the ``++<object>++`` which is provided to the user. This alternative content needs to be accessible or the screen readers won't be able to use it. For example, if an ``++<img>++`` is used it must contain an ``++alt++`` attribute.

This rule raises an issue when an ``++<object>++`` tag does not have any alternative content.

[source,html,diff-id=1,diff-type=noncompliant]
----
<object></object> <!-- Noncompliant -->
<object>
<object></object> <!-- Noncompliant -->
</object>
----

0 comments on commit 2e71406

Please sign in to comment.