Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add detekt #5539

Merged
merged 14 commits into from
Feb 5, 2024
9 changes: 9 additions & 0 deletions .github/workflows/android-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ jobs:
build-root-directory: android
execution-only-caches: true

- name: Run detekt
uses: burrunan/gradle-cache-action@v1
with:
job-id: jdk17
arguments: detekt
gradle-version: wrapper
build-root-directory: android
execution-only-caches: true

# Running the AGP lint here rather than in the separate lint workflow
# (android-kotlin-format-check.yml) since it's easier to make use of the running container,
# cache and previously ran tasks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class RedeemVoucherDialogTest {
}

companion object {
private const val REDEEM_BUTTON_TEXT = "Redeem"
private const val CANCEL_BUTTON_TEXT = "Cancel"
private const val GOT_IT_BUTTON_TEXT = "Got it!"
private const val DUMMY_VOUCHER = "DUMMY____VOUCHER"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("MagicNumber")

package net.mullvad.mullvadvpn.util

import kotlinx.coroutines.Deferred
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import androidx.core.graphics.drawable.toBitmapOrNull
fun PackageManager.getApplicationIconBitmapOrNull(packageName: String): Bitmap? =
try {
getApplicationIcon(packageName).toBitmapOrNull()
} catch (e: Exception) {
} catch (e: PackageManager.NameNotFoundException) {
// Name not found is thrown if the application is not installed
null
} catch (e: IllegalArgumentException) {
// IllegalArgumentException is thrown if the application has an invalid icon
when (e) {
is PackageManager.NameNotFoundException,
is IllegalArgumentException -> null
else -> throw e
}
null
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import java.net.InetAddress
import java.net.UnknownHostException
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.BufferOverflow
Expand Down Expand Up @@ -223,7 +224,7 @@ class VpnSettingsViewModel(
private fun List<String>.asInetAddressList(): List<InetAddress> {
return try {
map { InetAddress.getByName(it) }
} catch (ex: Exception) {
} catch (ex: UnknownHostException) {
Log.e("mullvad", "Error parsing the DNS address list.")
emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.unmockkAll
import kotlin.reflect.KClass
import net.mullvad.mullvadvpn.lib.common.util.JobTracker
import net.mullvad.mullvadvpn.lib.ipc.Event
import net.mullvad.mullvadvpn.lib.ipc.EventDispatcher
import net.mullvad.mullvadvpn.lib.ipc.Request
Expand All @@ -22,8 +21,6 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class ServiceConnectionDeviceDataSourceTest {
private val tracker = JobTracker()

@MockK private lateinit var mockedMainLooper: Looper

@MockK private lateinit var mockedDispatchingHandler: EventDispatcher
Expand Down
25 changes: 25 additions & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import io.gitlab.arturbosch.detekt.Detekt

plugins {
id(Dependencies.Plugin.dependencyCheckId) version Versions.Plugin.dependencyCheck apply false
id(Dependencies.Plugin.gradleVersionsId) version Versions.Plugin.gradleVersions
id(Dependencies.Plugin.ktfmtId) version Versions.Plugin.ktfmt apply false
id(Dependencies.Plugin.detektId) version Versions.Plugin.detekt
}

buildscript {
repositories {
google()
mavenCentral()
maven(Repositories.GradlePlugins)
gradlePluginPortal()
}

dependencies {
Expand All @@ -27,6 +30,28 @@ buildscript {
}
}

val baselineFile = file("$rootDir/config/baseline.xml")
val configFile = files("$rootDir/config/detekt.yml")

val projectSource = file(projectDir)
val buildFiles = "**/build/**"

detekt {
buildUponDefaultConfig = true
allRules = false
config.setFrom(configFile)
source.setFrom(projectSource)
baseline = baselineFile
parallel = true
ignoreFailures = false
autoCorrect = true
}

tasks.withType<Detekt>().configureEach {
// Ignore generated files from the build directory, e.g files created by ksp.
exclude(buildFiles)
}

allprojects {
apply(plugin = Dependencies.Plugin.dependencyCheckId)
apply(plugin = Dependencies.Plugin.ktfmtId)
Expand Down
1 change: 1 addition & 0 deletions android/buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ object Dependencies {
const val dependencyCheck =
"org.owasp:dependency-check-gradle:${Versions.Plugin.dependencyCheck}"
const val dependencyCheckId = "org.owasp.dependencycheck"
const val detektId = "io.gitlab.arturbosch.detekt"
const val gradleVersionsId = "com.github.ben-manes.versions"
const val junit5 = "de.mannodermaus.android-junit5"
const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
Expand Down
4 changes: 2 additions & 2 deletions android/buildSrc/src/main/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ fun String.isNonStableVersion(): Boolean {
return isNonStable
}

fun DependencyHandler.`leakCanaryImplementation`(dependencyNotation: Any): Dependency? =
fun DependencyHandler.leakCanaryImplementation(dependencyNotation: Any): Dependency? =
add("leakCanaryImplementation", dependencyNotation)

fun DependencyHandler.`playImplementation`(dependencyNotation: Any): Dependency? =
fun DependencyHandler.playImplementation(dependencyNotation: Any): Dependency? =
add("playImplementation", dependencyNotation)
1 change: 1 addition & 0 deletions android/buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ object Versions {
const val androidAapt = "$android-10154469"
const val playPublisher = "3.8.4"
const val dependencyCheck = "8.3.1"
const val detekt = "1.23.4"
const val gradleVersions = "0.47.0"
const val junit5 = "1.10.0.0"
const val ktfmt = "0.16.0"
Expand Down
Loading
Loading