diff --git a/CHANGELOG.md b/CHANGELOG.md index 458adbec..5de4f8aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deleted +- [#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 + ## [1.1.0] - 2023-11-17 ### Added diff --git a/android-plugin/pom.xml b/android-plugin/pom.xml index 06786050..0ae85e19 100644 --- a/android-plugin/pom.xml +++ b/android-plugin/pom.xml @@ -184,7 +184,7 @@ org.codenarc CodeNarc - 2.2.4 + 2.2.5 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 e7beefaf..9a8d936c 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,4 +1,3 @@ ruleKey;remediationFunction;remediationFactor EC5001;linear;1h -EC5002;linear;10min 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 ebe6fc37..bf5553c0 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,3 +1,2 @@ EC5001 -EC5002 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 6e5ea315..7d93da05 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 @@ -44,46 +44,6 @@ code-smell - - - EC5002 - MINOR - - - When looking at the minSdkVersion and targetSdkVersion (or minSdk, targetSdk) attributes for the in the AndroidManifest.xml file, the amplitude of supported platform versions should not be too wide, at the risk of making the app too heavy to handle all cases.

-

Example of violations:

-
android {
-    compileSdk 32
-
-    defaultConfig {
-        applicationId "com.example.sampleForSonar"
-        minSdkVersion 26
-        targetSdkVersion 31
-        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
-    }
-}
-
-]]>
- code-smell -
- EC5003 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 8a255fab..a636183c 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(3); + assertThat(rules).hasSize(2); } } diff --git a/codenarc-converter/CodeNarc/CHANGELOG.md b/codenarc-converter/CodeNarc/CHANGELOG.md index c77af577..f0a405a1 100644 --- a/codenarc-converter/CodeNarc/CHANGELOG.md +++ b/codenarc-converter/CodeNarc/CHANGELOG.md @@ -2,6 +2,11 @@ # CodeNarc Change Log +Version 2.2.5 (January 2024) +-------------------------------------- +Remove rule: +- Supported Version Range -> EC5002 + Version 2.2.4 (September 2023) -------------------------------------- Update key of ecoCode rules: diff --git a/codenarc-converter/CodeNarc/build.gradle b/codenarc-converter/CodeNarc/build.gradle index d90782e7..50e3b8df 100644 --- a/codenarc-converter/CodeNarc/build.gradle +++ b/codenarc-converter/CodeNarc/build.gradle @@ -14,7 +14,7 @@ shadowJar { group = 'org.codenarc' archivesBaseName = 'CodeNarc' -version = '2.2.4' +version = '2.2.5' sourceCompatibility = '1.7' targetCompatibility = '1.7' diff --git a/codenarc-converter/CodeNarc/docs/StarterRuleSet-AllRules.groovy.txt b/codenarc-converter/CodeNarc/docs/StarterRuleSet-AllRules.groovy.txt index 6f4567ab..21c46d02 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 - EC5002 EC5003 ElseBlockBraces EmptyCatchBlock diff --git a/codenarc-converter/CodeNarc/docs/StarterRuleSet-AllRulesByCategory.groovy.txt b/codenarc-converter/CodeNarc/docs/StarterRuleSet-AllRulesByCategory.groovy.txt index a51f5399..35488472 100644 --- a/codenarc-converter/CodeNarc/docs/StarterRuleSet-AllRulesByCategory.groovy.txt +++ b/codenarc-converter/CodeNarc/docs/StarterRuleSet-AllRulesByCategory.groovy.txt @@ -167,7 +167,6 @@ ruleset { // rulesets/ecocode.xml EC5001 - EC5002 EC5003 // rulesets/enhanced.xml 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 c21d39cb..aea5d050 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) -* [EC5002](./codenarc-rules-ecocode.html#EC5002-rule) * [EC5003](./codenarc-rules-ecocode.html#EC5003-rule) * [ElseBlockBraces](./codenarc-rules-braces.html#elseblockbraces-rule) * [EmptyCatchBlock](./codenarc-rules-basic.html#emptycatchblock-rule) diff --git a/codenarc-converter/CodeNarc/docs/codenarc-rule-index.md b/codenarc-converter/CodeNarc/docs/codenarc-rule-index.md index 36a0e2cc..2af10494 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) -* [EC5002](./codenarc-rules-ecocode.html#EC5002-rule) * [EC5003](./codenarc-rules-ecocode.html#EC5003-rule) ## [Enhanced](./codenarc-rules-enhanced.html) diff --git a/codenarc-converter/CodeNarc/docs/codenarc-rules-ecocode.md b/codenarc-converter/CodeNarc/docs/codenarc-rules-ecocode.md index b38a7c61..6280f050 100644 --- a/codenarc-converter/CodeNarc/docs/codenarc-rules-ecocode.md +++ b/codenarc-converter/CodeNarc/docs/codenarc-rules-ecocode.md @@ -45,44 +45,6 @@ Example of violations: } ``` -## EC5002 Rule - -*Since CodeNarc 2.2.1* - -When looking at the minSdkVersion and targetSdkVersion (or minSdk, targetSdk) attributes for the in the AndroidManifest.xml file, the amplitude of supported platform versions should not be too wide, at the risk of making the app too heavy to handle all cases. - -Example of violations: - -``` -android { - compileSdk 32 - - defaultConfig { - applicationId "com.example.sampleForSonar" - minSdkVersion 26 - targetSdkVersion 31 - 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 - } -} -``` - ## EC5003 Rule *Since CodeNarc 2.2.3* diff --git a/codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/rule/ecocode/EC5002.groovy b/codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/rule/ecocode/EC5002.groovy deleted file mode 100644 index a72582da..00000000 --- a/codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/rule/ecocode/EC5002.groovy +++ /dev/null @@ -1,67 +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 - -/** - * When looking at the minSdkVersion and targetSdkVersion or minSdk and targetSdk attributes for the in the AndroidManifest.xml file, the amplitude of supported platform versions should not be too wide, at the risk of making the app too heavy to handle all cases. - * - * @author Leboulanger Mickael - */ -class EC5002 extends AbstractAstVisitorRule { - - String name = 'EC5002' - int priority = 2 - int minSdkVersion = 0 - int minSdk = 0 - int targetSdkVersion = 0 - int targetSdk = 0 - int threshold = 4 // Value used to compare minSdkVersion and targetSdkVersion - Class astVisitorClass = EC5002AstVisitor -} - -class EC5002AstVisitor extends AbstractAstVisitor { - - @Override - void visitMethodCallExpression(MethodCallExpression methodCallExpression) { - def methodName = ((ConstantExpression) methodCallExpression.getMethod()).getValue() - if (methodName == 'minSdkVersion' || methodName == 'targetSdkVersion' || methodName == 'minSdk' || methodName == 'targetSdk') { - def arguments = AstUtil.getArgumentsValue(methodCallExpression.getArguments()) - - if (arguments.size() == 1) { - rule[methodName] = arguments.get(0) - } - - if ((rule.minSdkVersion && rule.targetSdkVersion) && rule.targetSdkVersion - rule.minSdkVersion > rule.threshold) { - addViolation(methodCallExpression, getViolationMessage()) - } - - if ((rule.minSdk && rule.targetSdk) && rule.targetSdk - rule.minSdk > rule.threshold) { - addViolation(methodCallExpression, getViolationMessage()) - } - } - super.visitMethodCallExpression(methodCallExpression) - } - - private String getViolationMessage() { - return 'The amplitude of supported platform versions should not be too wide, at the risk of making the app too heavy to handle all cases.' - } -} 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 d938f55b..12859699 100644 --- a/codenarc-converter/CodeNarc/src/main/resources/codenarc-base-messages.properties +++ b/codenarc-converter/CodeNarc/src/main/resources/codenarc-base-messages.properties @@ -2,9 +2,6 @@ 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. -EC5002.description=The amplitude of supported platform versions should not be too wide, at the risk of making the app too heavy to handle all cases. -EC5002.description.html=The amplitude of supported platform versions should not be too wide, at the risk of making the app too heavy to handle all cases. - 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 13f4c4af..65be9b4e 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 -EC5002 = org.codenarc.rule.ecocode.EC5002 EC5003 = org.codenarc.rule.ecocode.EC5003 ElseBlockBraces = org.codenarc.rule.braces.ElseBlockBracesRule EmptyCatchBlock = org.codenarc.rule.basic.EmptyCatchBlockRule diff --git a/codenarc-converter/CodeNarc/src/main/resources/codenarc-version.txt b/codenarc-converter/CodeNarc/src/main/resources/codenarc-version.txt index 530cdd91..21bb5e15 100644 --- a/codenarc-converter/CodeNarc/src/main/resources/codenarc-version.txt +++ b/codenarc-converter/CodeNarc/src/main/resources/codenarc-version.txt @@ -1 +1 @@ -2.2.4 +2.2.5 diff --git a/codenarc-converter/CodeNarc/src/main/resources/rulesets/ecocode.xml b/codenarc-converter/CodeNarc/src/main/resources/rulesets/ecocode.xml index ccf20fbb..377f3d7c 100644 --- a/codenarc-converter/CodeNarc/src/main/resources/rulesets/ecocode.xml +++ b/codenarc-converter/CodeNarc/src/main/resources/rulesets/ecocode.xml @@ -8,6 +8,5 @@ - diff --git a/codenarc-converter/CodeNarc/src/test/groovy/org/codenarc/rule/ecocode/EC5002Test.groovy b/codenarc-converter/CodeNarc/src/test/groovy/org/codenarc/rule/ecocode/EC5002Test.groovy deleted file mode 100644 index bbf8f013..00000000 --- a/codenarc-converter/CodeNarc/src/test/groovy/org/codenarc/rule/ecocode/EC5002Test.groovy +++ /dev/null @@ -1,141 +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.codenarc.rule.AbstractRuleTestCase -import org.junit.Test - -/** - * Tests for SupportedVersionRangeRule - * - * @author Leboulanger Mickael - */ -class EC5002Test extends AbstractRuleTestCase { - - @Test - void test_RuleProperties() { - assert rule.priority == 2 - assert rule.name == 'EC5002' - } - - @Test - void test_SomeCondition_NoViolations() { - final SOURCE = ''' - android { - compileSdk 32 - - defaultConfig { - applicationId "com.example.sampleForSonar" - minSdkVersion 28 - targetSdkVersion 31 - 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 test_SdkRange_SingleViolation() { - final SOURCE = ''' - android { - compileSdk 32 - - defaultConfig { - applicationId "com.example.sampleForSonar" - minSdkVersion 26 - targetSdkVersion 31 - 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 - } - } - ''' - assertSingleViolation(SOURCE,8, 'targetSdkVersion') - } - - - @Test - void test_SdkRange_Short_SingleViolation() { - final SOURCE = ''' - android { - compileSdk 32 - - defaultConfig { - applicationId "com.example.sampleForSonar" - minSdk 26 - targetSdk 31 - 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 - } - } - ''' - assertSingleViolation(SOURCE,8, 'targetSdk') - } - - @Override - protected EC5002 createRule() { - new EC5002() - } -} diff --git a/codenarc-converter/pom.xml b/codenarc-converter/pom.xml index 7620b45d..8e4f65c8 100644 --- a/codenarc-converter/pom.xml +++ b/codenarc-converter/pom.xml @@ -16,7 +16,7 @@ https://github.com/green-code-initiative/ecocode-android/tree/main/codenarc-converter - 2.2.4 + 2.2.5 1.8.2 true diff --git a/tool_prepare-codenarc.bat b/tool_prepare-codenarc.bat index 43c6380e..c5223c9d 100644 --- a/tool_prepare-codenarc.bat +++ b/tool_prepare-codenarc.bat @@ -1,5 +1,5 @@ REM == Define CodeNarc version -set codenarc_version=2.2.4 +set codenarc_version=2.2.5 REM == Build CodeNarc cd codenarc-converter/CodeNarc diff --git a/tool_prepare-codenarc.sh b/tool_prepare-codenarc.sh index 7e83c722..993baf85 100755 --- a/tool_prepare-codenarc.sh +++ b/tool_prepare-codenarc.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh # Define CodeNarc version -codenarcVersion="2.2.4" +codenarcVersion="2.2.5" # Build CodeNarc cd codenarc-converter/CodeNarc