Skip to content

Commit c0f117a

Browse files
authored
Porting GCI36 rule to JavaScript (#370)
1 parent 3aee1c0 commit c0f117a

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- GCI90 C#: Use `Cast` instead of `Select` to cast.
13+
- [#370](https://github.com/green-code-initiative/creedengo-rules-specifications/pull/370) Add new JS rule GCI36 - Avoid autoplay for videos and audio content
1314

1415
### Changed
1516

@@ -310,7 +311,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
310311

311312
### Changed
312313

313-
- [#40](https://github.com/green-code-initiative/creedengo-rules-specifications/issues/40) Refactoring of package names (`cnumr` to `greencodeinitiative`)
314+
- [#40](https://github.com/green-code-initiative/creedengo-rules-specifications/issues/40) Refactoring of package names (`cnumr` to `greencodeinitiative`)
314315
- [#55](https://github.com/green-code-initiative/creedengo-rules-specifications/issues/55) rename `eco-conception` tag of rules to `eco-design`
315316
- [#58](https://github.com/green-code-initiative/creedengo-rules-specifications/issues/58) check and upgrade compatibility to SonarQube 9.9
316317
- move common init scripts to `ecoCode-common` repository
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
:!sectids:
2+
3+
== Why is this an issue?
4+
5+
Autoplaying media consumes unnecessary energy, especially when users might not be actively engaging with the content.
6+
This can drain battery life on devices, particularly on mobile devices, leading to increased energy consumption and potentially contributing to environmental impact.
7+
It can also consume data, particularly for users on limited data plans or in areas with poor internet connectivity.
8+
This can lead to unnecessary data usage and potentially increased costs for users.
9+
10+
However, even without autoplay, segments of video or audio files might still download.
11+
This leads to unnecessary data usage, especially if users don't commence playback.
12+
To mitigate this, it's crucial to prevent browsers from preloading any content by configuring the appropriate settings.
13+
14+
Video:
15+
16+
[source,typescriptjsx,data-diff-id="3",data-diff-type="noncompliant"]
17+
----
18+
return (
19+
<>
20+
<video src="video.mp4" autoplay/> // Non-compliant
21+
<video src="video.mp4" preload="auto"/> // Non-compliant
22+
<video src="video.mp4" autoplay preload="auto"/> // Non-compliant
23+
</>
24+
)
25+
----
26+
27+
[source,typescriptjsx,data-diff-id="2",data-diff-type="compliant"]
28+
----
29+
return (
30+
<video src="video.mp4" preload="none"/> // Compliant
31+
)
32+
----
33+
34+
Audio:
35+
36+
[source,typescriptjsx,data-diff-id="2",data-diff-type="noncompliant"]
37+
----
38+
return (
39+
<audio controls src="audiofile.mp3" autoplay></audio> // Non-compliant
40+
)
41+
----
42+
43+
[source,typescriptjsx,data-diff-id="2",data-diff-type="compliant"]
44+
----
45+
return (
46+
<audio controls src="audiofile.mp3" preload="none"></audio> // Compliant
47+
)
48+
----
49+
50+
== Resources
51+
52+
=== Documentation
53+
54+
- https://github.com/cnumr/best-practices/blob/main/chapters/BP_4003_en.md[CNUMR best practices] - Avoid autoplay for videos and audio content
55+
56+
=== Articles & blog posts
57+
58+
- https://eco-conception.designersethiques.org/guide/en/content/5-2-video.html[eco-conception.designersethiques.org - 5.2. Video and sound]
59+
- https://www.ecoindex.fr/en/ecodesign/[www.ecoindex.fr - Some good practices]

src/main/rules/GCI36/js/GCI36.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"tags": ["creedengo", "eco-design", "react-native", "video", "audio"],
3+
"compatibleLanguages": ["JAVASCRIPT", "TYPESCRIPT"]
4+
}

0 commit comments

Comments
 (0)