Skip to content

Commit

Permalink
Merge branch 'main' into 82-Java
Browse files Browse the repository at this point in the history
  • Loading branch information
jpreisner authored May 30, 2024
2 parents 2c75496 + 1cb9478 commit 842b6da
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ 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

### Deleted
Expand Down
10 changes: 1 addition & 9 deletions ecocode-rules-specifications/src/main/rules/EC522/EC522.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
"func": "Constant\/Issue",
"constantCost": "20min"
},
"tags": [
"sobriety",
"environment",
"ecocode",
"android",
"ios",
"eco-design"
],
"ecoScore": "0.4",
"defaultSeverity": "Minor"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tags": [
"sobriety",
"environment",
"ecocode",
"android",
"eco-design"
]
}
Original file line number Diff line number Diff line change
@@ -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 (
<View>
<Text>Brightness Module Example</Text>
</View>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"tags": [
"sobriety",
"environment",
"ecocode",
"react-native",
"eco-design"
],
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tags": [
"sobriety",
"environment",
"ecocode",
"ios",
"eco-design"
]
}
8 changes: 0 additions & 8 deletions ecocode-rules-specifications/src/main/rules/EC530/EC530.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"sobriety",
"environment",
"ecocode",
"android",
"ios",
"eco-design"
],
"ecoScore": "0.4",
"defaultSeverity": "Major"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tags": [
"sobriety",
"environment",
"ecocode",
"android",
"eco-design"
]
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"tags": [
"sobriety",
"environment",
"ecocode",
"react-native",
"eco-design"
],
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tags": [
"sobriety",
"environment",
"ecocode",
"ios",
"eco-design"
]
}

0 comments on commit 842b6da

Please sign in to comment.