From cd0e44282f6c168dbb02304d976c5ebf64951c48 Mon Sep 17 00:00:00 2001 From: utarwyn Date: Thu, 5 Oct 2023 19:32:28 +0200 Subject: [PATCH 1/2] Use Java 17 for the SonarQube scan --- .github/workflows/build.yml | 40 ++++++++++++++++++++++++++----------- sonar-project.properties | 20 ------------------- 2 files changed, 28 insertions(+), 32 deletions(-) delete mode 100644 sonar-project.properties diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 96fd532cd..ae547eab0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,5 @@ name: Build and Tests + on: push: branches: @@ -9,7 +10,8 @@ on: tags: - '[0-9]+.[0-9]+.[0-9]+' pull_request: - types: [opened, synchronize, reopened] + types: [ opened, synchronize, reopened ] + jobs: build: name: Build @@ -18,27 +20,41 @@ jobs: pull-requests: read # allows SonarCloud to decorate PRs with analysis results steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 11 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'temurin' java-version: 11 - - name: Cache SonarCloud packages - uses: actions/cache@v1 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar + - name: Cache Maven packages - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - - name: Build and analyze + + - name: Verify + run: mvn -e -B verify + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 17 + + - name: Cache SonarQube packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: SonarQube Scan env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: mvn -e -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_ecoCode -Dsonar.exclusions=**/*.groovy,**/*.dummy + run: mvn -e -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=green-code-initiative_ecoCode diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index a8b72a766..000000000 --- a/sonar-project.properties +++ /dev/null @@ -1,20 +0,0 @@ -# must be unique in a given SonarQube instance -sonar.projectKey=sonar-custom-plugin-example - -# --- optional properties --- - -# defaults to project key -#sonar.projectName=My project -# defaults to 'not provided' -#sonar.projectVersion=1.0 - -# Path is relative to the sonar-project.properties file. Defaults to . -#sonar.sources=. - -# Encoding of the source code. Default is default system encoding -#sonar.sourceEncoding=UTF-8 - -sonar.eslint.reportPaths=/opt/project/eslint-report.json -sonar.css.stylelint.reportPaths=/opt/project/stylelint-report.json -sonar.java.binaries=/opt/project/java-plugin/target/classes -sonar.scm.disabled=true \ No newline at end of file From e59aa05e57f32e3862fb5ad2092a17cbb2a5b8ff Mon Sep 17 00:00:00 2001 From: David DE CARVALHO Date: Fri, 6 Oct 2023 21:28:01 +0200 Subject: [PATCH 2/2] Add new issue template to suggest new rule --- .github/ISSUE_TEMPLATE/new_rule_suggestion.md | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/new_rule_suggestion.md diff --git a/.github/ISSUE_TEMPLATE/new_rule_suggestion.md b/.github/ISSUE_TEMPLATE/new_rule_suggestion.md new file mode 100644 index 000000000..e1c6b4374 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/new_rule_suggestion.md @@ -0,0 +1,118 @@ +--- +name: New rule suggestion +about: Suggest an new rule idea for this project +title: '' +labels: 'rule' +assignees: '' + +--- + +# {Category: RuleTitle (Variant)} + +## Platform + +| OS | OS version | Langage | +|---------------|--------------|------------| +| {Android/IOS} | {OS version} | {Language} | + +## Main caracteristics + +| ID | Title | Category | Sub-category | +|----------|----------------------|-------------|----------------| +| {id} | {title} | {Category} | {SubCategory} | + +## Severity / Remediation Cost + +- **Case 1**: + | Severity | Remediation Cost | + |------------|---------------------| + | {Severity} | {Remediation_Cost} | +- **Case 2**: + | Severity | Remediation Cost | + |------------|---------------------| + | {Severity} | {Remediation_Cost} | + +## Rule short description + +- **Case 1**: {short description} +- **Case 2**: {short description} + +## Rule complete description + +## Text + +{big description} + +## HTML + + ```html +{html code} +``` + +## Implementation principle + +- {Implementation principe} +- {Implementation principe} + 17 h 17 + voici le template + 17 h 17 + et voici un example : + 17 h 17 + +# Optimized API: List Shallow Copy - Module copy + +## Platform + +| OS | OS version | Langage | +|----------|------------|-----------| +| - | - | Python | + +## Main caracteristics + +| ID | Title | Category | Sub-category | +|---------|----------------------------------|-------------|----------------| +| EOPT001 | List Shallow Copy - Module copy | Environment | Optimized API | + +## Severity / Remediation Cost + +| Severity | Remediation Cost | +|----------|------------------| +| Minor | Minor | + +## Rule short description + +Using `copy.copy(x)` of `module copy` to perform a shallow copy of a list is not energy efficient. + +## Rule complete description + +### Text + +Using `copy.copy(x)` of `module copy` to perform a shallow copy of a list is not energy efficient. +Prefer the usage of `list.copy()` which is more energy friendly. + +### HTML + + ```html +

Using copy.copy(x) of module copy to perform a shallow +copy of a list is not energy efficient.

+

Prefer the usage of list.copy() which is more energy friendly.

+

Noncompliant Code Example

+
+import copy
+ my_list = [1, 2, [3, 4], 5]
+list_copy = copy.copy(my_list)
+
+

Compliant Solution

+
+my_list = [1, 2, [3, 4], 5]
+list_copy = my_list.copy()
+
+``` + +## Implementation principle + +- Inspect the import node to find `copy` import +- Inspect the ARG_LIST node +- If the direct parent is CALL_EXPR tree and the function is `copy.copy()` +- If the function is present, check the first argument +- If it is a list, report the line \ No newline at end of file