diff --git a/pom.xml b/pom.xml index 001e77c79..4b2576522 100644 --- a/pom.xml +++ b/pom.xml @@ -129,13 +129,54 @@ 11 ${java.version} ${java.version} + + ${java.version} UTF-8 ${encoding} ${encoding} - + green-code-initiative + https://sonarcloud.io + 5.9.1 + 3.23.1 + 5.3.1 + 10.10.0.2391 + 2.12.0.2964 + + + + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + test + + + org.sonarsource.api.plugin + sonar-plugin-api + ${sonarqube.version} + test + + + org.sonarsource.analyzer-commons + sonar-analyzer-commons + ${sonar-analyzer-commons.version} + test + + + org.assertj + assertj-core + ${assertJ.version} + test + + + org.mockito + mockito-junit-jupiter + ${mockito.version} + test + + @@ -148,6 +189,75 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + com.mycila + license-maven-plugin + 4.5 + + + Green Code Initiative + https://green-code-initiative.org + + + +
+ com/mycila/maven/plugin/license/templates/GPL-3.txt
+ + **/*.java + +
+
+
+ + + validate + + check + + validate + + +
+ + com.diffplug.spotless + spotless-maven-plugin + 2.43.0 + + + + 1.23.0 + + + + + + src/**/*.json + + + JSON + + + + true + 2 + + + + + + + + check + + process-sources + + + org.apache.maven.plugins maven-enforcer-plugin diff --git a/src/main/rules/GCI1/GCI1.json b/src/main/rules/GCI1/GCI1.json index 517f6035b..c9bb6e721 100644 --- a/src/main/rules/GCI1/GCI1.json +++ b/src/main/rules/GCI1/GCI1.json @@ -1,5 +1,5 @@ { - "title": "Avoid Spring repository call in loop or stream operations", + "title": "Spring repository should not be called in loop or stream operations", "type": "CODE_SMELL", "status": "ready", "remediation": { @@ -9,8 +9,14 @@ "tags": [ "performance", "spring", - "eco-design", + "sustainability", "creedengo" ], - "defaultSeverity": "Minor" + "defaultSeverity": "Minor", + "code": { + "impacts": { + "RELIABILITY": "LOW" + }, + "attribute": "EFFICIENT" + } } diff --git a/src/main/rules/GCI1/java/GCI1.asciidoc b/src/main/rules/GCI1/java/GCI1.asciidoc index e6b3ef356..0924d5029 100644 --- a/src/main/rules/GCI1/java/GCI1.asciidoc +++ b/src/main/rules/GCI1/java/GCI1.asciidoc @@ -1,10 +1,16 @@ +:!sectids: + +== Why is this an issue? + The use of Spring repository in a loop induces unnecessary calculations by the CPU and therefore superfluous energy consumption. Also, the use of Spring repository in a stream operation like "peek, forEach, forEachOrdered, map" induces unnecessary multiple access to the database instead of single batch call. -== Non compliant Code Example +== How to fix it +=== Noncompliant code example [source,java] ---- +// Noncompliant private final List ids = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); List employees = new ArrayList<>(); @@ -19,6 +25,7 @@ for (Integer id: ids) { [source,java] ---- +// Noncompliant List employees = new ArrayList<>(); Stream stream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); stream.forEach(id -> { @@ -29,7 +36,7 @@ stream.forEach(id -> { }); ---- -== Compliant Solution +=== Compliant solution [source,java] ---- @@ -42,3 +49,7 @@ List employees = employeeRepository.findAllById(ids); private final List ids = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).toList(); List employees = employeeRepository.findAllById(ids); ---- + +== Resources + +Reference/Validation is unknown. diff --git a/src/main/rules/GCI10/GCI10.json b/src/main/rules/GCI10/GCI10.json index 860137ecc..0a68e3909 100644 --- a/src/main/rules/GCI10/GCI10.json +++ b/src/main/rules/GCI10/GCI10.json @@ -1,5 +1,5 @@ { - "title": "Avoid using unoptimized vector images", + "title": "Unoptimized vector images should be avoided", "type": "CODE_SMELL", "status": "ready", "remediation": { @@ -7,8 +7,15 @@ "constantCost": "60min" }, "tags": [ - "eco-design", - "creedengo" + "sustainability", + "creedengo", + "performance" ], - "defaultSeverity": "Minor" + "defaultSeverity": "Minor", + "code": { + "impacts": { + "RELIABILITY": "LOW" + }, + "attribute": "EFFICIENT" + } } diff --git a/src/main/rules/GCI10/python/GCI10.asciidoc b/src/main/rules/GCI10/python/GCI10.asciidoc index f49f967f3..0d4080f6a 100644 --- a/src/main/rules/GCI10/python/GCI10.asciidoc +++ b/src/main/rules/GCI10/python/GCI10.asciidoc @@ -1,9 +1,15 @@ +:!sectids: + +== Why is this an issue? + SVG images generated by common drawing softwares contains unnecessary data: calc layer, metadata, namespaces and comments. -== Non compliant Code Example +== How to fix it +=== Noncompliant code example [source,xml] ---- + ---- -== Compliant Solution +=== Compliant solution [source,xml] ---- @@ -39,3 +45,7 @@ SVG images generated by common drawing softwares contains unnecessary data: calc ---- + +== Resources + +- https://github.com/cnumr/best-practices/blob/main/chapters/BP_036_fr.md[CNumR best practices (3rd edition) BP_036] diff --git a/src/main/rules/GCI11/GCI11.json b/src/main/rules/GCI11/GCI11.json index 69b9050e4..19ec17b7d 100644 --- a/src/main/rules/GCI11/GCI11.json +++ b/src/main/rules/GCI11/GCI11.json @@ -14,7 +14,7 @@ }, "tags": [ "creedengo", - "eco-design", + "sustainability", "performance" ], "defaultSeverity": "Major", diff --git a/src/main/rules/GCI11/javascript/GCI11.asciidoc b/src/main/rules/GCI11/javascript/GCI11.asciidoc index e17e2e159..bb49f9b6c 100644 --- a/src/main/rules/GCI11/javascript/GCI11.asciidoc +++ b/src/main/rules/GCI11/javascript/GCI11.asciidoc @@ -10,6 +10,9 @@ Assigning the DOM object to a variable not only improves performance but also en It makes the code more concise and self-explanatory. Developers reading the code can understand that the variable holds a reference to a specific DOM element, and its subsequent use is likely for multiple operations. +== How to fix it +=== Noncompliant code example + Here's an example in JavaScript to illustrate this rule: [source,js,data-diff-id="2",data-diff-type="noncompliant"] @@ -18,6 +21,8 @@ const width = document.getElementById('block').clientWidth; const height = document.getElementById('block').clientHeight; // Noncompliant ---- +=== Compliant solution + [source,js,data-diff-id="1",data-diff-type="noncompliant"] ---- const blockElement = document.getElementById('block'); // Compliant diff --git a/src/main/rules/GCI12/GCI12.json b/src/main/rules/GCI12/GCI12.json index fc84eeab4..a226be5d1 100644 --- a/src/main/rules/GCI12/GCI12.json +++ b/src/main/rules/GCI12/GCI12.json @@ -14,7 +14,7 @@ }, "tags": [ "creedengo", - "eco-design", + "sustainability", "performance" ], "defaultSeverity": "Major", diff --git a/src/main/rules/GCI12/javascript/GCI12.asciidoc b/src/main/rules/GCI12/javascript/GCI12.asciidoc index 4d470e679..57cb75677 100644 --- a/src/main/rules/GCI12/javascript/GCI12.asciidoc +++ b/src/main/rules/GCI12/javascript/GCI12.asciidoc @@ -10,6 +10,9 @@ Making multiple CSS changes in a single batch can trigger multiple reflows and r Reflows and repaints are resource-intensive operations that can lead to performance issues. Applying changes individually minimizes the number of reflows and repaints, improving overall page performance. +== How to fix it +=== Noncompliant code example + Here's an example in JavaScript and CSS to illustrate this rule: [source,html,data-diff-id="3",data-diff-type="noncompliant"] @@ -21,6 +24,8 @@ Here's an example in JavaScript and CSS to illustrate this rule: ---- +=== Compliant solution + [source,html,data-diff-id="10",data-diff-type="compliant"] ----