Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
f14fbee
Added Swift port for rule EC513
Apr 30, 2024
dd0b06f
Merge branch 'main' into rule/EC513-swift
dedece35 May 13, 2024
25331a7
merged main
May 17, 2024
6ee6a59
Merge branch 'main' into rule/EC513-swift
dedece35 May 20, 2024
344db23
Added EC514 for Swift
May 29, 2024
b93f399
Corrected EC514 content
May 29, 2024
4cfe351
Updated CHANGELOG
May 29, 2024
fd9d6f4
Changelog update
May 30, 2024
94933bc
Corrected EC515 content
May 30, 2024
1fc0f7b
EC515 Swift update
May 30, 2024
d0b2e8c
add rule EC1369
May 30, 2024
e27bea4
[Python #26][EC1337] Avoid unlimited cache
B3ND3L May 30, 2024
1cb9478
Add EC522 to javascript (#321)
JuBaas May 30, 2024
264b458
Merge branch 'main' into rule/EC515-swift
May 30, 2024
3fad451
Merge branch 'main' into rule/EC515-swift
zippy1978 May 30, 2024
4397527
Merge branch 'main' into rule/EC514-swift
zippy1978 May 30, 2024
01f2a1a
Merge branch 'main' into rule/EC513-swift
zippy1978 May 30, 2024
3b57ae5
Update CHANGELOG.md
zippy1978 May 30, 2024
07ebadb
Update EC514.asciidoc
zippy1978 May 30, 2024
f20825c
Update EC515.asciidoc
zippy1978 May 30, 2024
4066e21
Add EC523 to javascript (#319)
poulainpi May 30, 2024
68a0e61
[Python #26][EC1337] Avoid unlimited cache
B3ND3L May 30, 2024
032f4d6
update RULES.md
May 30, 2024
9e5bb51
Merge branch 'main' into rule/EC515-swift
dedece35 May 30, 2024
5b18cf5
Merge pull request #312 from green-code-initiative/rule/EC515-swift
dedece35 May 30, 2024
4b80d4c
Merge branch 'main' into rule/EC514-swift
dedece35 May 30, 2024
1077684
Merge pull request #307 from green-code-initiative/rule/EC514-swift
dedece35 May 30, 2024
c0b53d6
Merge branch 'main' into rule/EC513-swift
dedece35 May 30, 2024
03b6151
Merge pull request #294 from green-code-initiative/rule/EC513-swift
dedece35 May 30, 2024
8f03608
changelog updates
dedece35 May 30, 2024
6daf909
[ISSUE 26][PYTHON] update RULES.md : Avoid using function cache witho…
dedece35 Jun 2, 2024
b917c97
[Python #26][EC89] Change EC1337 to EC89
B3ND3L Jun 3, 2024
5a411cf
Merge remote-tracking branch 'refs/remotes/upstream/main'
B3ND3L Jun 3, 2024
556b8cd
Merge pull request #327 from B3ND3L/main
dedece35 Jun 3, 2024
37ccff7
typo on CHANGELOG.md
dedece35 Jun 3, 2024
4cb5f5f
Merge branch 'main' into main
dedece35 Jun 3, 2024
4073394
prepare 1.6.0 : update CHANGELOG
dedece35 Jun 3, 2024
a903a5c
prepare 1.6.0 : update pom.xml
dedece35 Jun 3, 2024
6da471b
[maven-release-plugin] prepare release 1.6.0
dedece35 Jun 3, 2024
97ff3d7
[maven-release-plugin] prepare for next development iteration
dedece35 Jun 3, 2024
1282a71
Merge pull request #338 from green-code-initiative/release_1.6.0
dedece35 Jun 3, 2024
72e4e34
type in CHANGELOG.md
dedece35 Jun 3, 2024
d20071d
[ISSUE 26][PYTHON] update RULES.md : EC89 added for Python
dedece35 Jun 5, 2024
6153f82
Move OBS naming to Orange Business (#340)
glalloue Jun 7, 2024
98aac72
[EC93] [C#] Return Task directly (#339)
Jun 8, 2024
e734aab
Add avoid-keep-awake asciidoc and json
May 30, 2024
f71d21a
Merge branch 'main' into main
dedece35 Jun 13, 2024
b6c2ea9
Merge pull request #323 from Samdespion/main
dedece35 Jun 13, 2024
4d28f85
array format correction of RULES.md
dedece35 Jun 13, 2024
93f94a7
[EC94] update rule referentiel with real rule ID + CHANGELOG.md + RUL…
dedece35 Jun 13, 2024
097ec9f
Merge branch 'main' into avoid-keep-awake
dedece35 Jun 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [C# #66](https://github.com/green-code-initiative/ecoCode-csharp/pull/66) [EC93] [C#] Return Task directly
- [JAVA #323](https://github.com/green-code-initiative/ecoCode/pull/323) [EC94] [Java] Use orElseGet instead of orElse

### Changed

### Deleted

## [1.6.0] - 2024-06-03

### Added

- [#293](https://github.com/green-code-initiative/ecoCode/issues/293) [EC513] Swift port
- [#310](https://github.com/green-code-initiative/ecoCode/issues/310) EC515 Swift port
- [#306](https://github.com/green-code-initiative/ecoCode/issues/306) Swift port of rule EC514
- [#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)
- [Python #26](https://github.com/green-code-initiative/ecoCode-python/issues/26) [EC89] [Python] Avoid unlimited cache

### Changed

- [#318](https://github.com/green-code-initiative/ecoCode/issues/318) Implement the rule EC523 for React Native

### Deleted

- [#318](https://github.com/green-code-initiative/ecoCode/issues/318) Merge the rule EC8 with EC523

## [1.5.4] - 2024-05-24

### Added
Expand Down Expand Up @@ -301,7 +321,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Comparison List

[unreleased](https://github.com/green-code-initiative/ecoCode/compare/1.5.4...HEAD)
[unreleased](https://github.com/green-code-initiative/ecoCode/compare/1.6.0...HEAD)
[1.6.0](https://github.com/green-code-initiative/ecoCode/compare/1.5.4...1.6.0)
[1.5.4](https://github.com/green-code-initiative/ecoCode/compare/1.5.3...1.5.4)
[1.5.3](https://github.com/green-code-initiative/ecoCode/compare/1.5.2...1.5.3)
[1.5.2](https://github.com/green-code-initiative/ecoCode/compare/1.5.1...1.5.2)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Here we honor some no-longer-active core team members who have made valuable con
They have contributed to the success of ecoCode :

- [Davidson Consulting](https://www.davidson.fr/)
- [Orange Business Services](https://www.orange-business.com/)
- [Orange Business](https://www.orange-business.com/)
- [Snapp'](https://www.snapp.fr/)
- [Université de Pau et des Pays de l'Adour (UPPA)](https://www.univ-pau.fr/)
- [Solocal](https://www.solocal.com/) / [PagesJaunes.fr](https://www.pagesjaunes.fr/)
Expand Down
33 changes: 19 additions & 14 deletions RULES.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ecocode-rules-specifications/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.ecocode</groupId>
<artifactId>ecocode-parent</artifactId>
<version>1.5.5-SNAPSHOT</version>
<version>1.6.1-SNAPSHOT</version>
</parent>

<artifactId>ecocode-rules-specifications</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
:!sectids:

== Why is this an issue?

To avoid draining the battery, an Android device that is left idle quickly falls asleep.
Hence, keeping the screen on should be avoided, unless it is absolutely necessary.

== Example of non compliant code

```js
export default function KeepAwakeExample() {
useKeepAwake(); // Non compliant
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>This screen will never sleep!</Text>
</View>
);
}
```

```js
_activate = () => {
activateKeepAwake(); // Non-compliant
alert('Activated!');
};
```
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,57 @@
Most iOS devices come equipped with a variety of sensors that measure motion, orientation, and various environmental conditions.
In addition to these, the devices include advanced sensors such as the image sensor (commonly referred to as the Camera) and the geo-positioning sensor (commonly referred to as GPS).

The common point of all these sensors is that they are power-intensive while in use. A typical issue arises when these sensors continue to process data unnecessarily after the application enters an idle state, typically when paused or when the user stops interacting with it.

Consequently, calls must be carefully paired: `CLLocationManager.startUpdatingLocation()` and `CLLocationManager.stopUpdatingLocation()`.
Failing to do so can drain the battery in just a few hours.

== Noncompliant Code Example

[source,swift]
----
import CoreLocation

class LocationTracker: NSObject, CLLocationManagerDelegate {
var locationManager: CLLocationManager?

override init() {
super.init()
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.requestAlwaysAuthorization() // Request appropriate authorization
locationManager?.startUpdatingLocation() // Start location updates
}

// LocationManager Delegate Methods
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
// Process new locations
}
}
----

== Compliant Code Example

[source,swift]
----
import CoreLocation

class LocationTracker: NSObject, CLLocationManagerDelegate {
var locationManager: CLLocationManager?

override init() {
super.init()
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.requestAlwaysAuthorization() // Request appropriate authorization
locationManager?.startUpdatingLocation() // Start location updates only when needed
}

// LocationManager Delegate Methods
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
// Process new locations
// Possibly stop updates if they are no longer needed
locationManager?.stopUpdatingLocation()
}
}
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Most iOS devices have built-in sensors that measure motion, orientation, and various environmental conditions. Additionally, they have image sensors (a.k.a. Camera) and geo-positioning sensors (a.k.a. GPS).

The common point of all these sensors is that they consume significant power while in use. Their common issue is processing data unnecessarily when the app is in an idle state, typically when it enters the background or becomes inactive.

Consequently, calls to start and stop sensor updates must be carefully managed for motion sensor: CMMotionManager#startAccelerometerUpdates()/CMMotionManager#stopAccelerometerUpdates().
Failing to do so can drain the battery quickly.

== Noncompliant Code Example

[source,swift]
----
import CoreMotion

let motionManager = CMMotionManager()

func startMotionUpdates() {
if motionManager.isAccelerometerAvailable {
motionManager.startAccelerometerUpdates(to: .main) { data, error in
// Handle accelerometer updates
}
}
}
----

== Compliant Code Example

[source,swift]
----
import CoreMotion

let motionManager = CMMotionManager()

func startMotionUpdates() {
if motionManager.isAccelerometerAvailable {
motionManager.startAccelerometerUpdates(to: .main) { data, error in
// Handle accelerometer updates
}
}
}

func stopMotionUpdates() {
if motionManager.isAccelerometerActive {
motionManager.stopAccelerometerUpdates()
}
}
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Creation of an `AVAudioRecorder` object is used to record audio. These class has a method to stop recording and release resources.

In addition to unnecessary resources (such as memory and instances of codecs) being held, failure to properly stop and release these object if it is no longer needed may also lead to continuous battery consumption for mobile devices.


== Noncompliant Code Example

[source,swift]
----
import AVFoundation

var audioRecorder: AVAudioRecorder?

func startRecording() {
let settings = [
AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
AVSampleRateKey: 12000,
AVNumberOfChannelsKey: 1,
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
]

do {
audioRecorder = try AVAudioRecorder(url: getDocumentsDirectory().appendingPathComponent("recording.m4a"), settings: settings)
audioRecorder?.record()
} catch {
// Handle error
}
}
----

== Compliant Solution

[source,swift]
----
import AVFoundation

var audioRecorder: AVAudioRecorder?

func startRecording() {
let settings = [
AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
AVSampleRateKey: 12000,
AVNumberOfChannelsKey: 1,
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
]

do {
audioRecorder = try AVAudioRecorder(url: getDocumentsDirectory().appendingPathComponent("recording.m4a"), settings: settings)
audioRecorder?.record()
} catch {
// Handle error
}
}

func stopRecording() {
if let recorder = audioRecorder, recorder.isRecording {
recorder.stop()
audioRecorder = nil
}
}
----
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"
]
}
10 changes: 1 addition & 9 deletions ecocode-rules-specifications/src/main/rules/EC523/EC523.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
"func": "Constant\/Issue",
"constantCost": "10min"
},
"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"
]
}
Loading