From 370ffc16a039640e094aeede87cf17abaaf665eb Mon Sep 17 00:00:00 2001 From: Dirgon <45286358+Dirgon@users.noreply.github.com> Date: Thu, 30 May 2024 11:36:13 +0200 Subject: [PATCH 1/2] Add EC530 to javascript (#315) --- CHANGELOG.md | 2 ++ .../src/main/rules/EC530/EC530.json | 8 ------- .../src/main/rules/EC530/java/EC530.json | 9 ++++++++ .../rules/EC530/javascript/EC530.asciidoc | 21 +++++++++++++++++++ .../main/rules/EC530/javascript/EC530.json | 13 ++++++++++++ .../src/main/rules/EC530/swift/EC530.json | 9 ++++++++ 6 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 ecocode-rules-specifications/src/main/rules/EC530/java/EC530.json create mode 100644 ecocode-rules-specifications/src/main/rules/EC530/javascript/EC530.asciidoc create mode 100644 ecocode-rules-specifications/src/main/rules/EC530/javascript/EC530.json create mode 100644 ecocode-rules-specifications/src/main/rules/EC530/swift/EC530.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 21a7ee4bb..73939e07a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- [#315](https://github.com/green-code-initiative/ecoCode/pull/315) Add rule EC530 for javascript + ### Changed ### Deleted diff --git a/ecocode-rules-specifications/src/main/rules/EC530/EC530.json b/ecocode-rules-specifications/src/main/rules/EC530/EC530.json index b834ab295..2bca358ec 100644 --- a/ecocode-rules-specifications/src/main/rules/EC530/EC530.json +++ b/ecocode-rules-specifications/src/main/rules/EC530/EC530.json @@ -6,14 +6,6 @@ "func": "Constant\/Issue", "constantCost": "5min" }, - "tags": [ - "sobriety", - "environment", - "ecocode", - "android", - "ios", - "eco-design" - ], "ecoScore": "0.4", "defaultSeverity": "Major" } diff --git a/ecocode-rules-specifications/src/main/rules/EC530/java/EC530.json b/ecocode-rules-specifications/src/main/rules/EC530/java/EC530.json new file mode 100644 index 000000000..639ebdd0d --- /dev/null +++ b/ecocode-rules-specifications/src/main/rules/EC530/java/EC530.json @@ -0,0 +1,9 @@ +{ + "tags": [ + "sobriety", + "environment", + "ecocode", + "android", + "eco-design" + ] +} diff --git a/ecocode-rules-specifications/src/main/rules/EC530/javascript/EC530.asciidoc b/ecocode-rules-specifications/src/main/rules/EC530/javascript/EC530.asciidoc new file mode 100644 index 000000000..830784d73 --- /dev/null +++ b/ecocode-rules-specifications/src/main/rules/EC530/javascript/EC530.asciidoc @@ -0,0 +1,21 @@ +== Why is this an issue? + +Turning on the torch mode programmatically with `react-native-torch` must absolutely be avoided because the flashlight is one of the most energy-intensive component. + +## Non compliant Code Example + +[source,js,data-diff-id="2",data-diff-type="noncompliant"] +---- +import Torch from 'react-native-torch'; // Non-compliant +---- + +[source,js,data-diff-id="2",data-diff-type="compliant"] +---- +import axios from 'axios'; // Compliant +---- + +== Resources + +=== Documentation + +- [CNUMR best practices mobile](https://github.com/cnumr/best-practices-mobile) - Torch free \ No newline at end of file diff --git a/ecocode-rules-specifications/src/main/rules/EC530/javascript/EC530.json b/ecocode-rules-specifications/src/main/rules/EC530/javascript/EC530.json new file mode 100644 index 000000000..e32eae117 --- /dev/null +++ b/ecocode-rules-specifications/src/main/rules/EC530/javascript/EC530.json @@ -0,0 +1,13 @@ +{ + "tags": [ + "sobriety", + "environment", + "ecocode", + "react-native", + "eco-design" + ], + "compatibleLanguages": [ + "JAVASCRIPT", + "TYPESCRIPT" + ] +} diff --git a/ecocode-rules-specifications/src/main/rules/EC530/swift/EC530.json b/ecocode-rules-specifications/src/main/rules/EC530/swift/EC530.json new file mode 100644 index 000000000..bfcb65813 --- /dev/null +++ b/ecocode-rules-specifications/src/main/rules/EC530/swift/EC530.json @@ -0,0 +1,9 @@ +{ + "tags": [ + "sobriety", + "environment", + "ecocode", + "ios", + "eco-design" + ] +} From 1cb9478c5f8409b09fdd3bce3cb3c376757d9d3b Mon Sep 17 00:00:00 2001 From: JuBaas Date: Thu, 30 May 2024 13:30:05 +0200 Subject: [PATCH 2/2] Add EC522 to javascript (#321) --- CHANGELOG.md | 1 + .../src/main/rules/EC522/EC522.json | 10 +------ .../src/main/rules/EC522/java/EC522.json | 9 ++++++ .../rules/EC522/javascript/EC522.asciidoc | 30 +++++++++++++++++++ .../main/rules/EC522/javascript/EC522.json | 13 ++++++++ .../src/main/rules/EC522/swift/EC522.json | 9 ++++++ 6 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 ecocode-rules-specifications/src/main/rules/EC522/java/EC522.json create mode 100644 ecocode-rules-specifications/src/main/rules/EC522/javascript/EC522.asciidoc create mode 100644 ecocode-rules-specifications/src/main/rules/EC522/javascript/EC522.json create mode 100644 ecocode-rules-specifications/src/main/rules/EC522/swift/EC522.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 73939e07a..13ef138e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - [#315](https://github.com/green-code-initiative/ecoCode/pull/315) Add rule EC530 for javascript +- [#321](https://github.com/green-code-initiative/ecoCode/pull/321) Add rule EC522 for javascript (avoid brightness override) ### Changed diff --git a/ecocode-rules-specifications/src/main/rules/EC522/EC522.json b/ecocode-rules-specifications/src/main/rules/EC522/EC522.json index c333af544..7835b7a63 100644 --- a/ecocode-rules-specifications/src/main/rules/EC522/EC522.json +++ b/ecocode-rules-specifications/src/main/rules/EC522/EC522.json @@ -6,14 +6,6 @@ "func": "Constant\/Issue", "constantCost": "20min" }, - "tags": [ - "sobriety", - "environment", - "ecocode", - "android", - "ios", - "eco-design" - ], "ecoScore": "0.4", "defaultSeverity": "Minor" -} \ No newline at end of file +} diff --git a/ecocode-rules-specifications/src/main/rules/EC522/java/EC522.json b/ecocode-rules-specifications/src/main/rules/EC522/java/EC522.json new file mode 100644 index 000000000..639ebdd0d --- /dev/null +++ b/ecocode-rules-specifications/src/main/rules/EC522/java/EC522.json @@ -0,0 +1,9 @@ +{ + "tags": [ + "sobriety", + "environment", + "ecocode", + "android", + "eco-design" + ] +} diff --git a/ecocode-rules-specifications/src/main/rules/EC522/javascript/EC522.asciidoc b/ecocode-rules-specifications/src/main/rules/EC522/javascript/EC522.asciidoc new file mode 100644 index 000000000..94e8c6f5e --- /dev/null +++ b/ecocode-rules-specifications/src/main/rules/EC522/javascript/EC522.asciidoc @@ -0,0 +1,30 @@ +:!sectids: + +== Why is this an issue? + +To avoid draining the battery, iOS and Android devices adapt the brightness of the screen depending on the environment light. + +For some reasons, developers may disable this feature programmatically. + +This feature was introduced to improve battery life, be careful when deactivating it. + +Hence, keeping forcing the screen brightness on should be avoided, unless it is absolutely necessary. + +== Example of non compliant code + +```js +// Example with expo-brightness (Expo framework library) +import React, { useEffect } from 'react'; +import { View, Text } from 'react-native'; +import * as Brightness from 'expo-brightness'; + +export default function App() { + useEffect(() => { + (async () => { Brightness.setSystemBrightnessAsyn(1); })(); // Brightness is forced here + }, []); + return ( + + Brightness Module Example + + ); +} diff --git a/ecocode-rules-specifications/src/main/rules/EC522/javascript/EC522.json b/ecocode-rules-specifications/src/main/rules/EC522/javascript/EC522.json new file mode 100644 index 000000000..e32eae117 --- /dev/null +++ b/ecocode-rules-specifications/src/main/rules/EC522/javascript/EC522.json @@ -0,0 +1,13 @@ +{ + "tags": [ + "sobriety", + "environment", + "ecocode", + "react-native", + "eco-design" + ], + "compatibleLanguages": [ + "JAVASCRIPT", + "TYPESCRIPT" + ] +} diff --git a/ecocode-rules-specifications/src/main/rules/EC522/swift/EC522.json b/ecocode-rules-specifications/src/main/rules/EC522/swift/EC522.json new file mode 100644 index 000000000..bfcb65813 --- /dev/null +++ b/ecocode-rules-specifications/src/main/rules/EC522/swift/EC522.json @@ -0,0 +1,9 @@ +{ + "tags": [ + "sobriety", + "environment", + "ecocode", + "ios", + "eco-design" + ] +}