Skip to content

Commit

Permalink
sonar issues correction
Browse files Browse the repository at this point in the history
  • Loading branch information
dedece35 committed Oct 4, 2024
1 parent 679e4d2 commit 0794c91
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- refactoring docker system
- [#29](https://github.com/green-code-initiative/ecoCode-python/issues/29) Add test to ensure all Rules are registered
- [#24](https://github.com/green-code-initiative/ecoCode-python/issues/24) Set correct required language because the plugin wasn't loaded anymore => change of retro-compatibility (9.9.0 to 10.7 and not compatible before 9.9.0) AND add support for > 10.5 Sonarqube version (up to 10.7.0)
- update some maven plugin versions and librarie versions to be up-to-date
- [#24](https://github.com/green-code-initiative/ecoCode-python/issues/24) Set correct required language because the
plugin wasn't loaded anymore - retro-compatibility modifications (9.9.0 to 10.7 and not compatible before 9.9.0) AND
add support for > 10.5 Sonarqube version (up to 10.7.0)
- update some maven plugin versions and library versions to be up-to-date
- correction of SonarCloud issues

### Deleted

- delete EC69 rule because of deprecation (see RULES.md file)
- deletion of EC69 rule because of already deprecated (see RULES.md file)

## [1.4.4] - 2024-07-18

Expand All @@ -39,7 +42,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [#18](https://github.com/green-code-initiative/ecoCode-python/issues/18) Add support for SonarQube 10.4 "DownloadOnlyWhenRequired" feature
- [#18](https://github.com/green-code-initiative/ecoCode-python/issues/18) Add support for SonarQube 10.4 "
DownloadOnlyWhenRequired" feature
- Add Support for SonarQube 10.4.1

### Changed
Expand All @@ -66,7 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#5](https://github.com/green-code-initiative/ecoCode-python/pull/5) Upgrade licence system and licence headers of
Java files
- [#6](https://github.com/green-code-initiative/ecoCode-python/pull/6) Adding EC35 rule : EC35 rule replaces EC34 with a
specific use case ("file not found" sepcific)
specific use case ("file not found" specific)
- [#7](https://github.com/green-code-initiative/ecoCode-python/issues/7) Add build number to manifest
- [#123](https://github.com/green-code-initiative/ecoCode/issues/123) Improve unit tests for EC7 rule
- Update ecocode-rules-specifications to 1.4.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import java.util.Arrays;
import java.util.List;


public class PythonRuleRepository implements RulesDefinition, PythonCustomRuleRepository {

@SuppressWarnings("rawtypes") // not possible to make a correction because super class is like that
static final List<Class> ANNOTATED_RULE_CLASSES = Arrays.asList(
AvoidGettersAndSetters.class,
AvoidGlobalVariableInFunctionCheck.class,
Expand Down Expand Up @@ -65,6 +67,7 @@ public String repositoryKey() {
return REPOSITORY_KEY;
}

@SuppressWarnings("rawtypes") // not possible to make a correction because super class is like that
@Override
public List<Class> checkClasses() {
return ANNOTATED_RULE_CLASSES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
package fr.greencodeinitiative.python.checks;


import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

import org.sonar.check.Rule;
import org.sonar.plugins.python.api.PythonSubscriptionCheck;
import org.sonar.plugins.python.api.SubscriptionContext;
Expand All @@ -32,14 +26,18 @@
import org.sonar.plugins.python.api.tree.Tree;
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

@Rule(key = "EC74")
@DeprecatedRuleKey(repositoryKey = "gci-python", ruleKey = "S74")
public class AvoidFullSQLRequest extends PythonSubscriptionCheck {

protected static final String MESSAGERULE = "Don't use the query SELECT * FROM";
protected static final String MESSAGE_RULE = "Don't use the query SELECT * FROM";

// TODO DDC : create support to add in deployment th dependency com.google.re2j:re2j
// and replace "import java.util.regex.Pattern" by "import com.google.re2j.Pattern"
private static final Pattern PATTERN = Pattern.compile("(?i).*select.*\\*.*from.*");
private static final Map<String, Collection<Integer>> linesWithIssuesByFile = new HashMap<>();

Expand Down Expand Up @@ -68,7 +66,7 @@ private void repport(StringElement stringElement, SubscriptionContext ctx) {
linesWithIssuesByFile.computeIfAbsent(classname, k -> new ArrayList<>());
linesWithIssuesByFile.get(classname).add(line);
}
ctx.addIssue(stringElement, MESSAGERULE);
ctx.addIssue(stringElement, MESSAGE_RULE);
}

private boolean lineAlreadyHasThisIssue(StringElement stringElement, SubscriptionContext ctx) {
Expand Down

0 comments on commit 0794c91

Please sign in to comment.