From 61212c3628096d8a7700a6f55544e014435df695 Mon Sep 17 00:00:00 2001 From: David Perez Date: Mon, 5 Feb 2024 15:34:26 -0600 Subject: [PATCH] Update detekt and fix minor warnings (#955) --- .../data/platform/util/IntentExtensions.kt | 1 + .../data/platform/util/URIExtensions.kt | 4 +- .../vault/repository/VaultRepositoryTest.kt | 55 ------------------- detekt-config.yml | 4 +- gradle/libs.versions.toml | 2 +- 5 files changed, 6 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/data/platform/util/IntentExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/data/platform/util/IntentExtensions.kt index b1552c3ea..3d4a4dcce 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/platform/util/IntentExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/platform/util/IntentExtensions.kt @@ -18,5 +18,6 @@ inline fun Intent.getSafeParcelableExtra(name: String): T? = T::class.java, ) } else { + @Suppress("DEPRECATION") getParcelableExtra(name) } diff --git a/app/src/main/java/com/x8bit/bitwarden/data/platform/util/URIExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/data/platform/util/URIExtensions.kt index 3ab94bd68..0520595e8 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/platform/util/URIExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/platform/util/URIExtensions.kt @@ -18,7 +18,7 @@ private const val IP_REGEX: String = * Parses the base domain from the URL. Returns null if unavailable. */ fun URI.parseDomainOrNull(context: Context): String? { - val host = this?.host ?: return null + val host = this.host ?: return null val isIpAddress = host.matches(IP_REGEX.toRegex()) return if (host == "localhost" || isIpAddress) { @@ -38,7 +38,7 @@ fun URI.parseDomainOrNull(context: Context): String? { fun URI.parseDomainNameOrNull(context: Context): DomainName? = this // URI is a platform type and host can be null. - ?.host + .host ?.let { nonNullHost -> parseDomainNameOrNullInternal( context = context, diff --git a/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt index c1f46a78c..afdbb6823 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt @@ -3335,9 +3335,6 @@ class VaultRepositoryTest { fakeAuthDiskSource.userState = MOCK_USER_STATE val attachmentId = "mockId-1" - val attachment = mockk { - every { id } returns attachmentId - } val cipher = mockk { every { attachments } returns emptyList() every { id } returns "mockId-1" @@ -5366,58 +5363,6 @@ class VaultRepositoryTest { coEvery { vaultDiskSource.getSends(MOCK_USER_STATE.activeUserId) } returns sendsFlow } - /** - * Helper to ensures that the vault for the user with the given [userId] is unlocked. - */ - private suspend fun verifyUnlockedVault(userId: String) { - val kdf = MOCK_PROFILE.toSdkParams() - val email = MOCK_PROFILE.email - val masterPassword = "drowssap" - val userKey = "12345" - val privateKey = "54321" - val organizationKeys = null - coEvery { - vaultSdkSource.initializeCrypto( - userId = userId, - request = InitUserCryptoRequest( - kdfParams = kdf, - email = email, - privateKey = privateKey, - method = InitUserCryptoMethod.Password( - password = masterPassword, - userKey = userKey, - ), - ), - ) - } returns InitializeCryptoResult.Success.asSuccess() - - val result = vaultRepository.unlockVault( - userId = userId, - masterPassword = masterPassword, - kdf = kdf, - email = email, - userKey = userKey, - privateKey = privateKey, - organizationKeys = organizationKeys, - ) - - assertEquals(VaultUnlockResult.Success, result) - coVerify(exactly = 1) { - vaultSdkSource.initializeCrypto( - userId = userId, - request = InitUserCryptoRequest( - kdfParams = kdf, - email = email, - privateKey = privateKey, - method = InitUserCryptoMethod.Password( - password = masterPassword, - userKey = userKey, - ), - ), - ) - } - } - private suspend fun setupDataStateFlow(userId: String) { coEvery { vaultSdkSource.decryptCipherList( diff --git a/detekt-config.yml b/detekt-config.yml index f5ee4b631..a6ed6c7a3 100644 --- a/detekt-config.yml +++ b/detekt-config.yml @@ -417,7 +417,7 @@ naming: packagePattern: '[a-z]+(\.[a-z][A-Za-z0-9]*)*' TopLevelPropertyNaming: active: true - excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**', '**/compose/**'] + excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**', '**/compose/**' ] constantPattern: '[A-Z][_A-Z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*' privatePropertyPattern: '_?[A-Za-z][_A-Za-z0-9]*' @@ -584,7 +584,7 @@ style: active: true OptionalUnit: active: false - OptionalWhenBraces: + BracesOnWhenStatements: active: false PreferToOverPairSyntax: active: false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 95e03a5a3..b1d706c1f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -29,7 +29,7 @@ androdixAutofill = "1.1.0" androidxWork = "2.9.0" bitwardenSdk = "0.4.0-20240205.155354-106" crashlytics = "2.9.9" -detekt = "1.23.1" +detekt = "1.23.5" firebaseBom = "32.7.0" glide = "1.0.0-beta01" googleServices = "4.4.0"