From af23cf56b7787f87a1a3d25fa4ecddf710d4e144 Mon Sep 17 00:00:00 2001 From: MohitMali Date: Tue, 4 Jul 2023 19:08:33 +0530 Subject: [PATCH] Detecting deprecated code via detekt and fixed detekt detection for the issues in project, and refactored deprecated rules of detekt --- .github/workflows/pull_request.yml | 2 +- .../src/main/kotlin/plugin/AllProjectConfigurer.kt | 8 ++++++++ config/detekt/detekt.yml | 13 +++++++------ team-props/git-hooks/pre-commit.sh | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 53b6b4872..266ad4318 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -72,7 +72,7 @@ jobs: ${{ runner.os }}-gradle- - name: Static Analysis - run: ./gradlew detekt + run: ./gradlew detektDebug detektCustomExampleDebug - name: Upload Lint Reports uses: actions/upload-artifact@v3 if: ${{ always() }} diff --git a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt index 468574d82..9e74061e5 100644 --- a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt +++ b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt @@ -22,6 +22,8 @@ import Config import Libs import com.android.build.api.dsl.CommonExtension import com.android.build.gradle.BaseExtension +import io.gitlab.arturbosch.detekt.Detekt +import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask import io.gitlab.arturbosch.detekt.extensions.DetektExtension import org.gradle.api.Project import org.gradle.kotlin.dsl.apply @@ -67,6 +69,12 @@ class AllProjectConfigurer { target.tasks.withType(KotlinCompile::class.java) { kotlinOptions.jvmTarget = "1.8" } + target.tasks.withType(Detekt::class.java).configureEach { + jvmTarget = "1.8" + } + target.tasks.withType(DetektCreateBaselineTask::class.java).configureEach { + jvmTarget = "1.8" + } buildFeatures.viewBinding = true testOptions { diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index 45ba1cf73..ec68df645 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -79,7 +79,8 @@ complexity: threshold: 60 LongParameterList: active: true - threshold: 6 + functionThreshold: 6 + constructorThreshold: 6 ignoreDefaultParameters: false MethodOverloading: active: false @@ -316,7 +317,7 @@ potential-bugs: LateinitUsage: active: false excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" - excludeAnnotatedProperties: "" + ignoreAnnotated: [] ignoreOnClassesPattern: "" MapGetWithNotNullAssertionOperator: active: false @@ -379,7 +380,7 @@ style: active: true ignoreOverridableFunction: true excludedFunctions: 'describeContents' - excludeAnnotatedFunction: "dagger.Provides" + ignoreAnnotated: ["dagger.Provides"] LibraryCodeMustSpecifyReturnType: active: true LoopWithTooManyJumpStatements: @@ -450,10 +451,10 @@ style: active: false UnderscoresInNumericLiterals: active: false - acceptableDecimalLength: 5 + acceptableLength: 5 UnnecessaryAbstractClass: active: true - excludeAnnotatedClasses: "dagger.Module" + ignoreAnnotated: ["dagger.Module"] UnnecessaryAnnotationUseSiteTarget: active: false UnnecessaryApply: @@ -479,7 +480,7 @@ style: active: false UseDataClass: active: false - excludeAnnotatedClasses: "" + ignoreAnnotated: [] allowVars: false UseIfInsteadOfWhen: active: false diff --git a/team-props/git-hooks/pre-commit.sh b/team-props/git-hooks/pre-commit.sh index 9c66d7b78..4f8eb37f1 100644 --- a/team-props/git-hooks/pre-commit.sh +++ b/team-props/git-hooks/pre-commit.sh @@ -2,7 +2,7 @@ echo "Running lint..." -./gradlew ktlintCheck detekt app:lintDebug custom:lintCustomexampleDebug --daemon +./gradlew ktlintCheck detektDebug detektCustomExampleDebug app:lintDebug custom:lintCustomexampleDebug --daemon status=$?