Skip to content

Commit

Permalink
Merge branch 'main' into avoid-keep-awake
Browse files Browse the repository at this point in the history
  • Loading branch information
dedece35 authored Jun 13, 2024
2 parents e734aab + 93f94a7 commit 097ec9f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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

Expand Down
3 changes: 2 additions & 1 deletion RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ Some are applicable for different technologies.
| 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` | ||||||||
| 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) | 🚫 | 🚫 | 🚀 | 🚫 | 🚫 | 🚫 | 🚀 |
Expand Down
15 changes: 15 additions & 0 deletions ecocode-rules-specifications/src/main/rules/EC94/EC94.json
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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());
```

0 comments on commit 097ec9f

Please sign in to comment.