From 8d2d799e6a375557879ccbbd0efef9148b929685 Mon Sep 17 00:00:00 2001
From: Julien Hertout
Date: Mon, 15 Jan 2024 14:27:02 +0100
Subject: [PATCH] Remove groovy rule EC5003 since it is not in the best
practices anymore.
---
CHANGELOG.md | 2 +
.../org/sonar/plugins/groovy/cost.csv | 1 -
.../sonar/plugins/groovy/profile-default.txt | 1 -
.../org/sonar/plugins/groovy/rules.xml | 40 ----
.../codenarc/CodeNarcRulesDefinitionTest.java | 2 +-
codenarc-converter/CodeNarc/CHANGELOG.md | 1 +
.../docs/StarterRuleSet-AllRules.groovy.txt | 1 -
.../docs/codenarc-rule-index-by-name.md | 1 -
.../CodeNarc/docs/codenarc-rule-index.md | 1 -
.../org/codenarc/rule/ecocode/EC5003.groovy | 60 -----
.../codenarc-base-messages.properties | 3 -
.../resources/codenarc-base-rules.properties | 1 -
.../src/main/resources/rulesets/ecocode.xml | 1 -
.../codenarc/rule/ecocode/EC5003Test.groovy | 217 ------------------
14 files changed, 4 insertions(+), 328 deletions(-)
delete mode 100644 codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/rule/ecocode/EC5003.groovy
delete mode 100644 codenarc-converter/CodeNarc/src/test/groovy/org/codenarc/rule/ecocode/EC5003Test.groovy
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5de4f8aa..9e2d8d91 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#80](https://github.com/green-code-initiative/ecoCode-android/issues/80) Delete rule EC5002 (SDK range) since it not in
the [best practices mobile](https://github.com/cnumr/best-practices-mobile) anymore
+- [#88](https://github.com/green-code-initiative/ecoCode-android/issues/88) Delete rule EC5003 (Disable obfuscation) since it not in
+ the [best practices mobile](https://github.com/cnumr/best-practices-mobile) anymore
## [1.1.0] - 2023-11-17
diff --git a/android-plugin/src/main/resources/org/sonar/plugins/groovy/cost.csv b/android-plugin/src/main/resources/org/sonar/plugins/groovy/cost.csv
index 9a8d936c..9c4156bf 100644
--- a/android-plugin/src/main/resources/org/sonar/plugins/groovy/cost.csv
+++ b/android-plugin/src/main/resources/org/sonar/plugins/groovy/cost.csv
@@ -1,3 +1,2 @@
ruleKey;remediationFunction;remediationFactor
EC5001;linear;1h
-EC5003;linear;10min
diff --git a/android-plugin/src/main/resources/org/sonar/plugins/groovy/profile-default.txt b/android-plugin/src/main/resources/org/sonar/plugins/groovy/profile-default.txt
index bf5553c0..b8b72dea 100644
--- a/android-plugin/src/main/resources/org/sonar/plugins/groovy/profile-default.txt
+++ b/android-plugin/src/main/resources/org/sonar/plugins/groovy/profile-default.txt
@@ -1,2 +1 @@
EC5001
-EC5003
\ No newline at end of file
diff --git a/android-plugin/src/main/resources/org/sonar/plugins/groovy/rules.xml b/android-plugin/src/main/resources/org/sonar/plugins/groovy/rules.xml
index 7d93da05..d54205f7 100644
--- a/android-plugin/src/main/resources/org/sonar/plugins/groovy/rules.xml
+++ b/android-plugin/src/main/resources/org/sonar/plugins/groovy/rules.xml
@@ -43,44 +43,4 @@
]]>
code-smell
-
-
-
- EC5003
- MINOR
-
-
- Using minifyEnabled true will obfuscate code and will have a sligthly negative impact on power consumption at runtime.
-Example of violations:
- android {
- compileSdk 32
-
- defaultConfig {
- applicationId "com.example.sampleForSonar"
- minSdkVersion 28
- targetSdkVersion 32
- versionCode 1
- versionName "1.0"
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
- }
-
- buildTypes {
- release {
- minifyEnabled true
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
- }
- }
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
- }
- buildFeatures {
- viewBinding true
- }
- }
-
-]]>
- code-smell
-
-
diff --git a/android-plugin/src/test/java/org/sonar/plugins/groovy/codenarc/CodeNarcRulesDefinitionTest.java b/android-plugin/src/test/java/org/sonar/plugins/groovy/codenarc/CodeNarcRulesDefinitionTest.java
index a636183c..22047f7a 100644
--- a/android-plugin/src/test/java/org/sonar/plugins/groovy/codenarc/CodeNarcRulesDefinitionTest.java
+++ b/android-plugin/src/test/java/org/sonar/plugins/groovy/codenarc/CodeNarcRulesDefinitionTest.java
@@ -41,6 +41,6 @@ public void test() {
assertThat(repository.language()).isEqualTo(Groovy.KEY);
List rules = repository.rules();
- assertThat(rules).hasSize(2);
+ assertThat(rules).hasSize(1);
}
}
diff --git a/codenarc-converter/CodeNarc/CHANGELOG.md b/codenarc-converter/CodeNarc/CHANGELOG.md
index f0a405a1..2ffa96e0 100644
--- a/codenarc-converter/CodeNarc/CHANGELOG.md
+++ b/codenarc-converter/CodeNarc/CHANGELOG.md
@@ -6,6 +6,7 @@ Version 2.2.5 (January 2024)
--------------------------------------
Remove rule:
- Supported Version Range -> EC5002
+- Disable Obfuscation -> EC5003
Version 2.2.4 (September 2023)
--------------------------------------
diff --git a/codenarc-converter/CodeNarc/docs/StarterRuleSet-AllRules.groovy.txt b/codenarc-converter/CodeNarc/docs/StarterRuleSet-AllRules.groovy.txt
index 21c46d02..85979380 100644
--- a/codenarc-converter/CodeNarc/docs/StarterRuleSet-AllRules.groovy.txt
+++ b/codenarc-converter/CodeNarc/docs/StarterRuleSet-AllRules.groovy.txt
@@ -88,7 +88,6 @@ ruleset {
DuplicateSetValue
DuplicateStringLiteral
EC5001
- EC5003
ElseBlockBraces
EmptyCatchBlock
EmptyClass
diff --git a/codenarc-converter/CodeNarc/docs/codenarc-rule-index-by-name.md b/codenarc-converter/CodeNarc/docs/codenarc-rule-index-by-name.md
index aea5d050..2c117951 100644
--- a/codenarc-converter/CodeNarc/docs/codenarc-rule-index-by-name.md
+++ b/codenarc-converter/CodeNarc/docs/codenarc-rule-index-by-name.md
@@ -90,7 +90,6 @@ title: CodeNarc - Rule Index by Name
* [DuplicateSetValue](./codenarc-rules-basic.html#duplicatesetvalue-rule)
* [DuplicateStringLiteral](./codenarc-rules-dry.html#duplicatestringliteral-rule)
* [EC5001](./codenarc-rules-ecocode.html#EC5001-rule)
-* [EC5003](./codenarc-rules-ecocode.html#EC5003-rule)
* [ElseBlockBraces](./codenarc-rules-braces.html#elseblockbraces-rule)
* [EmptyCatchBlock](./codenarc-rules-basic.html#emptycatchblock-rule)
* [EmptyClass](./codenarc-rules-basic.html#emptyclass-rule)
diff --git a/codenarc-converter/CodeNarc/docs/codenarc-rule-index.md b/codenarc-converter/CodeNarc/docs/codenarc-rule-index.md
index 2af10494..616375b1 100644
--- a/codenarc-converter/CodeNarc/docs/codenarc-rule-index.md
+++ b/codenarc-converter/CodeNarc/docs/codenarc-rule-index.md
@@ -168,7 +168,6 @@ title: CodeNarc - Rule Index
## [Ecocode](./codenarc-rules-ecocode.html)
* [EC5001](./codenarc-rules-ecocode.html#EC5001-rule)
-* [EC5003](./codenarc-rules-ecocode.html#EC5003-rule)
## [Enhanced](./codenarc-rules-enhanced.html)
* [CloneWithoutCloneable](./codenarc-rules-enhanced.html#clonewithoutcloneable-rule)
diff --git a/codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/rule/ecocode/EC5003.groovy b/codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/rule/ecocode/EC5003.groovy
deleted file mode 100644
index 671b5b52..00000000
--- a/codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/rule/ecocode/EC5003.groovy
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.codenarc.rule.ecocode
-
-
-import org.codehaus.groovy.ast.expr.ConstantExpression
-import org.codehaus.groovy.ast.expr.MethodCallExpression
-import org.codenarc.rule.AbstractAstVisitor
-import org.codenarc.rule.AbstractAstVisitorRule
-import org.codenarc.util.AstUtil
-
-/**
- * Using minifyEnabled true will obfuscate code and will have a sligthly negative impact on power consumption at runtime.
- *
- * @author Berque Justin
- */
-class EC5003 extends AbstractAstVisitorRule {
-
- String name = 'EC5003'
- int priority = 2
- Class astVisitorClass = EC5003AstVisitor
-}
-
-class EC5003AstVisitor extends AbstractAstVisitor {
-
- @Override
- void visitMethodCallExpression(MethodCallExpression methodCallExpression) {
- if (((ConstantExpression) methodCallExpression.getMethod()).getValue() == 'minifyEnabled') {
- for (Object value : AstUtil.getArgumentsValue(methodCallExpression.getArguments())) {
- if (value == true)
- addViolation(methodCallExpression, getViolationMessage())
- else {
- this.getSourceCode().getLines().each { string ->
- if (string.contains(value + ' = true')) {
- addViolation(methodCallExpression, getViolationMessage())
- }
- }
- }
- }
- }
- super.visitMethodCallExpression(methodCallExpression)
- }
-
- private String getViolationMessage() {
- return 'Using minifyEnabled true will obfuscate code and will have a sligthly negative impact on power consumption at runtime.'
- }
-}
diff --git a/codenarc-converter/CodeNarc/src/main/resources/codenarc-base-messages.properties b/codenarc-converter/CodeNarc/src/main/resources/codenarc-base-messages.properties
index 12859699..4d8ad6b2 100644
--- a/codenarc-converter/CodeNarc/src/main/resources/codenarc-base-messages.properties
+++ b/codenarc-converter/CodeNarc/src/main/resources/codenarc-base-messages.properties
@@ -1,7 +1,4 @@
-EC5003.description=Using minifyEnabled true will obfuscate code and will have a sligthly negative impact on power consumption at runtime.
-EC5003.description.html=Using minifyEnabled true will obfuscate code and will have a sligthly negative impact on power consumption at runtime.
-
EC5001.description=Using "multiDexEnabled true" goes against the overall reduction of the weight of the apps and hence must be avoided.
EC5001.description.html=Using "multiDexEnabled true" goes against the overall reduction of the weight of the apps and hence must be avoided.
diff --git a/codenarc-converter/CodeNarc/src/main/resources/codenarc-base-rules.properties b/codenarc-converter/CodeNarc/src/main/resources/codenarc-base-rules.properties
index 65be9b4e..ec4b6d7d 100644
--- a/codenarc-converter/CodeNarc/src/main/resources/codenarc-base-rules.properties
+++ b/codenarc-converter/CodeNarc/src/main/resources/codenarc-base-rules.properties
@@ -81,7 +81,6 @@ DuplicateNumberLiteral = org.codenarc.rule.dry.DuplicateNumberLiteralRule
DuplicateSetValue = org.codenarc.rule.basic.DuplicateSetValueRule
DuplicateStringLiteral = org.codenarc.rule.dry.DuplicateStringLiteralRule
EC5001 = org.codenarc.rule.ecocode.EC5001
-EC5003 = org.codenarc.rule.ecocode.EC5003
ElseBlockBraces = org.codenarc.rule.braces.ElseBlockBracesRule
EmptyCatchBlock = org.codenarc.rule.basic.EmptyCatchBlockRule
EmptyClass = org.codenarc.rule.basic.EmptyClassRule
diff --git a/codenarc-converter/CodeNarc/src/main/resources/rulesets/ecocode.xml b/codenarc-converter/CodeNarc/src/main/resources/rulesets/ecocode.xml
index 377f3d7c..ef702037 100644
--- a/codenarc-converter/CodeNarc/src/main/resources/rulesets/ecocode.xml
+++ b/codenarc-converter/CodeNarc/src/main/resources/rulesets/ecocode.xml
@@ -8,5 +8,4 @@
-
diff --git a/codenarc-converter/CodeNarc/src/test/groovy/org/codenarc/rule/ecocode/EC5003Test.groovy b/codenarc-converter/CodeNarc/src/test/groovy/org/codenarc/rule/ecocode/EC5003Test.groovy
deleted file mode 100644
index c38bb783..00000000
--- a/codenarc-converter/CodeNarc/src/test/groovy/org/codenarc/rule/ecocode/EC5003Test.groovy
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.codenarc.rule.ecocode
-
-import org.junit.Test
-import org.codenarc.rule.AbstractRuleTestCase
-
-/**
- * Tests for DisableObfuscationRule
- *
- * @author Leboulanger Mickael
- */
-class EC5003Test extends AbstractRuleTestCase {
-
- @Test
- void test_RuleProperties() {
- assert rule.priority == 2
- assert rule.name == 'DisableObfuscation'
- }
-
- @Test
- void test_SomeCondition_NoViolations() {
- final SOURCE = '''
- android {
- compileSdk 32
-
- defaultConfig {
- applicationId "com.example.sampleForSonar"
- minSdkVersion 28
- targetSdkVersion 32
- versionCode 1
- versionName "1.0"
-
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
- }
-
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro\'
- }
- }
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
- }
- buildFeatures {
- viewBinding true
- }
- }
- '''
- assertNoViolations(SOURCE)
- }
-
- @Test
- void testDetect_minifyEnabled_true() {
- final SOURCE = '''
- android {
- compileSdk 32
-
- defaultConfig {
- applicationId "com.example.sampleForSonar"
- minSdkVersionVersionVersion 28
- targetSdkVersionVersionVersion 32
- versionCode 1
- versionName "1.0"
-
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
- }
-
- buildTypes {
- release {
- minifyEnabled true
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro\'
- }
- }
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
- }
- buildFeatures {
- viewBinding true
- }
- }
- '''
- assertSingleViolation(SOURCE, 17, 'minifyEnabled', getViolationMessage())
- }
-
- @Test
- void testDetect_minifyEnabled_variable_true_before() {
- final SOURCE = '''
- def minify = true
- android {
- compileSdk 32
-
- defaultConfig {
- applicationId "com.example.sampleForSonar"
- minSdkVersionVersion 28
- targetSdkVersionVersion 32
- versionCode 1
- versionName "1.0"
-
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
- }
-
- buildTypes {
- release {
- minifyEnabled minify
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro\'
- }
- }
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
- }
- buildFeatures {
- viewBinding true
- }
- }
- '''
- assertSingleViolation(SOURCE, 18, 'minifyEnabled', getViolationMessage())
- }
-
- @Test
- void testDetect_multiDexEnabled_variable_true_after() {
- final SOURCE = '''
- android {
- compileSdk 32
-
- defaultConfig {
- applicationId "com.example.sampleForSonar"
- minSdkVersion 28
- targetSdkVersion 32
- versionCode 1
- versionName "1.0"
-
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
- }
-
- buildTypes {
- release {
- minifyEnabled minify
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro\'
- }
- }
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
- }
- buildFeatures {
- viewBinding true
- }
- }
- def minify = true
- '''
- assertSingleViolation(SOURCE, 17, 'minifyEnabled', getViolationMessage())
- }
-
- @Test
- void testDetect_minifyEnabled_variable_may_be_true() {
- final SOURCE = '''
- def minify = false
- android {
- compileSdk 32
-
- defaultConfig {
- applicationId "com.example.sampleForSonar"
- minSdkVersion 28
- targetSdkVersion 32
- versionCode 1
- versionName "1.0"
-
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
- }
-
- buildTypes {
- release {
- minifyEnabled minify
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro\'
- }
- }
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
- }
- buildFeatures {
- viewBinding true
- }
- }
- if (true) {
- minify = true
- }
- '''
- assertSingleViolation(SOURCE, 18, 'minifyEnabled', getViolationMessage())
- }
-
- @Override
- protected EC5003 createRule() {
- new EC5003()
- }
- private String getViolationMessage() {
- return 'Using minifyEnabled true will obfuscate code and will have a sligthly negative impact on power consumption at runtime.'
- }
-}