diff --git a/CHANGELOG.md b/CHANGELOG.md
index 73939e07..1198bd0c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
@@ -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)
diff --git a/README.md b/README.md
index fae772b8..8ef25a0c 100644
--- a/README.md
+++ b/README.md
@@ -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/)
diff --git a/RULES.md b/RULES.md
index 05310c4b..65a8ebc1 100644
--- a/RULES.md
+++ b/RULES.md
@@ -1,10 +1,10 @@
# Rules
- [Rules](#rules)
- - [Rules support matrix by techno](#rules-support-matrix-by-techno)
- - [Rules to be reworked / measured / clarified](#rules-to-be-reworked--measured--clarified)
- - [Deprecated rules](#deprecated-rules)
- - [Refused / Deleted rules](#refused--deleted-rules)
+ - [Rules support matrix by techno](#rules-support-matrix-by-techno)
+ - [Rules to be reworked / measured / clarified](#rules-to-be-reworked--measured--clarified)
+ - [Deprecated rules](#deprecated-rules)
+ - [Refused / Deleted rules](#refused--deleted-rules)
## Rules support matrix by techno
@@ -30,7 +30,6 @@ Some are applicable for different technologies.
| EC4 | Use global variables | When using a global variable, the interpretation engine must check: 1) that it exists in the current scope, in the one above, etc. ; 2) the variable has a value; 3) ... To avoid all these checks, it is often possible to pass the useful variables as arguments of routines, making them local. This process saves computational time (CPU cycles). | [cnumr best practices (3rd edition) BP_050 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | π« | β
| π | β
| π | π« | π« |
| EC5 | Usage of preparedStatement instead of Statement | SQL will only commit the query once, whereas if you used only one statement, it would commit the query every time and thus induce unnecessary calculations by the CPU and therefore superfluous energy consumption. | | β
| π« | π« | π« | π« | π« | π« |
| EC7 | Rewrite native getter/setters | Overloading them lengthens the compilation and execution times of these methods, which are usually much better optimized by the language than by the developer. | [cnumr best practices (3rd edition) BP_062 (no longer exists in edition 4)](https://www.greenit.fr/2019/05/07/ecoconception-web-les-115-bonnes-pratiques-3eme-edition/) | π« | π« | π | β
| π | π« | π« |
-| EC8 | Avoid using high accuracy geolocation | ESLint key : @ecocode/avoid-high-accuracy-geolocation /// type : Front-end | | β | β | β
| β | β | β | π« |
| EC9 | No import all from library | ESLint key : @ecocode/no-import-all-from-library /// type : Common | | β | β | β
| β | β | β | π« |
| EC10 | Use unoptimized vector images | Less heavy SVG images using less bandwidth | [cnumr best practices (3rd edition) BP_036](https://github.com/cnumr/best-practices/blob/main/chapters/BP_036_fr.md) | π§ | π | π | β
| π | π« | β |
| EC11 | Call a DOM element multiple times without caching | ESLint key : @ecocode/no-multiple-access-dom-element /// type : Front-end | | π« | β | β
| π« | π« | β | π« |
@@ -66,6 +65,9 @@ Some are applicable for different technologies.
| EC86 | GC.Collect should not be called | In most cases, the cost of calling GC.Collect far outweighs the benefits | | π« | π« | π« | π« | π« | β
| π« |
| EC87 | Use collection indexer | Collection indexers should be used instead of Linq, when available | | π« | π« | π« | π« | π« | β
| π« |
| EC88 | Dispose resource asynchronously | Resources that implement `IAsyncDisposable` should be disposed asynchronously | | π« | π« | π« | π« | π« | β
| π« |
+| EC89 | Avoid using function cache without limit | If a function has decorators without max size cache, the program will store unlimited datas | | β | β | β | β
| β | β | β |
+| EC93 | Return `Task` directly | Consider returning a `Task` directly instead of a single `await` | | β | β | β | β | β | β
| β |
+| EC94 | Use orElseGet instead of orElse | Parameter of orElse() is evaluated, even when having a non-empty Optional. Supplier method of orElseGet passed as an argument is only executed when an Optional value isnβt present. Therefore, using orElseGet() will save computing time. | [cnumr best practices (3rd edition) BP_042](https://github.com/cnumr/best-practices/blob/main/chapters/BP_042_fr.md) | π§ | β | β | β | β | β | β |
| EC203 | Detect unoptimized file formats | When it is possible, to use svg format image over other image format | | π | π | π | β
| π | π | π« |
| EC404 | Avoid list comprehension in iterations | Use generator comprehension instead of list comprehension in for loop declaration | | π« | π« | π« | β
| π« | π« | π« |
| | Use official social media sharing buttons | These JavaScript plugins are very resource-intensive: to work, they require a large number of requests and download heavy files. It is better to prefer direct links. | [cnumr best practices (3rd edition) BP_019](https://github.com/cnumr/best-practices/blob/main/chapters/BP_019_fr.md) | π« | π« | π | π« | π« | π« | π |
@@ -78,7 +80,8 @@ Some are applicable for different technologies.
## Rules to be reworked / measured / clarified
-This table lists rules proposed by the community but they have to be reworked / measured / clarified before being implemented in ecoCode plugins.
+This table lists rules proposed by the community but they have to be reworked / measured / clarified before being
+implemented in ecoCode plugins.
(Issues and PR are closed, but they can be reopen once rework launched)
| Rule key | Language | Name | Description | Invalidation |
@@ -93,7 +96,8 @@ This table lists rules proposed by the community but they have to be reworked /
## Deprecated rules
-This table lists rules proposed by the community but deprecated in ecoCode plugins with the justification. These rules will be completely deleted in next releases and moved to bottom deleted rules array.
+This table lists rules proposed by the community but deprecated in ecoCode plugins with the justification. These rules
+will be completely deleted in next releases and moved to bottom deleted rules array.
| Rule key | Language | Name | Description | Invalidation |
|----------|---------------------|----------------------------------------------------|----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -104,10 +108,11 @@ This table lists rules proposed by the community but deprecated in ecoCode plugi
This table lists rules proposed by the community but refused or/and deleted in ecoCode plugins with the justification.
-| Rule key | Language | Name | Description | Invalidation |
-|----------|----------|---------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| CRDOM203 | HTML | HTML page must contain a doctype tag | The difference in performance is negligible, this rule is more related to the user experience. | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/103) |
-| CRPYT | Python | Use numpy array instead of standard list | The use of numpy library to perform array manipulation is more energy efficient than the use of the standard list functions. | [Github discussion with measures](https://github.com/green-code-initiative/ecoCode/issues/132) |
-| EC4 | Java | Avoid using global variables | Global variables do not exist in Java. | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/233) |
-| EC63 | Java | Unnecessarily assigning values to variables | There are already 3 native SonarQube rules for Java. | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/pull/258) |
-| EC75 | Java | Don't concatenate strings in loops | Optimizations on Java concatenation Strings are useless since JDK8 | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/246) |
+| Rule key | Language | Name | Description | Invalidation |
+|----------|------------|---------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
+| CRDOM203 | HTML | HTML page must contain a doctype tag | The difference in performance is negligible, this rule is more related to the user experience. | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/103) |
+| CRPYT | Python | Use numpy array instead of standard list | The use of numpy library to perform array manipulation is more energy efficient than the use of the standard list functions. | [Github discussion with measures](https://github.com/green-code-initiative/ecoCode/issues/132) |
+| EC4 | Java | Avoid using global variables | Global variables do not exist in Java. | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/233) |
+| EC63 | Java | Unnecessarily assigning values to variables | There are already 3 native SonarQube rules for Java. | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/pull/258) |
+| EC75 | Java | Don't concatenate strings in loops | Optimizations on Java concatenation Strings are useless since JDK8 | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/246) |
+| EC8 | JavaScript | Avoid using high accuracy geolocation | The rule has been merged with the rule EC523 | [Github discussion with sources](https://github.com/green-code-initiative/ecoCode/issues/318) |
diff --git a/ecocode-rules-specifications/pom.xml b/ecocode-rules-specifications/pom.xml
index e01aef47..2dd5f680 100644
--- a/ecocode-rules-specifications/pom.xml
+++ b/ecocode-rules-specifications/pom.xml
@@ -5,7 +5,7 @@
io.ecocode
ecocode-parent
- 1.5.5-SNAPSHOT
+ 1.6.1-SNAPSHOT
ecocode-rules-specifications
diff --git a/ecocode-rules-specifications/src/main/rules/EC505/javascript/EC505.asciidoc b/ecocode-rules-specifications/src/main/rules/EC505/javascript/EC505.asciidoc
new file mode 100644
index 00000000..05f67795
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC505/javascript/EC505.asciidoc
@@ -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 (
+
+ This screen will never sleep!
+
+ );
+}
+```
+
+```js
+_activate = () => {
+ activateKeepAwake(); // Non-compliant
+ alert('Activated!');
+ };
+```
\ No newline at end of file
diff --git a/ecocode-rules-specifications/src/main/rules/EC505/javascript/EC505.json b/ecocode-rules-specifications/src/main/rules/EC505/javascript/EC505.json
new file mode 100644
index 00000000..936cf1cc
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC505/javascript/EC505.json
@@ -0,0 +1,13 @@
+{
+ "tags": [
+ "sobriety",
+ "environment",
+ "ecocode",
+ "react-native",
+ "eco-design"
+ ],
+ "compatibleLanguages": [
+ "JAVASCRIPT",
+ "TYPESCRIPT"
+ ]
+ }
\ No newline at end of file
diff --git a/ecocode-rules-specifications/src/main/rules/EC513/swift/EC513.asciidoc b/ecocode-rules-specifications/src/main/rules/EC513/swift/EC513.asciidoc
new file mode 100644
index 00000000..efcb0b78
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC513/swift/EC513.asciidoc
@@ -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()
+ }
+}
+----
diff --git a/ecocode-rules-specifications/src/main/rules/EC514/swift/EC514.asciidoc b/ecocode-rules-specifications/src/main/rules/EC514/swift/EC514.asciidoc
new file mode 100644
index 00000000..37eb6dcb
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC514/swift/EC514.asciidoc
@@ -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()
+ }
+}
+----
diff --git a/ecocode-rules-specifications/src/main/rules/EC515/swift/EC515.asciidoc b/ecocode-rules-specifications/src/main/rules/EC515/swift/EC515.asciidoc
new file mode 100644
index 00000000..3770fded
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC515/swift/EC515.asciidoc
@@ -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
+ }
+}
+----
diff --git a/ecocode-rules-specifications/src/main/rules/EC522/EC522.json b/ecocode-rules-specifications/src/main/rules/EC522/EC522.json
index c333af54..7835b7a6 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 00000000..639ebdd0
--- /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 00000000..94e8c6f5
--- /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 00000000..e32eae11
--- /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 00000000..bfcb6581
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC522/swift/EC522.json
@@ -0,0 +1,9 @@
+{
+ "tags": [
+ "sobriety",
+ "environment",
+ "ecocode",
+ "ios",
+ "eco-design"
+ ]
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC523/EC523.json b/ecocode-rules-specifications/src/main/rules/EC523/EC523.json
index 5ac0edef..3ae99eb6 100644
--- a/ecocode-rules-specifications/src/main/rules/EC523/EC523.json
+++ b/ecocode-rules-specifications/src/main/rules/EC523/EC523.json
@@ -6,14 +6,6 @@
"func": "Constant\/Issue",
"constantCost": "10min"
},
- "tags": [
- "sobriety",
- "environment",
- "ecocode",
- "android",
- "ios",
- "eco-design"
- ],
"ecoScore": "0.4",
"defaultSeverity": "Major"
-}
\ No newline at end of file
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC523/java/EC523.json b/ecocode-rules-specifications/src/main/rules/EC523/java/EC523.json
new file mode 100644
index 00000000..639ebdd0
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC523/java/EC523.json
@@ -0,0 +1,9 @@
+{
+ "tags": [
+ "sobriety",
+ "environment",
+ "ecocode",
+ "android",
+ "eco-design"
+ ]
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC523/javascript/EC523.asciidoc b/ecocode-rules-specifications/src/main/rules/EC523/javascript/EC523.asciidoc
new file mode 100644
index 00000000..a6e81bb7
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC523/javascript/EC523.asciidoc
@@ -0,0 +1,68 @@
+:!sectids:
+
+== Why is this an issue?
+
+High-precision geolocation typically requires more power from the device's GPS hardware.
+By requesting less accurate geolocation, you can reduce the power consumption, leading to extended battery life, which
+is crucial for mobile devices.
+
+Obtaining highly accurate geolocation often involves more complex calculations and processing, which can increase CPU
+usage.
+If the application or service does not critically require pinpoint accuracy, opting for a less accurate geolocation can
+help minimize the strain on the device's CPU.
+
+== Web
+
+[source,js]
+----
+var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }; // Non-compliant
+navigator.geolocation.getCurrentPosition(
+ (pos) => console.log(pos),
+ (err) => console.warn(err),
+ options
+);
+----
+
+In these examples, the enableHighAccuracy option is set to false (the default), indicating that the application prefers
+lower-accuracy geolocation to conserve resources:
+
+[source,js]
+----
+navigator.geolocation.getCurrentPosition((pos) => console.log(pos)); // Compliant by default
+----
+
+[source,js]
+----
+var options = { enableHighAccuracy: false, timeout: 5000, maximumAge: 0 }; // Compliant
+navigator.geolocation.getCurrentPosition(
+ (pos) => console.log(pos),
+ (err) => console.warn(err),
+ options
+);
+----
+
+== React Native
+
+In this example, we ask the user to turn on high accuracy location mode which enables network provider that uses Google Play services to improve location accuracy and location-based services:
+
+[source,js]
+----
+import * as Location from 'expo-location';
+
+Location.enableNetworkProviderAsync(); // Non-compliant
+----
+
+Prefer to ask the user to turn on lower-accuracy geolocation to conserve resources:
+
+[source,js]
+----
+import * as Location from 'expo-location';
+
+Location.requestPermissionsAsync(); // Compliant
+----
+
+== Resources
+
+=== Documentation
+
+- https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition[getCurrentPosition() method] - Mozilla Web Technology for Developers
diff --git a/ecocode-rules-specifications/src/main/rules/EC523/javascript/EC523.json b/ecocode-rules-specifications/src/main/rules/EC523/javascript/EC523.json
new file mode 100644
index 00000000..e32eae11
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC523/javascript/EC523.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/EC8/EC8.json b/ecocode-rules-specifications/src/main/rules/EC8/EC8.json
deleted file mode 100644
index 3d5e7565..00000000
--- a/ecocode-rules-specifications/src/main/rules/EC8/EC8.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "title": "Avoid using high accuracy geolocation in web applications.",
- "type": "CODE_SMELL",
- "code": {
- "impacts": {
- "MAINTAINABILITY": "MEDIUM"
- },
- "attribute": "EFFICIENT"
- },
- "status": "ready",
- "remediation": {
- "func": "Constant\/Issue",
- "constantCost": "5min"
- },
- "tags": [
- "ecocode",
- "eco-design",
- "performance"
- ],
- "defaultSeverity": "Major",
- "compatibleLanguages": [
- "JAVASCRIPT",
- "TYPESCRIPT"
- ]
-}
diff --git a/ecocode-rules-specifications/src/main/rules/EC8/javascript/EC8.asciidoc b/ecocode-rules-specifications/src/main/rules/EC8/javascript/EC8.asciidoc
deleted file mode 100644
index 71b5146f..00000000
--- a/ecocode-rules-specifications/src/main/rules/EC8/javascript/EC8.asciidoc
+++ /dev/null
@@ -1,42 +0,0 @@
-:!sectids:
-
-== Why is this an issue?
-
-High-precision geolocation typically requires more power from the device's GPS hardware.
-By requesting less accurate geolocation, you can reduce the power consumption, leading to extended battery life, which is crucial for mobile devices.
-
-Obtaining highly accurate geolocation often involves more complex calculations and processing, which can increase CPU usage.
-If the application or service does not critically require pinpoint accuracy, opting for a less accurate geolocation can help minimize the strain on the device's CPU.
-
-[source,js,data-diff-id="1",data-diff-type="noncompliant"]
-----
-var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }; // Non-compliant
-navigator.geolocation.getCurrentPosition(
- (pos) => console.log(pos),
- (err) => console.warn(err),
- options
-);
-----
-
-In these examples, the enableHighAccuracy option is set to false (the default), indicating that the application prefers lower-accuracy geolocation to conserve resources:
-
-[source,js,data-diff-id="1",data-diff-type="compliant"]
-----
-navigator.geolocation.getCurrentPosition((pos) => console.log(pos)); // Compliant by default
-----
-
-[source,js,data-diff-id="1",data-diff-type="compliant"]
-----
-var options = { enableHighAccuracy: false, timeout: 5000, maximumAge: 0 }; // Compliant
-navigator.geolocation.getCurrentPosition(
- (pos) => console.log(pos),
- (err) => console.warn(err),
- options
-);
-----
-
-== Resources
-
-=== Documentation
-
-- https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition[Mozilla Web Technology for Developers] - getCurrentPosition() method
diff --git a/ecocode-rules-specifications/src/main/rules/EC89/EC89.json b/ecocode-rules-specifications/src/main/rules/EC89/EC89.json
new file mode 100644
index 00000000..a4b4753c
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC89/EC89.json
@@ -0,0 +1,17 @@
+{
+ "title": "Avoid suspect unlimited cache size",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "eco-design",
+ "performance",
+ "network",
+ "cache",
+ "ecocode"
+ ],
+ "defaultSeverity": "Major"
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC89/python/EC89.asciidoc b/ecocode-rules-specifications/src/main/rules/EC89/python/EC89.asciidoc
new file mode 100644
index 00000000..dd4ebc3f
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC89/python/EC89.asciidoc
@@ -0,0 +1,36 @@
+Python doesn't have TTL on cache with default libraries.
+
+With functools library @cache acts the same way than @lru_cache(maxsize=None).
+@lru_cache(maxsize=None) create an unlimited cache and must be a source of memory leak, an unlimited cache can take a lot of RAM / Disk space, resulting to a big energy consumption.
+
+By default, lru_cache set the size of cache to 128 entries.
+
+In this case, the cache is unlimited which is suspect.
+
+## Noncompliant Code Examples
+
+```python
+ @cache # Noncompliant
+ def cached_function():
+ ...
+```
+
+```python
+ @lru_cache(maxsize=None) # Noncompliant
+ def cached_function():
+ ...
+```
+
+## Compliant Solution
+
+```python
+ @lru_cache() # By default, the max size of the cache is 128
+ def cached_function():
+ ...
+```
+
+```python
+ @lru_cache(maxsize=16) # Define a max size to the cache
+ def cached_function():
+ ...
+```
diff --git a/ecocode-rules-specifications/src/main/rules/EC93/EC93.json b/ecocode-rules-specifications/src/main/rules/EC93/EC93.json
new file mode 100644
index 00000000..dd3cbc1d
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC93/EC93.json
@@ -0,0 +1,15 @@
+{
+ "title": "Return Task directly",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "eco-design",
+ "performance",
+ "ecocode"
+ ],
+ "defaultSeverity": "Minor"
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC93/csharp/EC93.asciidoc b/ecocode-rules-specifications/src/main/rules/EC93/csharp/EC93.asciidoc
new file mode 100644
index 00000000..07237306
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC93/csharp/EC93.asciidoc
@@ -0,0 +1,41 @@
+:!sectids:
+
+Return Task directly.
+
+## Why is this an issue ?
+
+Asynchronous methods that contain a single awaited statement can be optimized by removing the `async` modifier and returning the awaited `Task` directly. Doing so reduces the overhead of the state machine generated for the asynchronous method, leading to more efficient code and improving the resource efficiency of the application.
+
+### When can it be ignored ?
+
+When this rule is applied, exception handling is deferred to the main caller instead, which may or may not be desirable. The decision should be done with consideration to the context in which the method is used.
+
+## Non-compliant examples
+
+[source, cs]
+----
+public static async Task Test1()
+{
+ await Task.Delay(1000); // Non-compliant, return the Task directly.
+}
+
+public static async Task Test2()
+{
+ await MyAsyncMethod(); // Non-compliant, exceptions within MyAsyncMethod are handled by the method itself.
+}
+----
+
+## Compliant examples
+
+[source, cs]
+----
+public static Task Test1()
+{
+ return Task.Delay(1000); // Compliant
+}
+
+public static Task Test2()
+{
+ return MyAsyncMethod(); // Compliant, exceptions within MyAsyncMethod are handled by the caller of Test2.
+}
+----
diff --git a/ecocode-rules-specifications/src/main/rules/EC94/EC94.json b/ecocode-rules-specifications/src/main/rules/EC94/EC94.json
new file mode 100644
index 00000000..aea5000b
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC94/EC94.json
@@ -0,0 +1,15 @@
+{
+ "title": "Performance: orElseGet instead of orElse",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "1min"
+ },
+ "tags": [
+ "ecocode",
+ "eco-design",
+ "performance"
+ ],
+ "defaultSeverity": "Minor"
+}
diff --git a/ecocode-rules-specifications/src/main/rules/EC94/java/EC94.asciidoc b/ecocode-rules-specifications/src/main/rules/EC94/java/EC94.asciidoc
new file mode 100644
index 00000000..77dfc09f
--- /dev/null
+++ b/ecocode-rules-specifications/src/main/rules/EC94/java/EC94.asciidoc
@@ -0,0 +1,21 @@
+Parameter of orElse() is evaluated, even when having a non-empty Optional.
+
+Supplier method of orElseGet passed as an argument is only executed when an Optional value isnβt present.
+
+Therefore, using orElseGet() will save computing time.
+
+## Noncompliant Code Example
+
+```java
+Optional.of("ecoCode").orElse(getUnpredictedMethod());
+```
+
+## Compliant Code Example
+
+```java
+Optional.of("ecoCode").orElseGet(() -> getUnpredictedMethod());
+```
+
+```java
+randomClass.orElse(getUnpredictedMethod());
+```
diff --git a/pom.xml b/pom.xml
index 0570acbd..8d4e0441 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
io.ecocode
ecocode-parent
- 1.5.5-SNAPSHOT
+ 1.6.1-SNAPSHOT
pom
ecoCode Sonar Plugins Project