Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into bugfix/EC63_Unnecessa…
Browse files Browse the repository at this point in the history
…rilyAssignValuesToVariables_rule_on_caught_exception

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
natixis-caen committed Nov 7, 2023
2 parents bce05cf + 20035d7 commit c3dd1ef
Show file tree
Hide file tree
Showing 131 changed files with 2,509 additions and 250 deletions.
118 changes: 118 additions & 0 deletions .github/ISSUE_TEMPLATE/new_rule_suggestion.md
Original file line number Diff line number Diff line change
@@ -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
<p>Using <code>copy.copy(x)</code> of <code>module copy</code> to perform a shallow
copy of a list is not energy efficient.</p>
<p>Prefer the usage of <code>list.copy()</code> which is more energy friendly.</p>
<h2>Noncompliant Code Example</h2>
<pre>
import copy
my_list = [1, 2, [3, 4], 5]
list_copy = copy.copy(my_list)
</pre>
<h2>Compliant Solution</h2>
<pre>
my_list = [1, 2, [3, 4], 5]
list_copy = my_list.copy()
</pre>
```

## 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
40 changes: 28 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Build and Tests

on:
push:
branches:
Expand All @@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- [ios#3](https://github.com/green-code-initiative/ecoCode-ios/issues/3) Move iOS rules into centralized rules repository
- [android#67](https://github.com/green-code-initiative/ecoCode-android/issues/67) Move Android rules into centralized rules repository
- [#216](https://github.com/green-code-initiative/ecoCode/issues/216) Upgrade rule EC2 for Java : Multiple if-else statement improvment
- [#106](https://github.com/green-code-initiative/ecoCode/issues/106) Upgrade RULES.md : rule EC67 not relevant neither for Python nor Rust
- [#225](https://github.com/green-code-initiative/ecoCode/pull/225) Upgrade licence system and licence headers of Java files
- [#140](https://github.com/green-code-initiative/ecoCode/issues/140) Upgrade rule EC3 for Python : no implementation possible for python
- [#136](https://github.com/green-code-initiative/ecoCode/issues/136) Upgrade rule EC53 for Python : no implementation possible for python
- [#128](https://github.com/green-code-initiative/ecoCode/pull/128) Adding EC35 rule for Python and PHP : EC35 rule replaces EC34 with a specific use case ("file not found" sepcific)
- [#228](https://github.com/green-code-initiative/ecoCode/issues/228) Upgrade rule EC63 for java: Stop reporting caught exception even if unused

### Deleted
Expand Down
Loading

0 comments on commit c3dd1ef

Please sign in to comment.