Skip to content

Commit

Permalink
ANDROID-11179 detekt implementation (#386)
Browse files Browse the repository at this point in the history
* ANDROID-11179 detekt implementation

* ANDROID-11179 using detekt's last version

* ANDROID-11179 excluding files beneath .gradle, build & tmp

* ANDROID-11179 deprecated input replaced with basePath, and now excluding more autogenerated files

* ANDROID-11179 non deprecated config setting

* ANDROID-11179 interface name capitalisation to meet detekt requirements

* ANDROID-11179 for loop replaced with repeat in order to fix detekt issue after spotting unused "a" variable

* ANDROID-11179 unused imports removed

* ANDROID-11179 too long line detekt issue fixed

* ANDROID-11179 multiple variable declaration detekt issue fixed

* ANDROID-11179 calling error function instead of throwing exception in order to fix detekt's issue

* ANDROID-11179 putting composable functions first in order to avoid renaming ButtonSizeConfig data class or ButtonSizes.kt

* ANDROID-11179 empty constructor removed

* ANDROID-11179 detekt issues fixed LongMethod, CyclomaticComplexMethod

* ANDROID-11179 detekt issues fixed SwallowedException

* ANDROID-11179 detekt issue fixed: CyclomaticComplexMethod

* ANDROID-11179 detekt issue fixed: LongMethod

* ANDROID-11179 detekt added to tests.yml

* ANDROID-11179 unused import removed

* ANDROID-11179 too long line issue fixed and detekt issues with configureView suppressed

* ANDROID-11179 detekt issues suppressed until further notice (jira tickets will be created to address them)

* ANDROID-11179 code cleanup

* ANDROID-11179 detekt-baseline.xml removed

* ANDROID-11179 error prone icon replaced with stable one

* ANDROID-11179 link to the library updated

* ANDROID-11179 LongMethod issue ignored on Composable annotated functions
  • Loading branch information
jmanriquehiberus authored Sep 24, 2024
1 parent 44d6ab7 commit 4d44396
Show file tree
Hide file tree
Showing 37 changed files with 442 additions and 556 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v2

- name: "Build Android project"
run: 'bash ./gradlew clean check assemble'
run: 'bash ./gradlew clean check detekt assemble'

- name: Upload Lint results
uses: github/codeql-action/upload-sarif@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
![Mistica for Android](doc/images/mistica-android-dark.svg#gh-dark-mode-only)

[![Platform](https://img.shields.io/badge/Platform-Android-brightgreen)](https://github.com/Telefonica/mistica-android)
[![Version](https://maven-badges.herokuapp.com/maven-central/com.telefonica/mistica/badge.png)](https://central.sonatype.com/artifact/com.telefonica/mistica?smo=true)
[![Version](https://img.shields.io/maven-metadata/v.svg?label=maven-central&metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fcom%2Ftelefonica%2Fmistica%2Fmaven-metadata.xml)](https://central.sonatype.com/artifact/com.telefonica/mistica)
[![Support](https://img.shields.io/badge/Support-%3E%3D%20Android%205.0-brightgreen)](https://github.com/Telefonica/mistica-android)
[![Kotlin version badge](https://img.shields.io/badge/kotlin-1.8.20-blue.svg)](https://kotlinlang.org/docs/whatsnew1820.html)

Expand Down
6 changes: 6 additions & 0 deletions build-tools/detekt.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

detekt {
buildUponDefaultConfig = true
config.from(files("$projectDir/build-tools/detekt/detekt.yml"))
basePath = files("$projectDir")
}
39 changes: 39 additions & 0 deletions build-tools/detekt/detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
complexity:
TooManyFunctions:
active: false
LongParameterList:
active: false
LongMethod:
ignoreAnnotated: 'Composable'


style:
NewLineAtEndOfFile:
active: false
MagicNumber:
active: false
ReturnCount:
active: false
UnusedImports:
active: true
MaxLineLength:
maxLineLength: 160
UnusedPrivateMember:
ignoreAnnotated: 'Preview'
UnnecessaryAbstractClass:
ignoreAnnotated: "Module"

naming:
FunctionNaming:
active: true
ignoreAnnotated: 'Composable'

empty-blocks:
EmptyFunctionBlock:
active: false

exceptions:
TooGenericExceptionThrown:
active: false
TooGenericExceptionCaught:
active: false
44 changes: 44 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ buildscript {
accompanist_version = "0.32.0"
coil_version = '2.5.0'
constraintComposeVersion = '1.0.1'
detekt_version = '1.23.7'
roborazzi_version = "1.10.1"
}
repositories {
Expand All @@ -23,13 +24,19 @@ buildscript {
classpath "com.android.tools.build:gradle:8.1.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "gradle.plugin.com.betomorrow.gradle:appcenter-plugin:2.0.3"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detekt_version"
}
}

plugins {
id 'org.jetbrains.kotlin.android' version '1.5.21' apply false
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' apply false
id "io.github.takahirom.roborazzi" version '1.10.1' apply false
id "io.gitlab.arturbosch.detekt" version '1.23.7'
}

dependencies {
apply plugin: "io.gitlab.arturbosch.detekt"
}

allprojects {
Expand All @@ -41,10 +48,47 @@ allprojects {
version = System.getProperty("LIBRARY_VERSION") ?: "undefined"
}

tasks.withType(io.gitlab.arturbosch.detekt.Detekt).all {
exclude("build/")
exclude("**/build/**")
exclude("**/resources/**")
exclude("**/tmp/**")
exclude("**/*Autogenerated.kt")
}

tasks.withType(io.gitlab.arturbosch.detekt.Detekt).configureEach {
reports {
html {
outputLocation.set(file("$buildDir/reports/detekt/detekt-report.html"))
required.set(true)
}
xml {
outputLocation.set(file("$buildDir/reports/detekt/detekt-checkstyle.xml"))
required.set(true)
}
}
}

task detektProjectBaseline(type: io.gitlab.arturbosch.detekt.DetektCreateBaselineTask) {
description = "Overrides current baseline."
ignoreFailures.set(true)
parallel.set(true)
buildUponDefaultConfig.set(true)
setSource(files("$projectDir"))
config.setFrom(files("$projectDir/build-tools/detekt/detekt.yml"))
include("**/*.kt")
include("**/*.kts")
}

repositories {
google()
mavenCentral()
}
}

apply from: "${rootProject.projectDir}/publish_maven_central.gradle"
apply from: "build-tools/detekt.gradle"

tasks.withType(io.gitlab.arturbosch.detekt.Detekt) {
autoCorrect = true
}
Loading

0 comments on commit 4d44396

Please sign in to comment.