+ The shape using the quotation marks (") allows the developer to insert variables that will be substituted at run time.
+ But if the string does not have a variable, use quotes (') instead.
+ Thus, language will not look for variables to substitute, which will reduce the consumption of CPU cycles.
+
+
Noncompliant Code Example
+
+ # in variables
+ firstname = "Andrea" # Noncompliant {{Avoid using quotation mark ("), prefer using simple quote (')}}
+
+ # in functions
+ def my_function(name, age):
+ print(name + 'is' + age + ' yo.')
+
+ my_function("Robert", 12) # Noncompliant {{Avoid using quotation mark ("), prefer using simple quote (')}}
+
diff --git a/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/CRJVM204.json b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/CRJVM204.json
new file mode 100644
index 000000000..199e43d9c
--- /dev/null
+++ b/java-plugin/src/main/resources/fr/greencodeinitiative/l10n/java/rules/java/CRJVM204.json
@@ -0,0 +1,15 @@
+{
+ "title": "Detect unoptimized image format",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "15min"
+ },
+ "tags": [
+ "eco-design",
+ "bug",
+ "ecocode"
+ ],
+ "defaultSeverity": "Minor"
+}
diff --git a/java-plugin/src/test/files/DetectUnoptimizedFileFormat.java b/java-plugin/src/test/files/DetectUnoptimizedFileFormat.java
new file mode 100644
index 000000000..31ad318a8
--- /dev/null
+++ b/java-plugin/src/test/files/DetectUnoptimizedFileFormat.java
@@ -0,0 +1,59 @@
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.LayoutManager;
+import java.io.IOException;
+import java.net.URL;
+
+import javax.swing.JEditorPane;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+public class SwingTester {
+ private static void createWindow() {
+ JFrame frame = new JFrame("Swing Tester");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ createUI(frame);
+ frame.setSize(560, 450);
+ frame.setLocationRelativeTo(null);
+ frame.setVisible(true);
+ }
+
+ private static void createUI(final JFrame frame) {
+ JPanel panel = new JPanel();
+ LayoutManager layout = new FlowLayout();
+ panel.setLayout(layout);
+
+ JEditorPane jEditorPane = new JEditorPane();
+ jEditorPane.setEditable(false);
+
+ jEditorPane.setContentType("text/html");
+ jEditorPane.setText("Le titre avec une partie en gras," +
+ " et une autre partie en bleu." +
+ " " +
+ " " + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.bmp\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.tiff\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.webp\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.png\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.jpeg\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.jfif\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.pjpeg\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.pjp\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.gif\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.avif\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.apng\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
+ "");
+
+ JScrollPane jScrollPane = new JScrollPane(jEditorPane);
+ jScrollPane.setPreferredSize(new Dimension(540, 400));
+
+ panel.add(jScrollPane);
+ panel.add(jScrollPane2);
+ frame.getContentPane().add(panel, BorderLayout.CENTER);
+ }
+}
\ No newline at end of file
diff --git a/java-plugin/src/test/files/DetectUnoptimizedFileFormatComplient.java b/java-plugin/src/test/files/DetectUnoptimizedFileFormatComplient.java
new file mode 100644
index 000000000..abd142116
--- /dev/null
+++ b/java-plugin/src/test/files/DetectUnoptimizedFileFormatComplient.java
@@ -0,0 +1,47 @@
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.LayoutManager;
+import java.io.IOException;
+import java.net.URL;
+
+import javax.swing.JEditorPane;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+public class SwingTester {
+ private static void createWindow() {
+ JFrame frame = new JFrame("Swing Tester");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ createUI(frame);
+ frame.setSize(560, 450);
+ frame.setLocationRelativeTo(null);
+ frame.setVisible(true);
+ }
+
+ private static void createUI(final JFrame frame){
+ JPanel panel = new JPanel();
+ LayoutManager layout = new FlowLayout();
+ panel.setLayout(layout);
+
+ JEditorPane jEditorPane3 = new JEditorPane();
+ jEditorPane3.setEditable(false);
+
+ jEditorPane3.setContentType("text/html");
+ jEditorPane3.setText("Le titre avec une partie en gras," +
+ " et une autre partie en bleu." +
+ " " +
+ "");
+
+ JScrollPane jScrollPane = new JScrollPane(jEditorPane);
+ jScrollPane.setPreferredSize(new Dimension(540,400));
+
+ panel.add(jScrollPane);
+ panel.add(jScrollPane2);
+ panel.add(jScrollPane3);
+ frame.getContentPane().add(panel, BorderLayout.CENTER);
+ }
+}
\ No newline at end of file
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/DetectUnoptimizedImageFormatTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/DetectUnoptimizedImageFormatTest.java
new file mode 100644
index 000000000..80f357786
--- /dev/null
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/checks/DetectUnoptimizedImageFormatTest.java
@@ -0,0 +1,23 @@
+package fr.greencodeinitiative.java.checks;
+
+import org.junit.jupiter.api.Test;
+import org.sonar.java.checks.verifier.CheckVerifier;
+
+public class DetectUnoptimizedImageFormatTest {
+
+ @Test
+ void test() {
+ CheckVerifier.newVerifier()
+ .onFile("src/test/files/DetectUnoptimizedImageFormat.java")
+ .withCheck(new DetectUnoptimizedImageFormat())
+ .verifyIssues();
+ }
+
+ @Test
+ void testComplient() {
+ CheckVerifier.newVerifier()
+ .onFile("src/test/files/DetectUnoptimizedFileFormatComplient.java")
+ .withCheck(new DetectUnoptimizedImageFormat())
+ .verifyNoIssues();
+ }
+}
From 5ec73df950171888c1063ccdfb17525e32c3174b Mon Sep 17 00:00:00 2001
From: Jean-Baptiste GINGUENE
Date: Thu, 6 Apr 2023 10:19:13 +0200
Subject: [PATCH 003/170] EC66-PYTHON - up imports
---
.../greencodeinitiative/python/PythonRuleRepository.java | 8 +++++++-
.../src/test/resources/checks/avoidDoubleQuoteCheck.py | 2 +-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java
index 7183f872c..b9056b13a 100644
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java
+++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java
@@ -29,7 +29,13 @@
import java.util.List;
import java.util.Map;
-import fr.greencodeinitiative.python.checks.*;
+import fr.greencodeinitiative.python.checks.AvoidDoubleQuoteCheck;
+import fr.greencodeinitiative.python.checks.AvoidFullSQLRequest;
+import fr.greencodeinitiative.python.checks.AvoidGettersAndSetters;
+import fr.greencodeinitiative.python.checks.AvoidGlobalVariableInFunctionCheck;
+import fr.greencodeinitiative.python.checks.AvoidSQLRequestInLoop;
+import fr.greencodeinitiative.python.checks.AvoidTryCatchFinallyCheck;
+import fr.greencodeinitiative.python.checks.NoFunctionCallWhenDeclaringForLoop;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.server.rule.RulesDefinitionAnnotationLoader;
diff --git a/python-plugin/src/test/resources/checks/avoidDoubleQuoteCheck.py b/python-plugin/src/test/resources/checks/avoidDoubleQuoteCheck.py
index 0af5f44ee..893f24e8e 100644
--- a/python-plugin/src/test/resources/checks/avoidDoubleQuoteCheck.py
+++ b/python-plugin/src/test/resources/checks/avoidDoubleQuoteCheck.py
@@ -10,4 +10,4 @@ def my_function(name, age):
print(name + 'is' + age + ' yo.')
my_function("Robert", 12) # Noncompliant {{Avoid using quotation mark ("), prefer using simple quote (')}}
-my_function('Robert', 12)
\ No newline at end of file
+my_function('Robert', 12)
From a2fbf1b674159dffd31f51f03e9fff135cab678e Mon Sep 17 00:00:00 2001
From: plougastela
Date: Thu, 6 Apr 2023 11:03:33 +0200
Subject: [PATCH 004/170] CRJVM204 Detect unoptimized image format
---
.../java/checks/DetectUnoptimizedImageFormat.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/DetectUnoptimizedImageFormat.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/DetectUnoptimizedImageFormat.java
index 43eb24d70..2b3190b19 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/DetectUnoptimizedImageFormat.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/checks/DetectUnoptimizedImageFormat.java
@@ -20,7 +20,7 @@
public class DetectUnoptimizedImageFormat extends IssuableSubscriptionVisitor {
protected static final String MESSAGERULE = "Detect unoptimized image format";
- protected static final String MESSAGEERROR = "If possible, utilisation of svg image format is recommended over other image format.";
+ protected static final String MESSAGEERROR = "If possible, the utilisation of svg image format (or html tag) is recommended over other image format.";
protected static Pattern IMG_EXTENSION = Pattern.compile("\\.(bmp|ico|tiff|webp|png|jpg|jpeg|jfif|pjpeg|pjp|gif|avif|apng)");
@Override
From cc526cc44e5face12f63042f1369d6647d1db420 Mon Sep 17 00:00:00 2001
From: plougastela
Date: Thu, 6 Apr 2023 11:19:10 +0200
Subject: [PATCH 005/170] CRJVM204 Detect unoptimized image format
---
.../files/DetectUnoptimizedFileFormat.java | 59 -------------
.../files/DetectUnoptimizedImageFormat.java | 84 +++++++++++++++++++
...etectUnoptimizedImageFormatComplient.java} | 36 ++++++--
.../DetectUnoptimizedImageFormatTest.java | 2 +-
4 files changed, 114 insertions(+), 67 deletions(-)
delete mode 100644 java-plugin/src/test/files/DetectUnoptimizedFileFormat.java
create mode 100644 java-plugin/src/test/files/DetectUnoptimizedImageFormat.java
rename java-plugin/src/test/files/{DetectUnoptimizedFileFormatComplient.java => DetectUnoptimizedImageFormatComplient.java} (50%)
diff --git a/java-plugin/src/test/files/DetectUnoptimizedFileFormat.java b/java-plugin/src/test/files/DetectUnoptimizedFileFormat.java
deleted file mode 100644
index 31ad318a8..000000000
--- a/java-plugin/src/test/files/DetectUnoptimizedFileFormat.java
+++ /dev/null
@@ -1,59 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.LayoutManager;
-import java.io.IOException;
-import java.net.URL;
-
-import javax.swing.JEditorPane;
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-
-public class SwingTester {
- private static void createWindow() {
- JFrame frame = new JFrame("Swing Tester");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- createUI(frame);
- frame.setSize(560, 450);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
-
- private static void createUI(final JFrame frame) {
- JPanel panel = new JPanel();
- LayoutManager layout = new FlowLayout();
- panel.setLayout(layout);
-
- JEditorPane jEditorPane = new JEditorPane();
- jEditorPane.setEditable(false);
-
- jEditorPane.setContentType("text/html");
- jEditorPane.setText("Le titre avec une partie en gras," +
- " et une autre partie en bleu." +
- " " +
- " " + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- " src=\"/media/cc0-images/grapefruit-slice-332-332.bmp\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- " src=\"/media/cc0-images/grapefruit-slice-332-332.tiff\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- " src=\"/media/cc0-images/grapefruit-slice-332-332.webp\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- " src=\"/media/cc0-images/grapefruit-slice-332-332.png\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- " src=\"/media/cc0-images/grapefruit-slice-332-332.jpeg\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- " src=\"/media/cc0-images/grapefruit-slice-332-332.jfif\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- " src=\"/media/cc0-images/grapefruit-slice-332-332.pjpeg\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- " src=\"/media/cc0-images/grapefruit-slice-332-332.pjp\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- " src=\"/media/cc0-images/grapefruit-slice-332-332.gif\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- " src=\"/media/cc0-images/grapefruit-slice-332-332.avif\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- " src=\"/media/cc0-images/grapefruit-slice-332-332.apng\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, utilisation of svg image format is recommended over other image format.}}
- "");
-
- JScrollPane jScrollPane = new JScrollPane(jEditorPane);
- jScrollPane.setPreferredSize(new Dimension(540, 400));
-
- panel.add(jScrollPane);
- panel.add(jScrollPane2);
- frame.getContentPane().add(panel, BorderLayout.CENTER);
- }
-}
\ No newline at end of file
diff --git a/java-plugin/src/test/files/DetectUnoptimizedImageFormat.java b/java-plugin/src/test/files/DetectUnoptimizedImageFormat.java
new file mode 100644
index 000000000..c8c631820
--- /dev/null
+++ b/java-plugin/src/test/files/DetectUnoptimizedImageFormat.java
@@ -0,0 +1,84 @@
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.LayoutManager;
+import java.io.IOException;
+import java.net.URL;
+
+import javax.swing.JEditorPane;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+public class DetectUnoptimizedImageFormat {
+
+ private String img_bmp = "test/image.bmp"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ private String img_ico = "image.ico"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ private String img_tiff = "test/path/to/image.tiff"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ private String img_webp = "test/path/to/" + "image.webp"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ private String img_jpg = "image.jpg"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ private String img_jpeg = "image.jpeg"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ private String img_jfif = "image.jfif"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ private String img_pjpeg = "image.pjpeg"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ private String img_pjp = "image.pjp"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ private String img_gif = "image.gif"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ private String img_avif = "image.avif"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ private String img_apng = "image.apng"; // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+
+
+ private static String getImagePath(String image) {
+ return "path/to/" + image;
+ }
+
+ private static void testImage() {
+ String img1 = getImagePath("test/image.bmp"); // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ String img2 = getImagePath("image.ico"); // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ String img3 = getImagePath("image.jpg"); // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ }
+
+ private static void createWindow() {
+ JFrame frame = new JFrame("Swing Tester");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ createUI(frame);
+ frame.setSize(560, 450);
+ frame.setLocationRelativeTo(null);
+ frame.setVisible(true);
+ }
+
+ private static void createUI(final JFrame frame) {
+ JPanel panel = new JPanel();
+ LayoutManager layout = new FlowLayout();
+ panel.setLayout(layout);
+
+ JEditorPane jEditorPane = new JEditorPane();
+ jEditorPane.setEditable(false);
+
+ jEditorPane.setContentType("text/html");
+ jEditorPane.setText("Le titre avec une partie en gras," +
+ " et une autre partie en bleu." +
+ " html tag) is recommended over other image format.}}
+ " alt=\"Grapefruit slice atop a pile of other slices\">" +
+ " " + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.bmp\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.tiff\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.webp\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.png\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.jpeg\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.jfif\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.pjpeg\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.pjp\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.gif\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.avif\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ " src=\"/media/cc0-images/grapefruit-slice-332-332.apng\" alt=\"Grapefruit slice atop a pile of other slices\">" + // Noncompliant {{If possible, the utilisation of svg image format (or html tag) is recommended over other image format.}}
+ "");
+
+ JScrollPane jScrollPane = new JScrollPane(jEditorPane);
+ jScrollPane.setPreferredSize(new Dimension(540, 400));
+
+ panel.add(jScrollPane);
+ panel.add(jScrollPane2);
+ frame.getContentPane().add(panel, BorderLayout.CENTER);
+ }
+}
\ No newline at end of file
diff --git a/java-plugin/src/test/files/DetectUnoptimizedFileFormatComplient.java b/java-plugin/src/test/files/DetectUnoptimizedImageFormatComplient.java
similarity index 50%
rename from java-plugin/src/test/files/DetectUnoptimizedFileFormatComplient.java
rename to java-plugin/src/test/files/DetectUnoptimizedImageFormatComplient.java
index abd142116..c0ce54011 100644
--- a/java-plugin/src/test/files/DetectUnoptimizedFileFormatComplient.java
+++ b/java-plugin/src/test/files/DetectUnoptimizedImageFormatComplient.java
@@ -10,7 +10,19 @@
import javax.swing.JPanel;
import javax.swing.JScrollPane;
-public class SwingTester {
+public class DetectUnoptimizedImageFormat {
+
+ private String img_svg = "test/image.svg"; // Complient
+
+ private String getImagePath(String image) {
+ return "path/to/" + image;
+ }
+
+ private static void testImage() {
+ String img1 = getImagePath("test/image.svg"); // Complient
+ String img2 = getImagePath("image.svg"); // Complient
+ }
+
private static void createWindow() {
JFrame frame = new JFrame("Swing Tester");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -20,24 +32,34 @@ private static void createWindow() {
frame.setVisible(true);
}
- private static void createUI(final JFrame frame){
+ private static void createUI(final JFrame frame) {
JPanel panel = new JPanel();
LayoutManager layout = new FlowLayout();
panel.setLayout(layout);
- JEditorPane jEditorPane3 = new JEditorPane();
- jEditorPane3.setEditable(false);
+ JEditorPane jEditorPane = new JEditorPane();
+ jEditorPane.setEditable(false);
- jEditorPane3.setContentType("text/html");
- jEditorPane3.setText("Le titre avec une partie en gras," +
+ jEditorPane.setContentType("text/html");
+ jEditorPane.setText("Le titre avec une partie en gras," +
" et une autre partie en bleu." +
" " +
"");
+ JEditorPane jEditorPane1 = new JEditorPane();
+ jEditorPane1.setEditable(false);
+
+ jEditorPane1.setContentType("text/html");
+ jEditorPane1.setText("Le titre avec une partie en gras," +
+ " et une autre partie en bleu." +
+ "
+
Some advantages of using SVG :
+
+
SVGs are scalable and will render pixel-perfect at any resolution whereas JPEGs, PNGs and GIFs will not.
+
SVGs are vector images and therefore are usually much smaller in file-size than bitmap-based images.
+
SVGs can be embedded into the HTML which means they can be cached, edited directly using CSS and indexed for greater accessibility.
+
SVGs can be animated directly or by using CSS or JavaScript making it easy for web designers to add interactivity to a site.
When iterating over any collection, fetch the size of the collection in advance to avoid fetching it on each iteration, this saves CPU cycles, and therefore consumes less power.
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpRuleRepositoryTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpRuleRepositoryTest.java
index f2345716d..3a124f382 100644
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpRuleRepositoryTest.java
+++ b/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpRuleRepositoryTest.java
@@ -41,8 +41,8 @@ public void init() {
public void test() {
assertThat(phpRuleRepository.repositoryKey()).isEqualTo(PhpRuleRepository.REPOSITORY_KEY);
assertThat(context.repositories()).hasSize(1).extracting("key").containsExactly(phpRuleRepository.repositoryKey());
- assertThat(context.repositories().get(0).rules()).hasSize(8);
- assertThat(phpRuleRepository.checkClasses()).hasSize(8);
+ assertThat(context.repositories().get(0).rules()).hasSize(9);
+ assertThat(phpRuleRepository.checkClasses()).hasSize(9);
}
/**
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidGettingSizeCollectionInForLoopTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidGettingSizeCollectionInForLoopTest.java
new file mode 100644
index 000000000..9e527c140
--- /dev/null
+++ b/php-plugin/src/test/java/fr/greencodeinitiative/php/checks/AvoidGettingSizeCollectionInForLoopTest.java
@@ -0,0 +1,15 @@
+package fr.greencodeinitiative.php.checks;
+
+import org.junit.Test;
+import org.sonar.plugins.php.api.tests.PHPCheckTest;
+import org.sonar.plugins.php.api.tests.PhpTestFile;
+
+import java.io.File;
+
+public class AvoidGettingSizeCollectionInForLoopTest {
+
+ @Test
+ public void test() throws Exception {
+ PHPCheckTest.check(new AvoidGettingSizeCollectionInForLoopCheck(), new PhpTestFile(new File("src/test/resources/checks/AvoidGettingSizeCollectionInForLoop.php")));
+ }
+}
diff --git a/php-plugin/src/test/resources/checks/AvoidGettingSizeCollectionInForLoop.php b/php-plugin/src/test/resources/checks/AvoidGettingSizeCollectionInForLoop.php
new file mode 100644
index 000000000..4fa8d242b
--- /dev/null
+++ b/php-plugin/src/test/resources/checks/AvoidGettingSizeCollectionInForLoop.php
@@ -0,0 +1,79 @@
+
Date: Thu, 13 Apr 2023 23:43:38 +0200
Subject: [PATCH 020/170] update CHANGELOG
---
CHANGELOG.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca102b523..4d6548bc1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,7 +25,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#63](https://github.com/green-code-initiative/ecoCode/issues/63) Update plugins to be compliant for SonarQube MarketPlace integration ( PR [#79](https://github.com/green-code-initiative/ecoCode/pull/79) )
- [#88](https://github.com/green-code-initiative/ecoCode/pull/88) upgrade rules matrix with new ids + refactoring rules documentation (`RULES.md`)
- - _*WARNING*_ : since this plugin version, ids of plugin rules changed. In consequence, if you have already made some issue checks in your SonarQube instance, you will have to do them again (example : false-positive issues will appear again)
### Deleted
From 4d995451a7a0ee1eee4f830eb264169b08ace1c9 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Fri, 14 Apr 2023 09:52:26 +0200
Subject: [PATCH 021/170] [ISSUE 173] correction of unit tests :(
---
.../avoidTryCatchFinallyCheck_NOK_FailsAllTryStatements.php | 4 ++--
.../src/test/resources/checks/avoidTryCatchFinallyCheck.py | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/php-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck_NOK_FailsAllTryStatements.php b/php-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck_NOK_FailsAllTryStatements.php
index 22a44564c..1698df424 100644
--- a/php-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck_NOK_FailsAllTryStatements.php
+++ b/php-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck_NOK_FailsAllTryStatements.php
@@ -7,7 +7,7 @@ function test() {
throw new SpecificException('Oopsie');
}
-try // NOK {{Avoid using try-catch-finally}}
+try // NOK {{Avoid using try-catch}}
{
$picture = PDF_open_image_file($PDF, "jpeg", $imgFile, "", 0); // This is the original statement, this works on PHP4
}
@@ -17,7 +17,7 @@ function test() {
throw new Exception($msg);
}
-try { // NOK {{Avoid using try-catch-finally}}
+try { // NOK {{Avoid using try-catch}}
throw new \Exception("Hello");
} catch(\Exception $e) {
echo $e->getMessage()." catch in\n";
diff --git a/python-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck.py b/python-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck.py
index a026587ed..1e24bb491 100644
--- a/python-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck.py
+++ b/python-plugin/src/test/resources/checks/avoidTryCatchFinallyCheck.py
@@ -6,7 +6,7 @@
def my_function():
x=0
- try: # Noncompliant {{Avoid the use of try-catch-finally}}
+ try: # Noncompliant {{Avoid the use of try-catch}}
print(x)
except:
print("Something went wrong")
@@ -14,7 +14,7 @@ def my_function():
print("The 'try except' is finished")
def foo():
- try: # Noncompliant {{Avoid the use of try-catch-finally}}
+ try: # Noncompliant {{Avoid the use of try-catch}}
f = open(path)
print(f.read())
except:
From 56a4498ec9825264520225324da9c6ce290d2a11 Mon Sep 17 00:00:00 2001
From: Ludovic BOSSE <63793941+natixis-caen@users.noreply.github.com>
Date: Fri, 14 Apr 2023 10:05:54 +0200
Subject: [PATCH 022/170] [ISSUE 161] :heavy_minus_sign: Remove unused junit
dependency
---
CHANGELOG.md | 1 +
java-plugin/pom.xml | 6 ------
javascript-plugin/pom.xml | 6 ++----
.../javascript/JavaScriptPluginTest.java | 6 +++---
.../javascript/JavaScriptRulesDefinitionTest.java | 6 +++---
php-plugin/pom.xml | 7 -------
pom.xml | 15 ---------------
python-plugin/pom.xml | 6 ------
8 files changed, 9 insertions(+), 44 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4d6548bc1..cf6f01553 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [171](https://github.com/green-code-initiative/ecoCode/issues/171) Add migration mechanism to support "issue re-keying"
### Changed
+- [#161](https://github.com/green-code-initiative/ecoCode/pull/161) Remove unnecessary junit dependencies in pom.xml
- [166](https://github.com/green-code-initiative/ecoCode/issues/166) Correction of wrong message of rule EC63
- [167](https://github.com/green-code-initiative/ecoCode/issues/167) Use same kind for rules across different languages
diff --git a/java-plugin/pom.xml b/java-plugin/pom.xml
index 6e5e11f38..88ba0c619 100644
--- a/java-plugin/pom.xml
+++ b/java-plugin/pom.xml
@@ -69,12 +69,6 @@
test
-
- org.junit.jupiter
- junit-jupiter-migrationsupport
- test
-
-
org.assertjassertj-core
diff --git a/javascript-plugin/pom.xml b/javascript-plugin/pom.xml
index 8412187ea..379b9f388 100644
--- a/javascript-plugin/pom.xml
+++ b/javascript-plugin/pom.xml
@@ -38,11 +38,9 @@
sonar-analyzer-commons
-
-
- junit
- junit
+ org.junit.jupiter
+ junit-jupitertest
diff --git a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java b/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java
index a558e0626..ad50f25ec 100644
--- a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java
+++ b/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java
@@ -1,15 +1,15 @@
package fr.greencodeinitiative.javascript;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.*;
import org.sonar.api.utils.Version;
import static org.assertj.core.api.Assertions.assertThat;
-public class JavaScriptPluginTest {
+class JavaScriptPluginTest {
@Test
- public void extensions() {
+ void extensions() {
Plugin.Context context = new Plugin.Context(new MockedSonarRuntime());
new JavaScriptPlugin().define(context);
assertThat(context.getExtensions()).hasSize(1);
diff --git a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinitionTest.java b/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinitionTest.java
index 60bdc8510..e90f75d95 100644
--- a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinitionTest.java
+++ b/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptRulesDefinitionTest.java
@@ -1,14 +1,14 @@
package fr.greencodeinitiative.javascript;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.sonar.api.server.rule.RulesDefinition;
import static org.assertj.core.api.Assertions.assertThat;
-public class JavaScriptRulesDefinitionTest {
+class JavaScriptRulesDefinitionTest {
@Test
- public void createExternalRepository() {
+ void createExternalRepository() {
RulesDefinition.Context context = new RulesDefinition.Context();
new JavaScriptRulesDefinition().define(context);
assertThat(context.repositories()).hasSize(1);
diff --git a/php-plugin/pom.xml b/php-plugin/pom.xml
index a79f181ef..0180065c8 100644
--- a/php-plugin/pom.xml
+++ b/php-plugin/pom.xml
@@ -40,18 +40,11 @@
-
- junit
- junit
- test
-
-
org.assertjassertj-coretest
-
diff --git a/pom.xml b/pom.xml
index 83d26a01e..c778ffec3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,7 +67,6 @@
1.21.0.505true3.4.1
- 4.13.25.9.13.23.1
@@ -156,13 +155,6 @@
test
-
- org.junit.jupiter
- junit-jupiter-migrationsupport
- ${junit.jupiter.version}
- test
-
-
org.assertjassertj-core
@@ -170,13 +162,6 @@
test
-
- junit
- junit
- ${junit.version}
- test
-
-
org.sonarsource.pythonpython-checks-testkit
diff --git a/python-plugin/pom.xml b/python-plugin/pom.xml
index bfef526ff..cbc4d6906 100644
--- a/python-plugin/pom.xml
+++ b/python-plugin/pom.xml
@@ -44,12 +44,6 @@
test
-
- junit
- junit
- test
-
-
From 3021907849a70d460923f44c14a824b51b395ddb Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Fri, 14 Apr 2023 10:08:05 +0200
Subject: [PATCH 023/170] [ISSUE 173] correction issue description
---
.../python/checks/AvoidTryCatchFinallyCheck.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheck.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheck.java
index 2d70e97f3..70197a1e3 100644
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheck.java
+++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidTryCatchFinallyCheck.java
@@ -10,7 +10,7 @@
@Rule(
key = AvoidTryCatchFinallyCheck.RULE_KEY,
- name = "Avoid using try-catch-finally statement",
+ name = "Avoid using try-catch statement",
description = AvoidTryCatchFinallyCheck.DESCRIPTION,
priority = Priority.MINOR,
tags = {"bug", "eco-design", "ecocode"})
From e88624351e43de411ebb3cc29f5f4f6474162a4d Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Fri, 14 Apr 2023 10:08:18 +0200
Subject: [PATCH 024/170] upgrade CHANGELOG.md
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cf6f01553..84c2ca3b0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,8 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [171](https://github.com/green-code-initiative/ecoCode/issues/171) Add migration mechanism to support "issue re-keying"
### Changed
-- [#161](https://github.com/green-code-initiative/ecoCode/pull/161) Remove unnecessary junit dependencies in pom.xml
+- [#161](https://github.com/green-code-initiative/ecoCode/pull/161) Remove unnecessary junit dependencies in pom.xml
- [166](https://github.com/green-code-initiative/ecoCode/issues/166) Correction of wrong message of rule EC63
- [167](https://github.com/green-code-initiative/ecoCode/issues/167) Use same kind for rules across different languages
- [173](https://github.com/green-code-initiative/ecoCode/issues/173) Update issue description of rule EC34 (try-catch)
From 9cdd98c2b67a1b4f867908125e52d3221a2bcd5b Mon Sep 17 00:00:00 2001
From: Ludovic BOSSE <63793941+natixis-caen@users.noreply.github.com>
Date: Fri, 14 Apr 2023 11:11:05 +0200
Subject: [PATCH 025/170] [ISSUE 177] Rename property in pom (#177)
---
pom.xml | 13 +++++++------
python-plugin/pom.xml | 2 +-
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/pom.xml b/pom.xml
index c778ffec3..6841635cb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,7 +51,6 @@
${encoding}9.4.0.54424
- 7.15.0.30507green-code-initiativehttps://sonarcloud.io
@@ -59,11 +58,13 @@
0.8.8
- 9.7.1.62043
- 2.1.0.1111
- 3.19.0.10254
+ 7.15.0.30507
+ 3.19.0.102543.25.0.90779.13.0.20537
+
+ 9.7.1.62043
+ 2.1.0.11111.21.0.505true3.4.1
@@ -135,7 +136,7 @@
org.sonarsource.pythonsonar-python-plugin
- ${sonar.python.version}
+ ${sonarpython.version}sonar-pluginprovided
@@ -165,7 +166,7 @@
org.sonarsource.pythonpython-checks-testkit
- ${sonar.python.version}
+ ${sonarpython.version}test
diff --git a/python-plugin/pom.xml b/python-plugin/pom.xml
index cbc4d6906..faa480543 100644
--- a/python-plugin/pom.xml
+++ b/python-plugin/pom.xml
@@ -57,7 +57,7 @@
${project.name}fr.greencodeinitiative.python.PythonPlugintrue
- python:${sonar.python.version}
+ python:${sonarpython.version}${sonarqube.version}${java.version}
From e1b16d29bee24e68226c24651a29d4d822420a42 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Fri, 14 Apr 2023 22:54:40 +0200
Subject: [PATCH 026/170] prepare 1.2.0 version
---
docker-compose.yml | 16 ++++++++--------
java-plugin/pom.xml | 2 +-
javascript-plugin/pom.xml | 2 +-
php-plugin/pom.xml | 2 +-
pom.xml | 2 +-
python-plugin/pom.xml | 2 +-
6 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/docker-compose.yml b/docker-compose.yml
index bc48387aa..e188f2bf0 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -16,17 +16,17 @@ services:
SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true'
volumes:
- type: bind
- source: ./java-plugin/target/ecocode-java-plugin-1.1.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.1.1-SNAPSHOT.jar
+ source: ./java-plugin/target/ecocode-java-plugin-1.2.0-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.2.0-SNAPSHOT.jar
- type: bind
- source: ./javascript-plugin/target/ecocode-javascript-plugin-1.1.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-javascript-plugin-1.1.1-SNAPSHOT.jar
+ source: ./javascript-plugin/target/ecocode-javascript-plugin-1.2.0-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-javascript-plugin-1.2.0-SNAPSHOT.jar
- type: bind
- source: ./php-plugin/target/ecocode-php-plugin-1.1.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-php-plugin-1.1.1-SNAPSHOT.jar
+ source: ./php-plugin/target/ecocode-php-plugin-1.2.0-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-php-plugin-1.2.0-SNAPSHOT.jar
- type: bind
- source: ./python-plugin/target/ecocode-python-plugin-1.1.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-python-plugin-1.1.1-SNAPSHOT.jar
+ source: ./python-plugin/target/ecocode-python-plugin-1.2.0-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-python-plugin-1.2.0-SNAPSHOT.jar
- "extensions:/opt/sonarqube/extensions"
- "logs:/opt/sonarqube/logs"
- "data:/opt/sonarqube/data"
diff --git a/java-plugin/pom.xml b/java-plugin/pom.xml
index 88ba0c619..7d08b5082 100644
--- a/java-plugin/pom.xml
+++ b/java-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.1.1-SNAPSHOT
+ 1.2.0-SNAPSHOTecocode-java-plugin
diff --git a/javascript-plugin/pom.xml b/javascript-plugin/pom.xml
index 379b9f388..353c00a1e 100644
--- a/javascript-plugin/pom.xml
+++ b/javascript-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.1.1-SNAPSHOT
+ 1.2.0-SNAPSHOTecocode-javascript-plugin
diff --git a/php-plugin/pom.xml b/php-plugin/pom.xml
index 0180065c8..675548ea8 100644
--- a/php-plugin/pom.xml
+++ b/php-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.1.1-SNAPSHOT
+ 1.2.0-SNAPSHOTecocode-php-plugin
diff --git a/pom.xml b/pom.xml
index 6841635cb..0ce325dfe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
io.ecocodeecocode-parent
- 1.1.1-SNAPSHOT
+ 1.2.0-SNAPSHOTpomecoCode Sonar Plugins Project
diff --git a/python-plugin/pom.xml b/python-plugin/pom.xml
index faa480543..280d64ba4 100644
--- a/python-plugin/pom.xml
+++ b/python-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.1.1-SNAPSHOT
+ 1.2.0-SNAPSHOTecocode-python-plugin
From 8f60ea11f74a0c7c5e92b36e56202753c8174b73 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Fri, 14 Apr 2023 22:57:39 +0200
Subject: [PATCH 027/170] prepare 1.2.0 version - CHANGELOG.md update
---
CHANGELOG.md | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 84c2ca3b0..b97918436 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
+### Changed
+
+### Deleted
+
+## [1.2.0] - 2023-04-14
+
+### Added
+
- [171](https://github.com/green-code-initiative/ecoCode/issues/171) Add migration mechanism to support "issue re-keying"
### Changed
@@ -108,9 +116,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- First official release of ecocode plugins : java plugin, php plugin and python plugin
-[unreleased]: https://github.com/green-code-initiative/ecoCode/compare/v1.1.0...HEAD
+[unreleased]: https://github.com/green-code-initiative/ecoCode/compare/v1.2.0...HEAD
+
+[1.2.0]: https://github.com/green-code-initiative/ecoCode/compare/v1.1.0...v1.2.0
-[1.0.0]: https://github.com/green-code-initiative/ecoCode/compare/v1.0.0...v1.1.0
+[1.1.0]: https://github.com/green-code-initiative/ecoCode/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/green-code-initiative/ecoCode/compare/v0.2.2...v1.0.0
From 7354bec681c2e0bbbd43c07912e858ee9c6ecea9 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Fri, 14 Apr 2023 23:00:11 +0200
Subject: [PATCH 028/170] [maven-release-plugin] prepare release 1.2.0
---
java-plugin/pom.xml | 2 +-
javascript-plugin/pom.xml | 2 +-
php-plugin/pom.xml | 2 +-
pom.xml | 4 ++--
python-plugin/pom.xml | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/java-plugin/pom.xml b/java-plugin/pom.xml
index 7d08b5082..7abb551fa 100644
--- a/java-plugin/pom.xml
+++ b/java-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.0-SNAPSHOT
+ 1.2.0ecocode-java-plugin
diff --git a/javascript-plugin/pom.xml b/javascript-plugin/pom.xml
index 353c00a1e..7c8ff136a 100644
--- a/javascript-plugin/pom.xml
+++ b/javascript-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.0-SNAPSHOT
+ 1.2.0ecocode-javascript-plugin
diff --git a/php-plugin/pom.xml b/php-plugin/pom.xml
index 675548ea8..ce245a592 100644
--- a/php-plugin/pom.xml
+++ b/php-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.0-SNAPSHOT
+ 1.2.0ecocode-php-plugin
diff --git a/pom.xml b/pom.xml
index 0ce325dfe..4c7d81730 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
io.ecocodeecocode-parent
- 1.2.0-SNAPSHOT
+ 1.2.0pomecoCode Sonar Plugins Project
@@ -33,7 +33,7 @@
scm:git:https://github.com/green-code-initiative/ecocodescm:git:https://github.com/green-code-initiative/ecocodehttps://github.com/green-code-initiative/ecocode
- HEAD
+ 1.2.0GitHub
diff --git a/python-plugin/pom.xml b/python-plugin/pom.xml
index 280d64ba4..7ea1007f6 100644
--- a/python-plugin/pom.xml
+++ b/python-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.0-SNAPSHOT
+ 1.2.0ecocode-python-plugin
From 7e21523d98246f34e69d07289dd84da098d00656 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Fri, 14 Apr 2023 23:00:12 +0200
Subject: [PATCH 029/170] [maven-release-plugin] prepare for next development
iteration
---
java-plugin/pom.xml | 2 +-
javascript-plugin/pom.xml | 2 +-
php-plugin/pom.xml | 2 +-
pom.xml | 4 ++--
python-plugin/pom.xml | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/java-plugin/pom.xml b/java-plugin/pom.xml
index 7abb551fa..49c99e88e 100644
--- a/java-plugin/pom.xml
+++ b/java-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.0
+ 1.2.1-SNAPSHOTecocode-java-plugin
diff --git a/javascript-plugin/pom.xml b/javascript-plugin/pom.xml
index 7c8ff136a..56c1b52d6 100644
--- a/javascript-plugin/pom.xml
+++ b/javascript-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.0
+ 1.2.1-SNAPSHOTecocode-javascript-plugin
diff --git a/php-plugin/pom.xml b/php-plugin/pom.xml
index ce245a592..1cef01679 100644
--- a/php-plugin/pom.xml
+++ b/php-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.0
+ 1.2.1-SNAPSHOTecocode-php-plugin
diff --git a/pom.xml b/pom.xml
index 4c7d81730..9a7d83e5c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
io.ecocodeecocode-parent
- 1.2.0
+ 1.2.1-SNAPSHOTpomecoCode Sonar Plugins Project
@@ -33,7 +33,7 @@
scm:git:https://github.com/green-code-initiative/ecocodescm:git:https://github.com/green-code-initiative/ecocodehttps://github.com/green-code-initiative/ecocode
- 1.2.0
+ HEADGitHub
diff --git a/python-plugin/pom.xml b/python-plugin/pom.xml
index 7ea1007f6..9529ebc29 100644
--- a/python-plugin/pom.xml
+++ b/python-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.0
+ 1.2.1-SNAPSHOTecocode-python-plugin
From 32dbf33de1634681a3d613acd5b57b01e3509bec Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Fri, 14 Apr 2023 23:17:22 +0200
Subject: [PATCH 030/170] end of 1.2.0 release : change docker-compose to
1.2.1-SNAPSHOT
---
docker-compose.yml | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/docker-compose.yml b/docker-compose.yml
index e188f2bf0..6b7db1772 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -16,17 +16,17 @@ services:
SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true'
volumes:
- type: bind
- source: ./java-plugin/target/ecocode-java-plugin-1.2.0-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.2.0-SNAPSHOT.jar
+ source: ./java-plugin/target/ecocode-java-plugin-1.2.1-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.2.1-SNAPSHOT.jar
- type: bind
- source: ./javascript-plugin/target/ecocode-javascript-plugin-1.2.0-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-javascript-plugin-1.2.0-SNAPSHOT.jar
+ source: ./javascript-plugin/target/ecocode-javascript-plugin-1.2.1-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-javascript-plugin-1.2.1-SNAPSHOT.jar
- type: bind
- source: ./php-plugin/target/ecocode-php-plugin-1.2.0-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-php-plugin-1.2.0-SNAPSHOT.jar
+ source: ./php-plugin/target/ecocode-php-plugin-1.2.1-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-php-plugin-1.2.1-SNAPSHOT.jar
- type: bind
- source: ./python-plugin/target/ecocode-python-plugin-1.2.0-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-python-plugin-1.2.0-SNAPSHOT.jar
+ source: ./python-plugin/target/ecocode-python-plugin-1.2.1-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-python-plugin-1.2.1-SNAPSHOT.jar
- "extensions:/opt/sonarqube/extensions"
- "logs:/opt/sonarqube/logs"
- "data:/opt/sonarqube/data"
From 08938f422bb724418467ba853dff6b0f60c55935 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Fri, 14 Apr 2023 23:18:55 +0200
Subject: [PATCH 031/170] correction typo CHANGELOG.md
---
CHANGELOG.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b97918436..fbde0393c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,14 +17,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
-- [171](https://github.com/green-code-initiative/ecoCode/issues/171) Add migration mechanism to support "issue re-keying"
+- [#171](https://github.com/green-code-initiative/ecoCode/issues/171) Add migration mechanism to support "issue re-keying"
### Changed
- [#161](https://github.com/green-code-initiative/ecoCode/pull/161) Remove unnecessary junit dependencies in pom.xml
-- [166](https://github.com/green-code-initiative/ecoCode/issues/166) Correction of wrong message of rule EC63
-- [167](https://github.com/green-code-initiative/ecoCode/issues/167) Use same kind for rules across different languages
-- [173](https://github.com/green-code-initiative/ecoCode/issues/173) Update issue description of rule EC34 (try-catch)
+- [#166](https://github.com/green-code-initiative/ecoCode/issues/166) Correction of wrong message of rule EC63
+- [#167](https://github.com/green-code-initiative/ecoCode/issues/167) Use same kind for rules across different languages
+- [#173](https://github.com/green-code-initiative/ecoCode/issues/173) Update issue description of rule EC34 (try-catch)
### Deleted
From 2caa75272ed89ce958ba2e5f9030cdb69c2723aa Mon Sep 17 00:00:00 2001
From: jycr
Date: Tue, 18 Apr 2023 01:05:46 +0200
Subject: [PATCH 032/170] green-code-initiative/ecoCode#63 fix: fixes metadata
generation task from SonarSource/sonar-update-center-properties
Since "core" analyzers have been integrated more tightly with SonarQube, they no longer appear on the Marketplace. So now plugins should no longer explicitly "require" their respective language "core" analyzers.
More information: https://community.sonarsource.com/t/new-plugin-ecocode-requesting-inclusion-in-sonarqube-marketplace/85398/20
---
java-plugin/pom.xml | 10 ----------
javascript-plugin/pom.xml | 1 -
php-plugin/pom.xml | 2 --
.../fr/greencodeinitiative/php/PhpRuleRepository.java | 4 +---
python-plugin/pom.xml | 1 -
5 files changed, 1 insertion(+), 17 deletions(-)
diff --git a/java-plugin/pom.xml b/java-plugin/pom.xml
index 49c99e88e..9daece94e 100644
--- a/java-plugin/pom.xml
+++ b/java-plugin/pom.xml
@@ -44,12 +44,6 @@
3.11
-
- com.google.guava
- guava
- 31.0.1-jre
-
-
com.google.re2j
@@ -89,10 +83,6 @@
fr.greencodeinitiative.java.JavaPlugintrue${sonarqube.version}
-
-
-
- java${java.version}
diff --git a/javascript-plugin/pom.xml b/javascript-plugin/pom.xml
index 56c1b52d6..f7d53dc99 100644
--- a/javascript-plugin/pom.xml
+++ b/javascript-plugin/pom.xml
@@ -64,7 +64,6 @@
fr.greencodeinitiative.javascript.JavaScriptPlugintrue${sonarqube.version}
- javascript${java.version}
diff --git a/php-plugin/pom.xml b/php-plugin/pom.xml
index 1cef01679..46492ca2c 100644
--- a/php-plugin/pom.xml
+++ b/php-plugin/pom.xml
@@ -59,9 +59,7 @@
fr.greencodeinitiative.php.PHPPlugintrue${sonarqube.version}
- php${java.version}
- php:${sonarphp.version}${sonarqube.version}${java.version}
diff --git a/php-plugin/src/main/java/fr/greencodeinitiative/php/PhpRuleRepository.java b/php-plugin/src/main/java/fr/greencodeinitiative/php/PhpRuleRepository.java
index bebb9e605..91d307a7e 100644
--- a/php-plugin/src/main/java/fr/greencodeinitiative/php/PhpRuleRepository.java
+++ b/php-plugin/src/main/java/fr/greencodeinitiative/php/PhpRuleRepository.java
@@ -24,12 +24,10 @@
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import com.google.common.collect.ImmutableList;
import fr.greencodeinitiative.php.checks.AvoidDoubleQuoteCheck;
import fr.greencodeinitiative.php.checks.AvoidFullSQLRequestCheck;
import fr.greencodeinitiative.php.checks.AvoidSQLRequestInLoopCheck;
@@ -90,7 +88,7 @@ public String repositoryKey() {
@Override
public List> checkClasses() {
- return ImmutableList.of(
+ return List.of(
AvoidDoubleQuoteCheck.class,
AvoidFullSQLRequestCheck.class,
AvoidSQLRequestInLoopCheck.class,
diff --git a/python-plugin/pom.xml b/python-plugin/pom.xml
index 9529ebc29..cdfa76710 100644
--- a/python-plugin/pom.xml
+++ b/python-plugin/pom.xml
@@ -57,7 +57,6 @@
${project.name}fr.greencodeinitiative.python.PythonPlugintrue
- python:${sonarpython.version}${sonarqube.version}${java.version}
From 6ce15e2d7ee7204611eefba0d6a30828ba173fc9 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Tue, 18 Apr 2023 09:45:59 +0200
Subject: [PATCH 033/170] prepare 1.2.1 version - CHANGELOG.md update
---
CHANGELOG.md | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fbde0393c..3b36e9b06 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deleted
+## [1.2.1] - 2023-04-18
+
+### Added
+
+### Changed
+
+- [#180](https://github.com/green-code-initiative/ecoCode/pull/180) correction of SonarQube review for MarketPlace (sonar plugin)
+
+### Deleted
+
## [1.2.0] - 2023-04-14
### Added
@@ -116,7 +126,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- First official release of ecocode plugins : java plugin, php plugin and python plugin
-[unreleased]: https://github.com/green-code-initiative/ecoCode/compare/v1.2.0...HEAD
+[unreleased]: https://github.com/green-code-initiative/ecoCode/compare/v1.2.1...HEAD
+
+[1.2.1]: https://github.com/green-code-initiative/ecoCode/compare/v1.2.0...v1.2.1
[1.2.0]: https://github.com/green-code-initiative/ecoCode/compare/v1.1.0...v1.2.0
From 7565ab0eb8ef7087f3ada6346ca4ae1053f15850 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Tue, 18 Apr 2023 09:47:01 +0200
Subject: [PATCH 034/170] [maven-release-plugin] prepare release 1.2.1
---
java-plugin/pom.xml | 2 +-
javascript-plugin/pom.xml | 2 +-
php-plugin/pom.xml | 2 +-
pom.xml | 4 ++--
python-plugin/pom.xml | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/java-plugin/pom.xml b/java-plugin/pom.xml
index 9daece94e..fad3faeba 100644
--- a/java-plugin/pom.xml
+++ b/java-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.1-SNAPSHOT
+ 1.2.1ecocode-java-plugin
diff --git a/javascript-plugin/pom.xml b/javascript-plugin/pom.xml
index f7d53dc99..b2e3f073c 100644
--- a/javascript-plugin/pom.xml
+++ b/javascript-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.1-SNAPSHOT
+ 1.2.1ecocode-javascript-plugin
diff --git a/php-plugin/pom.xml b/php-plugin/pom.xml
index 46492ca2c..df91f1031 100644
--- a/php-plugin/pom.xml
+++ b/php-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.1-SNAPSHOT
+ 1.2.1ecocode-php-plugin
diff --git a/pom.xml b/pom.xml
index 9a7d83e5c..688a9fa74 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
io.ecocodeecocode-parent
- 1.2.1-SNAPSHOT
+ 1.2.1pomecoCode Sonar Plugins Project
@@ -33,7 +33,7 @@
scm:git:https://github.com/green-code-initiative/ecocodescm:git:https://github.com/green-code-initiative/ecocodehttps://github.com/green-code-initiative/ecocode
- HEAD
+ 1.2.1GitHub
diff --git a/python-plugin/pom.xml b/python-plugin/pom.xml
index cdfa76710..60a6cd683 100644
--- a/python-plugin/pom.xml
+++ b/python-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.1-SNAPSHOT
+ 1.2.1ecocode-python-plugin
From 485f2dfe1796f507b2d79f87dd217b756a72b64d Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Tue, 18 Apr 2023 09:47:01 +0200
Subject: [PATCH 035/170] [maven-release-plugin] prepare for next development
iteration
---
java-plugin/pom.xml | 2 +-
javascript-plugin/pom.xml | 2 +-
php-plugin/pom.xml | 2 +-
pom.xml | 4 ++--
python-plugin/pom.xml | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/java-plugin/pom.xml b/java-plugin/pom.xml
index fad3faeba..acb1b601c 100644
--- a/java-plugin/pom.xml
+++ b/java-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.1
+ 1.2.2-SNAPSHOTecocode-java-plugin
diff --git a/javascript-plugin/pom.xml b/javascript-plugin/pom.xml
index b2e3f073c..3349c963f 100644
--- a/javascript-plugin/pom.xml
+++ b/javascript-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.1
+ 1.2.2-SNAPSHOTecocode-javascript-plugin
diff --git a/php-plugin/pom.xml b/php-plugin/pom.xml
index df91f1031..0910c07b5 100644
--- a/php-plugin/pom.xml
+++ b/php-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.1
+ 1.2.2-SNAPSHOTecocode-php-plugin
diff --git a/pom.xml b/pom.xml
index 688a9fa74..4f15d9b78 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
io.ecocodeecocode-parent
- 1.2.1
+ 1.2.2-SNAPSHOTpomecoCode Sonar Plugins Project
@@ -33,7 +33,7 @@
scm:git:https://github.com/green-code-initiative/ecocodescm:git:https://github.com/green-code-initiative/ecocodehttps://github.com/green-code-initiative/ecocode
- 1.2.1
+ HEADGitHub
diff --git a/python-plugin/pom.xml b/python-plugin/pom.xml
index 60a6cd683..1a239fa51 100644
--- a/python-plugin/pom.xml
+++ b/python-plugin/pom.xml
@@ -5,7 +5,7 @@
io.ecocodeecocode-parent
- 1.2.1
+ 1.2.2-SNAPSHOTecocode-python-plugin
From d7154361c5555d3b6dc0a4b8d09aedd69fd1db3e Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Tue, 18 Apr 2023 10:01:50 +0200
Subject: [PATCH 036/170] docker-compose update for current version
---
docker-compose.yml | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/docker-compose.yml b/docker-compose.yml
index 6b7db1772..a6aca9888 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -16,17 +16,17 @@ services:
SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: 'true'
volumes:
- type: bind
- source: ./java-plugin/target/ecocode-java-plugin-1.2.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.2.1-SNAPSHOT.jar
+ source: ./java-plugin/target/ecocode-java-plugin-1.2.2-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-java-plugin-1.2.2-SNAPSHOT.jar
- type: bind
- source: ./javascript-plugin/target/ecocode-javascript-plugin-1.2.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-javascript-plugin-1.2.1-SNAPSHOT.jar
+ source: ./javascript-plugin/target/ecocode-javascript-plugin-1.2.2-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-javascript-plugin-1.2.2-SNAPSHOT.jar
- type: bind
- source: ./php-plugin/target/ecocode-php-plugin-1.2.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-php-plugin-1.2.1-SNAPSHOT.jar
+ source: ./php-plugin/target/ecocode-php-plugin-1.2.2-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-php-plugin-1.2.2-SNAPSHOT.jar
- type: bind
- source: ./python-plugin/target/ecocode-python-plugin-1.2.1-SNAPSHOT.jar
- target: /opt/sonarqube/extensions/plugins/ecocode-python-plugin-1.2.1-SNAPSHOT.jar
+ source: ./python-plugin/target/ecocode-python-plugin-1.2.2-SNAPSHOT.jar
+ target: /opt/sonarqube/extensions/plugins/ecocode-python-plugin-1.2.2-SNAPSHOT.jar
- "extensions:/opt/sonarqube/extensions"
- "logs:/opt/sonarqube/logs"
- "data:/opt/sonarqube/data"
From bf98814903b3c5759da6380404558a456e0a267c Mon Sep 17 00:00:00 2001
From: Aghiles Azzoug
Date: Mon, 8 May 2023 11:13:23 +0200
Subject: [PATCH 037/170] docs: update RULES.md file with rule EC404
---
RULES.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/RULES.md b/RULES.md
index 7ef76d27a..e157e9aa0 100644
--- a/RULES.md
+++ b/RULES.md
@@ -47,3 +47,4 @@ Some are applicable for different technologies.
| EC28 | Optimize read file exceptions | | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 |
| 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. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 |
| EC27 | Usage of system.arraycopy to copy arrays | Programs spend most of the time in loops. These can be resource consuming, especially when they integrate heavy processing (IO access). Moreover, the size of the data and processing inside the loops will not allow full use of hardware mechanisms such as the cache or compiler optimization mechanisms. | | ✅ | 🚫 | 🚫 | 🚫 | 🚫 |
+| EC404 | Avoid list comprehension in iterations | Use generator comprehension instead of list comprehension in for loop declaration | | 🚫 | 🚫 | 🚫 | ✅ | 🚫 |
From e6b1b8c451ecba198d114bf462d6da7e80af1dc5 Mon Sep 17 00:00:00 2001
From: Aghiles Azzoug
Date: Mon, 8 May 2023 11:14:35 +0200
Subject: [PATCH 038/170] refactor: update rule EC404 (code factorization +
code smells correction)
---
.../AvoidListComprehensionInIterations.java | 41 ++++++++++---------
1 file changed, 22 insertions(+), 19 deletions(-)
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
index dec37acaa..b95cd01e1 100644
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
+++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
@@ -4,11 +4,16 @@
import org.sonar.check.Rule;
import org.sonar.plugins.python.api.PythonSubscriptionCheck;
import org.sonar.plugins.python.api.SubscriptionContext;
-import org.sonar.plugins.python.api.tree.*;
+import org.sonar.plugins.python.api.tree.Tree;
+import org.sonar.plugins.python.api.tree.ForStatement;
+import org.sonar.plugins.python.api.tree.Expression;
+import org.sonar.plugins.python.api.tree.CallExpression;
import java.util.Objects;
-import static org.sonar.plugins.python.api.tree.Tree.Kind.*;
+import static org.sonar.plugins.python.api.tree.Tree.Kind.LIST_COMPREHENSION;
+import static org.sonar.plugins.python.api.tree.Tree.Kind.CALL_EXPR;
+import static org.sonar.plugins.python.api.tree.Tree.Kind.FOR_STMT;
@Rule(
key = AvoidListComprehensionInIterations.RULE_KEY,
@@ -37,33 +42,31 @@ private void visitIteration(SubscriptionContext context) {
} else if (forTestExpression.is(CALL_EXPR)) {
CallExpression callExpression = (CallExpression) forTestExpression;
- switch (callExpression.callee().firstToken().value()) {
- case "zip":
- case "filter":
- case "enumerate":
- Objects.requireNonNull(callExpression.argumentList()).
- arguments().forEach(e -> visitFunctionArguments(context, e.children().get(0)));
- }
+ visitCallExpression(context, callExpression);
}
}
- private void visitFunctionArguments(SubscriptionContext context, Tree argument) {
+ private void visitFunctionArgument(SubscriptionContext context, Tree argument) {
if (argument.is(LIST_COMPREHENSION)) {
context.addIssue(argument.firstToken(), DESCRIPTION);
} else if (argument.is(CALL_EXPR)) {
CallExpression callExpression = (CallExpression) argument;
- switch (callExpression.callee().firstToken().value()) {
- case "zip":
- case "filter":
- case "enumerate":
- Objects.requireNonNull(callExpression.argumentList()).
- arguments().forEach(e -> visitFunctionArguments(context, e.children().get(0)));
- break;
-
- }
+ visitCallExpression(context, callExpression);
}
+ }
+ private void visitCallExpression(SubscriptionContext context, CallExpression callExpression){
+ switch (callExpression.callee().firstToken().value()) {
+ case "zip":
+ case "filter":
+ case "enumerate":
+ Objects.requireNonNull(callExpression.argumentList()).
+ arguments().forEach(e -> visitFunctionArgument(context, e.children().get(0)));
+ break;
+ default:
+ break;
+ }
}
}
From e5306f609f94607919ea72661e081973531f65d0 Mon Sep 17 00:00:00 2001
From: Aghiles Azzoug
Date: Mon, 8 May 2023 11:27:36 +0200
Subject: [PATCH 039/170] docs: update CHANGELOG.md
---
CHANGELOG.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3b36e9b06..68d369758 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
+- [#127](https://github.com/green-code-initiative/ecoCode/issues/127) Add Python rule EC404: Usage of generator comprehension instead of list comprehension in for loop declaration.
+
### Changed
### Deleted
From a1d203889953069769da7001b196084c0bae4d5a Mon Sep 17 00:00:00 2001
From: Aghiles Azzoug
Date: Mon, 8 May 2023 11:40:28 +0200
Subject: [PATCH 040/170] refactor: better check for function arguments, and
better retrieving of function name
---
.../AvoidListComprehensionInIterations.java | 41 ++++++++++++-------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
index b95cd01e1..e22d73d4a 100644
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
+++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
@@ -4,16 +4,19 @@
import org.sonar.check.Rule;
import org.sonar.plugins.python.api.PythonSubscriptionCheck;
import org.sonar.plugins.python.api.SubscriptionContext;
-import org.sonar.plugins.python.api.tree.Tree;
-import org.sonar.plugins.python.api.tree.ForStatement;
+import org.sonar.plugins.python.api.symbols.Symbol;
import org.sonar.plugins.python.api.tree.Expression;
import org.sonar.plugins.python.api.tree.CallExpression;
+import org.sonar.plugins.python.api.tree.ForStatement;
+import org.sonar.plugins.python.api.tree.Tree;
+import org.sonar.plugins.python.api.tree.RegularArgument;
import java.util.Objects;
-import static org.sonar.plugins.python.api.tree.Tree.Kind.LIST_COMPREHENSION;
import static org.sonar.plugins.python.api.tree.Tree.Kind.CALL_EXPR;
import static org.sonar.plugins.python.api.tree.Tree.Kind.FOR_STMT;
+import static org.sonar.plugins.python.api.tree.Tree.Kind.LIST_COMPREHENSION;
+import static org.sonar.plugins.python.api.tree.Tree.Kind.REGULAR_ARGUMENT;
@Rule(
key = AvoidListComprehensionInIterations.RULE_KEY,
@@ -46,27 +49,35 @@ private void visitIteration(SubscriptionContext context) {
}
}
- private void visitFunctionArgument(SubscriptionContext context, Tree argument) {
- if (argument.is(LIST_COMPREHENSION)) {
- context.addIssue(argument.firstToken(), DESCRIPTION);
-
- } else if (argument.is(CALL_EXPR)) {
- CallExpression callExpression = (CallExpression) argument;
- visitCallExpression(context, callExpression);
- }
- }
-
private void visitCallExpression(SubscriptionContext context, CallExpression callExpression){
- switch (callExpression.callee().firstToken().value()) {
+ switch (getFunctionNameFromCallExpression(callExpression)) {
case "zip":
case "filter":
case "enumerate":
Objects.requireNonNull(callExpression.argumentList()).
- arguments().forEach(e -> visitFunctionArgument(context, e.children().get(0)));
+ arguments().forEach(e -> visitFunctionArgument(context, e));
break;
default:
break;
}
}
+ private void visitFunctionArgument(SubscriptionContext context, Tree argument) {
+ if (argument.is(REGULAR_ARGUMENT)) {
+ Expression expression = ((RegularArgument)argument).expression();
+ if (expression.is(LIST_COMPREHENSION)) {
+ context.addIssue(expression.firstToken(), DESCRIPTION);
+
+ } else if (expression.is(CALL_EXPR)) {
+ CallExpression callExpression = (CallExpression) expression;
+ visitCallExpression(context, callExpression);
+ }
+ }
+ }
+
+ private static String getFunctionNameFromCallExpression(CallExpression callExpression) {
+ Symbol symbol = callExpression.calleeSymbol();
+ return symbol != null && symbol.name() != null ? symbol.name() : "";
+ }
+
}
From 5146a9f1b3b134ebaa38bc67ac2a92f95feb167b Mon Sep 17 00:00:00 2001
From: Aghiles Azzoug
Date: Mon, 8 May 2023 23:29:54 +0200
Subject: [PATCH 041/170] refactor: remove useless linebreaks
---
.../python/checks/AvoidListComprehensionInIterations.java | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
index e22d73d4a..8ff881836 100644
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
+++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidListComprehensionInIterations.java
@@ -32,7 +32,6 @@ public class AvoidListComprehensionInIterations extends PythonSubscriptionCheck
@Override
public void initialize(Context context) {
context.registerSyntaxNodeConsumer(FOR_STMT, this::visitIteration);
-
}
private void visitIteration(SubscriptionContext context) {
@@ -40,9 +39,7 @@ private void visitIteration(SubscriptionContext context) {
Expression forTestExpression = forStatement.testExpressions().get(0);
if (forTestExpression.is(LIST_COMPREHENSION)) {
-
context.addIssue(forTestExpression.firstToken(), DESCRIPTION);
-
} else if (forTestExpression.is(CALL_EXPR)) {
CallExpression callExpression = (CallExpression) forTestExpression;
visitCallExpression(context, callExpression);
@@ -67,7 +64,6 @@ private void visitFunctionArgument(SubscriptionContext context, Tree argument) {
Expression expression = ((RegularArgument)argument).expression();
if (expression.is(LIST_COMPREHENSION)) {
context.addIssue(expression.firstToken(), DESCRIPTION);
-
} else if (expression.is(CALL_EXPR)) {
CallExpression callExpression = (CallExpression) expression;
visitCallExpression(context, callExpression);
@@ -75,9 +71,8 @@ private void visitFunctionArgument(SubscriptionContext context, Tree argument) {
}
}
- private static String getFunctionNameFromCallExpression(CallExpression callExpression) {
+ private String getFunctionNameFromCallExpression(CallExpression callExpression) {
Symbol symbol = callExpression.calleeSymbol();
return symbol != null && symbol.name() != null ? symbol.name() : "";
}
-
}
From 7513076522101458be7dc3c2e5b31bcd2a06ca6f Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Wed, 10 May 2023 08:27:49 +0200
Subject: [PATCH 042/170] upgrade README.md with last data
---
README.md | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index eff1fbc1b..5ebecab8c 100644
--- a/README.md
+++ b/README.md
@@ -94,6 +94,7 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code-
| 0.2.+ | 11 / 17 |
| 1.0.+ | 11 / 17 |
| 1.1.+ | 11 / 17 |
+| 1.2.+ | 11 / 17 |
🤝 Contribution
---------------
@@ -117,13 +118,13 @@ Any question ? We are here for you !
first, create an issue, please.
Then, if no answer, contact ...
-- Jules Delecour
+- [Jules Delecour](https://www.linkedin.com/in/jules-delecour-498680118/)
- [Geoffrey Lalloué](https://github.com/glalloue)
-- Julien Hertout
+- [Julien Hertout](https://www.linkedin.com/in/julien-hertout-b1175449/)
- [Justin Berque](https://www.linkedin.com/in/justin-berque-444412140)
- [Olivier Le Goaër](https://olegoaer.perso.univ-pau.fr)
-- Maxime DUBOIS
-- [David DE CARVALHO](https://www.linkedin.com/in/%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-david%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-de-carvalho%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-%E2%80%8E-8b395284/)
+- [Maxime DUBOIS](https://www.linkedin.com/in/maxime-dubois-%F0%9F%8C%B1-649a3a3/)
+- [David DE CARVALHO](https://www.linkedin.com/in/david%E2%80%8E-de-carvalho-8b395284/)
🧐 Core Team Emeriti
--------------------
From f9c0e6224ddda842d8a50c4b8b6fb615208aa2ee Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Wed, 10 May 2023 08:28:49 +0200
Subject: [PATCH 043/170] upgrade to SonarQube 10.0.0 (manual checks)
---
Dockerfile | 2 +-
README.md | 13 +++++++------
docker-compose.yml | 2 +-
3 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/Dockerfile b/Dockerfile
index 0fd4e5340..bd5462ffb 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -5,5 +5,5 @@ COPY . /usr/src/ecocode
WORKDIR /usr/src/ecocode
RUN ./tool_build.sh
-FROM sonarqube:9.9-community
+FROM sonarqube:10.0.0-community
COPY --from=builder /usr/src/ecocode/lib/* /opt/sonarqube/extensions/plugins/
diff --git a/README.md b/README.md
index 5ebecab8c..c050991eb 100644
--- a/README.md
+++ b/README.md
@@ -78,12 +78,13 @@ Ready to use binaries are available [from GitHub](https://github.com/green-code-
🧩 Plugins version compatibility
------------------
-| Plugins Version | SonarQube version |
-|------------------|----------------------------|
-| 0.1.+ | SonarQube 8.9.+ LTS to 9.3 |
-| 0.2.+ | SonarQube 9.4.+ LTS to 9.9 |
-| 1.0.+ | SonarQube 9.4.+ LTS to 9.9 |
-| 1.1.+ | SonarQube 9.4.+ LTS to 9.9 |
+| Plugins Version | SonarQube version |
+|------------------|-----------------------------|
+| 0.1.+ | SonarQube 8.9.+ LTS to 9.3 |
+| 0.2.+ | SonarQube 9.4.+ LTS to 9.9 |
+| 1.0.+ | SonarQube 9.4.+ LTS to 9.9 |
+| 1.1.+ | SonarQube 9.4.+ LTS to 9.9 |
+| 1.2.+ | SonarQube 9.4.+ LTS to 10.0 |
☕ Plugin Java part compatibility
------------------
diff --git a/docker-compose.yml b/docker-compose.yml
index a6aca9888..32a7dc027 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,7 +1,7 @@
version: "3.3"
services:
sonar:
- image: sonarqube:9.9-community
+ image: sonarqube:10.0.0-community
container_name: sonar_ecocode
ports:
- "9000:9000"
From 8870c64b1e89a95f683a933d87fcd2ea8bfaa4d8 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Wed, 10 May 2023 16:46:13 +0200
Subject: [PATCH 044/170] [ISSUE 184] upgrade component versions / clean
pom.xml / upgrade code for SonarQube 10
---
java-plugin/pom.xml | 33 +----------
.../java/JavaRulesDefinition.java | 2 +-
.../java/JavaPluginTest.java | 2 +-
javascript-plugin/pom.xml | 30 ++--------
.../javascript/JavaScriptPluginTest.java | 2 +-
php-plugin/pom.xml | 35 -----------
.../php/PhpPluginTest.java | 2 +-
pom.xml | 59 +++++++++++++++----
python-plugin/pom.xml | 35 -----------
.../python/PythonPluginTest.java | 2 +-
10 files changed, 60 insertions(+), 142 deletions(-)
diff --git a/java-plugin/pom.xml b/java-plugin/pom.xml
index acb1b601c..773c3a0bd 100644
--- a/java-plugin/pom.xml
+++ b/java-plugin/pom.xml
@@ -87,40 +87,9 @@
+
org.apache.maven.pluginsmaven-shade-plugin
-
-
- package
-
- shade
-
-
-
-
- commons-*:*
-
- META-INF/**
-
-
-
- org.*:*
-
- META-INF/**
- org/sonar/api/batch/sensor/**
- javax/annotation/**
-
-
-
- com.*:*
-
- META-INF/**
-
-
-
-
-
- org.jacoco
diff --git a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java
index 9b6d698d5..37a82c438 100644
--- a/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java
+++ b/java-plugin/src/main/java/fr/greencodeinitiative/java/JavaRulesDefinition.java
@@ -52,7 +52,7 @@ public class JavaRulesDefinition implements RulesDefinition {
public void define(Context context) {
NewRepository repository = context.createRepository(REPOSITORY_KEY, LANGUAGE).setName(NAME);
- SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(9, 8), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER);
+ SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(10, 0), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER);
RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, sonarRuntime);
diff --git a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java
index 53eaad42e..649268421 100644
--- a/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java
+++ b/java-plugin/src/test/java/fr/greencodeinitiative/java/JavaPluginTest.java
@@ -43,7 +43,7 @@ private static class MockedSonarRuntime implements SonarRuntime {
@Override
public Version getApiVersion() {
- return Version.create(9, 9);
+ return Version.create(10, 0);
}
@Override
diff --git a/javascript-plugin/pom.xml b/javascript-plugin/pom.xml
index 3349c963f..ebf069c23 100644
--- a/javascript-plugin/pom.xml
+++ b/javascript-plugin/pom.xml
@@ -68,33 +68,13 @@
+
org.apache.maven.pluginsmaven-shade-plugin
-
-
- package
-
- shade
-
-
-
-
- commons-*:*
-
- META-INF/**
-
-
-
- org.*:*
-
- META-INF/**
- org/sonar/api/batch/sensor/**
-
-
-
-
-
-
+
org.apache.maven.plugins
diff --git a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java b/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java
index ad50f25ec..3f8ed8f3f 100644
--- a/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java
+++ b/javascript-plugin/src/test/java/fr/greencodeinitiative/javascript/JavaScriptPluginTest.java
@@ -19,7 +19,7 @@ private static class MockedSonarRuntime implements SonarRuntime {
@Override
public Version getApiVersion() {
- return Version.create(9, 9);
+ return Version.create(10, 0);
}
@Override
diff --git a/php-plugin/pom.xml b/php-plugin/pom.xml
index 0910c07b5..3ee2639c8 100644
--- a/php-plugin/pom.xml
+++ b/php-plugin/pom.xml
@@ -64,41 +64,6 @@
${java.version}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
org.apache.maven.pluginsmaven-dependency-plugin
diff --git a/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpPluginTest.java b/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpPluginTest.java
index 3c89dab5a..b64679cbb 100644
--- a/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpPluginTest.java
+++ b/php-plugin/src/test/java/fr/greencodeinitiative/php/PhpPluginTest.java
@@ -32,7 +32,7 @@
public class PhpPluginTest {
@Test
public void test() {
- SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(9, 9), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER);
+ SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(10, 0), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER);
Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(sonarRuntime).build();
new PHPPlugin().define(context);
assertThat(context.getExtensions()).hasSize(1);
diff --git a/pom.xml b/pom.xml
index 4f15d9b78..0ec29ab22 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,24 +50,24 @@
${encoding}${encoding}
- 9.4.0.54424
-
green-code-initiativehttps://sonarcloud.io
-
- 0.8.8
+ 9.4.0.54424
+ 10.0.0.68432
- 7.15.0.30507
- 3.19.0.10254
- 3.25.0.9077
- 9.13.0.20537
+ 7.19.0.31550
+ 4.3.0.11660
+ 3.29.0.9684
+ 10.2.0.21568
+
+ 2.5.0.1358
- 9.7.1.62043
- 2.1.0.11111.21.0.505true3.4.1
+
+ 0.8.105.9.13.23.1
@@ -195,6 +195,45 @@
org.apache.maven.pluginsmaven-shade-plugin${maven-shade-plugin.version}
+
+
+
+ package
+
+ shade
+
+
+
+
+ commons-*:*
+
+ META-INF/**
+
+
+
+ org.*:*
+
+ META-INF/**
+ org/sonar/api/batch/sensor/**
+ javax/annotation/**
+
+
+
+ com.*:*
+
+ META-INF/**
+
+
+
+ junit:*
+
+ META-INF/**
+
+
+
+
+
+ org.jacoco
diff --git a/python-plugin/pom.xml b/python-plugin/pom.xml
index 1a239fa51..e16bdca63 100644
--- a/python-plugin/pom.xml
+++ b/python-plugin/pom.xml
@@ -61,41 +61,6 @@
${java.version}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
org.apache.maven.pluginsmaven-dependency-plugin
diff --git a/python-plugin/src/test/java/fr/greencodeinitiative/python/PythonPluginTest.java b/python-plugin/src/test/java/fr/greencodeinitiative/python/PythonPluginTest.java
index 03c88941b..a5ad52390 100644
--- a/python-plugin/src/test/java/fr/greencodeinitiative/python/PythonPluginTest.java
+++ b/python-plugin/src/test/java/fr/greencodeinitiative/python/PythonPluginTest.java
@@ -32,7 +32,7 @@
public class PythonPluginTest {
@Test
public void test() {
- SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(9, 9), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER);
+ SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(10, 0), SonarQubeSide.SCANNER, SonarEdition.DEVELOPER);
Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(sonarRuntime).build();
new PythonPlugin().define(context);
assertThat(context.getExtensions()).hasSize(1);
From 34e03424009ea0643d9a66c2ef1242575838b512 Mon Sep 17 00:00:00 2001
From: utarwyn
Date: Sun, 14 May 2023 19:17:04 +0200
Subject: [PATCH 045/170] Update JavaScript rules
---
.../l10n/javascript/rules.json | 24 +++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json b/javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json
index 5beda43e8..e86627bb5 100644
--- a/javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json
+++ b/javascript-plugin/src/main/resources/fr/greencodeinitiative/l10n/javascript/rules.json
@@ -1,4 +1,28 @@
[
+ {
+ "key": "@ecocode/avoid-high-accuracy-geolocation",
+ "type": "CODE_SMELL",
+ "name": "Avoid using high accuracy geolocation in web applications",
+ "description": "\n\n
Rule details
\n
This rule aims at reducing CPU consumption by telling the device to use a less accurate yet more eco friendly geolocation, when geolocation API is used.
// enableHighAccuracy is false by default, so not declaring it is correct\nfunction success(pos) {\n console.log(pos);\n}\nnavigator.geolocation.getCurrentPosition(success);\n
\n Click here to access the rule details.",
+ "constantDebtMinutes": 5,
+ "severity": "MINOR",
+ "tags": [
+ "eco-design",
+ "ecocode"
+ ]
+ },
+ {
+ "key": "@ecocode/no-import-all-from-library",
+ "type": "CODE_SMELL",
+ "name": "Should not import all from librar",
+ "description": "\n\n
Rule details
\n
This rule aims to reduce weight of programs by using only needed modules. Many libraries export only one module by\ndefault, but some of them are exporting ES modules or submodules. We should use them to select more precisly needed\nmodules and avoid unnecessarily overloading files weight.
\n\n
Example with the well-known lodash library, if you only need "isEmpty" method.
\n
Options
\n
You can externally add your own libraries to be checked.\nTo add your own libraries you need to modify your .eslintrc.js by adding the following rule configuration:
\n
module.exports = {\n ...yourConf,\n rules: {\n "no-import-all-from-library": [\n "warn",\n {\n notAllowedLibraries: ["some-lib"], // will check for -> import someLib from "some-lib"\n importByNamespaceNotAllowedLibraries: ["some-other-lib"], // will check for -> import * as someOtherLib from "some-other-lib"\n },\n ],\n },\n};\n
\n
Examples
\n
Examples of non-compliant code for this rule:
\n
// Example with lodash\nimport lodash from "lodash";\nimport { isEmpty } from "lodash";\nimport * as lodash from "lodash";\n\n// Example with underscore\nimport _ from "underscore";\n
\n
Examples of compliant code for this rule:
\n
// Example with lodash (uses submodules)\nimport isEmpty from "lodash/isEmpty";\nimport intersect from "lodash/intersect";\n\n// Example with underscore (uses esm modules)\nimport map from "underscore/modules/map.js";\n
\n Click here to access the rule details.",
+ "constantDebtMinutes": 5,
+ "severity": "MINOR",
+ "tags": [
+ "eco-design",
+ "ecocode"
+ ]
+ },
{
"key": "@ecocode/no-multiple-access-dom-element",
"type": "CODE_SMELL",
From 5fcf195815e2f9ca86d5e23e9e91775a75552466 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Tue, 16 May 2023 22:01:53 +0200
Subject: [PATCH 046/170] update CHANGELOG.md
---
CHANGELOG.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3b36e9b06..0bcca3e0a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
+- process changed for development environment installation : easier to initialize locally environment (check (`INSTALL.md`)[https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#howto-install-sonarqube-dev-environment] file)
+
### Deleted
## [1.2.1] - 2023-04-18
From bee566394fc58a32e9ca1aac01dd4c19c352219a Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Tue, 16 May 2023 22:02:56 +0200
Subject: [PATCH 047/170] correction link in CHANGELOG.md
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0bcca3e0a..89bd3cba4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
-- process changed for development environment installation : easier to initialize locally environment (check (`INSTALL.md`)[https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#howto-install-sonarqube-dev-environment] file)
+- process changed for development environment installation : easier to initialize locally environment (check [`INSTALL.md`](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#howto-install-sonarqube-dev-environment) file)
### Deleted
From 08ae84c75a32158368df19472a4cc75d60ce98f4 Mon Sep 17 00:00:00 2001
From: David DE CARVALHO
Date: Tue, 16 May 2023 22:04:12 +0200
Subject: [PATCH 048/170] improive CHANGELOG.md
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 89bd3cba4..1dcc6b5fc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
-- process changed for development environment installation : easier to initialize locally environment (check [`INSTALL.md`](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#howto-install-sonarqube-dev-environment) file)
+- [#19](https://github.com/green-code-initiative/ecoCode-common/issues/19) process changed for development environment installation : easier to initialize locally environment (check [`INSTALL.md`](https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/INSTALL.md#howto-install-sonarqube-dev-environment) file)
### Deleted
From cc7e34c2cad0b2e070cc76b0e6731169c74b6464 Mon Sep 17 00:00:00 2001
From: Aghiles Azzoug
Date: Tue, 16 May 2023 22:36:04 +0200
Subject: [PATCH 049/170] refactor: remove duplicated test in
AvoidListComprehensionInIterations python file
---
.../resources/checks/AvoidListComprehensionInIterations.py | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/python-plugin/src/test/resources/checks/AvoidListComprehensionInIterations.py b/python-plugin/src/test/resources/checks/AvoidListComprehensionInIterations.py
index 9dab94c8b..547eb5724 100644
--- a/python-plugin/src/test/resources/checks/AvoidListComprehensionInIterations.py
+++ b/python-plugin/src/test/resources/checks/AvoidListComprehensionInIterations.py
@@ -10,10 +10,6 @@ def non_compliant_example_zip():
for var, var_ in zip([var2 for var2 in range(1000)], [var2 for var2 in range(1000)]): # Noncompliant {{Use generator comprehension instead of list comprehension in for loop declaration}} {{Use generator comprehension instead of list comprehension in for loop declaration}}
print(var)
-def non_compliant_example_zip():
- for var, var_ in zip([var2 for var2 in range(1000)], [var2 for var2 in range(1000)]): # Noncompliant {{Use generator comprehension instead of list comprehension in for loop declaration}} {{Use generator comprehension instead of list comprehension in for loop declaration}}
- print(var)
-
def non_compliant_example_enumerate_zip():
for packed_var in enumerate(zip([1, 2, 3], filter(bool, [idx % 2 for idx in range(100)]))): # Noncompliant {{Use generator comprehension instead of list comprehension in for loop declaration}}
print(packed_var)
@@ -36,4 +32,4 @@ def compliant_example_with_enumerate():
def compliant_example_with_zip():
for var, var2 in zip((idx for idx in range(3)), ["a", "b", "c"]):
- print(var)
\ No newline at end of file
+ print(var)
From 7f050a2ee0700f662b6731bc09802e6f4f30221b Mon Sep 17 00:00:00 2001
From: Eliott Lavier <67601109+eliottlv@users.noreply.github.com>
Date: Thu, 6 Apr 2023 09:59:30 +0200
Subject: [PATCH 050/170] [ISSUE 113] Use unoptimized vector images
---
.../python/PythonRuleRepository.java | 8 +--
.../AvoidUnoptimizedVectorImagesCheck.java | 66 +++++++++++++++++++
.../l10n/python/rules/python/EC10.html | 47 +++++++++++++
.../python/PythonRuleRepositoryTest.java | 4 +-
.../AvoidUnoptimizedVectorImagesTest.java | 12 ++++
.../checks/avoidUnoptimizedVectorImages.py | 5 ++
6 files changed, 134 insertions(+), 8 deletions(-)
create mode 100644 python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidUnoptimizedVectorImagesCheck.java
create mode 100644 python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC10.html
create mode 100644 python-plugin/src/test/java/fr/greencodeinitiative/python/checks/AvoidUnoptimizedVectorImagesTest.java
create mode 100644 python-plugin/src/test/resources/checks/avoidUnoptimizedVectorImages.py
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java
index 93de44ffb..726ded00e 100644
--- a/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java
+++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/PythonRuleRepository.java
@@ -29,12 +29,7 @@
import java.util.List;
import java.util.Map;
-import fr.greencodeinitiative.python.checks.AvoidFullSQLRequest;
-import fr.greencodeinitiative.python.checks.AvoidGettersAndSetters;
-import fr.greencodeinitiative.python.checks.AvoidGlobalVariableInFunctionCheck;
-import fr.greencodeinitiative.python.checks.AvoidSQLRequestInLoop;
-import fr.greencodeinitiative.python.checks.AvoidTryCatchFinallyCheck;
-import fr.greencodeinitiative.python.checks.NoFunctionCallWhenDeclaringForLoop;
+import fr.greencodeinitiative.python.checks.*;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.rule.RulesDefinition;
@@ -93,6 +88,7 @@ public List checkClasses() {
AvoidGlobalVariableInFunctionCheck.class,
AvoidSQLRequestInLoop.class,
AvoidTryCatchFinallyCheck.class,
+ AvoidUnoptimizedVectorImagesCheck.class,
NoFunctionCallWhenDeclaringForLoop.class,
AvoidFullSQLRequest.class
);
diff --git a/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidUnoptimizedVectorImagesCheck.java b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidUnoptimizedVectorImagesCheck.java
new file mode 100644
index 000000000..743e7ad71
--- /dev/null
+++ b/python-plugin/src/main/java/fr/greencodeinitiative/python/checks/AvoidUnoptimizedVectorImagesCheck.java
@@ -0,0 +1,66 @@
+package fr.greencodeinitiative.python.checks;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.sonar.check.Priority;
+import org.sonar.check.Rule;
+import org.sonar.plugins.python.api.PythonSubscriptionCheck;
+import org.sonar.plugins.python.api.SubscriptionContext;
+import org.sonar.plugins.python.api.tree.*;
+
+@Rule(
+ key = AvoidUnoptimizedVectorImagesCheck.RULE_KEY,
+ name = AvoidUnoptimizedVectorImagesCheck.DESCRIPTION,
+ description = AvoidUnoptimizedVectorImagesCheck.DESCRIPTION,
+ priority = Priority.MINOR,
+ tags = {"eco-design", "ecocode"})
+public class AvoidUnoptimizedVectorImagesCheck extends PythonSubscriptionCheck {
+
+ public static final String RULE_KEY = "EC10";
+ public static final String DESCRIPTION = "Avoid using unoptimized vector images";
+ private static final Pattern COMMENT_PATTERN = Pattern.compile("()");
+ private static final Pattern LAYERS_PATTERN = Pattern.compile("");
+ private static final Pattern NAMESPACE_PATTERN = Pattern.compile("xmlns:(?!svg)[a-z0-9]+");
+ private static final String STRING_TAG_TO_DETECT = "";
+
+ @Override
+ public void initialize(Context ctx) {
+ ctx.registerSyntaxNodeConsumer(Tree.Kind.STRING_ELEMENT, this::checkSVG);
+ }
+
+ public void checkSVG(SubscriptionContext ctx) {
+ StringElement stringLiteral = (StringElement) ctx.syntaxNode();
+ checkComments(stringLiteral, ctx);
+ checkLayers(stringLiteral, ctx);
+ checkNamespaces(stringLiteral, ctx);
+ checkMetadata(stringLiteral, ctx);
+ }
+
+ private void checkComments(StringElement str, SubscriptionContext ctx) {
+ if (str.value().contains(AvoidUnoptimizedVectorImagesCheck.STRING_TAG_TO_DETECT) && COMMENT_PATTERN.matcher(str.value()).find()) {
+ ctx.addIssue(str, DESCRIPTION);
+ }
+ }
+
+ private void checkLayers(StringElement str, SubscriptionContext ctx) {
+ Matcher matcher = LAYERS_PATTERN.matcher(str.value());
+ int matches = 0;
+ while (matcher.find()) matches++;
+ if (str.value().contains(AvoidUnoptimizedVectorImagesCheck.STRING_TAG_TO_DETECT) && matches > 1) {
+ ctx.addIssue(str, DESCRIPTION);
+ }
+ }
+
+ private void checkNamespaces(StringElement str, SubscriptionContext ctx) {
+ if (str.value().contains(AvoidUnoptimizedVectorImagesCheck.STRING_TAG_TO_DETECT) && NAMESPACE_PATTERN.matcher(str.value()).find()) {
+ ctx.addIssue(str, DESCRIPTION);
+ }
+ }
+
+ private void checkMetadata(StringElement str, SubscriptionContext ctx) {
+ if (str.value().contains(AvoidUnoptimizedVectorImagesCheck.STRING_TAG_TO_DETECT) && str.value().contains("")) {
+ ctx.addIssue(str, DESCRIPTION);
+ }
+ }
+}
diff --git a/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC10.html b/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC10.html
new file mode 100644
index 000000000..555e80b74
--- /dev/null
+++ b/python-plugin/src/main/resources/fr/greencodeinitiative/l10n/python/rules/python/EC10.html
@@ -0,0 +1,47 @@
+
SVG images generated by common drawing softwares contains unnecessary data : calc layer, metadata, namespaces and comments.