Skip to content

Commit

Permalink
refactor: fix detekt warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceanis committed Mar 20, 2020
1 parent 9cc2550 commit 497cfde
Show file tree
Hide file tree
Showing 45 changed files with 221 additions and 163 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ jobs:
# upload test coverage report!
- run: bash <(curl -s https://codecov.io/bash)

# run linter
- run: ./gradlew detekt
- store_artifacts:
path: ./build/reports

workflows:
version: 2
workflow:
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ detekt {
"$projectDir"
)
config = files("${projectDir}/detekt.yml")
baseline = file("${projectDir}/detekt_baseline.xml")
parallel = true
reports {
xml {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.uport.credential_status
package me.uport.credentialstatus

import me.uport.sdk.universaldid.DIDDocument

Expand Down Expand Up @@ -41,4 +41,4 @@ interface StatusResolver {
* Checks the status of a given credential and returns a [CredentialStatus] or throws an error
*/
suspend fun checkStatus(credential: String, didDoc: DIDDocument): CredentialStatus
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package me.uport.credential_status
package me.uport.credentialstatus

import me.uport.sdk.universaldid.DIDDocument
import me.uport.sdk.universaldid.UniversalDID.method
import me.uport.sdk.universaldid.UniversalDID.registerResolver

/**
*
Expand Down Expand Up @@ -36,12 +34,13 @@ class UniversalStatusResolver : StatusResolver {

val statusEntry = getStatusEntry(credential)

if (statusEntry.type.isBlank() || !resolvers.containsKey(statusEntry.type)) {
throw IllegalStateException("There is no StatusResolver registered to check status using '${statusEntry.type}' method.")
} else {
return resolvers[statusEntry.type]?.checkStatus(credential, didDoc)
?: throw IllegalStateException("There StatusResolver for '$statusEntry.type' failed to resolve for an unknown reason.")
val resolver = resolvers[statusEntry.type]

check(statusEntry.type.isNotBlank() && resolver != null) {
"There is no StatusResolver registered to check status using '${statusEntry.type}' method."
}

return resolver.checkStatus(credential, didDoc)
}


Expand All @@ -54,4 +53,4 @@ class UniversalStatusResolver : StatusResolver {
}
resolvers[resolver.method] = resolver
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.uport.credential_status
package me.uport.credentialstatus

import me.uport.sdk.jwt.JWTTools

Expand All @@ -15,4 +15,4 @@ fun getStatusEntry(credential: String): StatusEntry {
status["type"] ?: "",
status["id"] ?: ""
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import assertk.assertions.isEqualTo
import assertk.assertions.isFailure
import assertk.assertions.isInstanceOf
import kotlinx.coroutines.runBlocking
import me.uport.credential_status.CredentialStatus
import me.uport.credential_status.StatusResolver
import me.uport.credential_status.UniversalStatusResolver
import me.uport.credentialstatus.CredentialStatus
import me.uport.credentialstatus.StatusResolver
import me.uport.credentialstatus.UniversalStatusResolver
import me.uport.sdk.ethrdid.EthrDIDDocument
import me.uport.sdk.testhelpers.coAssert
import me.uport.sdk.universaldid.DIDDocument
Expand Down Expand Up @@ -89,4 +89,4 @@ class UniversalStatusResolverTests {
val result = resolver.checkStatus(successfulCred, didDoc)
assertThat(result).isEqualTo(TestStatus(BigInteger.ONE))
}
}
}
13 changes: 13 additions & 0 deletions detekt_baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<SmellBaseline>
<Blacklist></Blacklist>
<Whitelist>
<ID>MaxLineLength:UniversalDID.kt$UniversalDID$ override suspend fun resolve(did: String): DIDDocument</ID>
<ID>MaxLineLength:UniversalDID.kt$UniversalDID$?:</ID>
<ID>MaxLineLength:UniversalDID.kt$UniversalDID$throw IllegalStateException("There is no DIDResolver registered to resolve '$method' DIDs and none of the other ${resolvers.size} registered ones can do it.")</ID>
<ID>MaxLineLength:UportIdentityDocument.kt$UportIdentityDocument$val image: ProfilePicture? = null</ID>
<ID>MaxLineLength:UportIdentityDocument.kt$UportIdentityDocument$val publicEncKey: String? = null</ID>
<ID>MaxLineLength:UportIdentityDocument.kt$UportIdentityDocument$val publicKey: String? = null</ID>
<ID>TooGenericExceptionCaught:UniversalDID.kt$UniversalDID$ex: Exception</ID>
</Whitelist>
</SmellBaseline>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("UndocumentedPublicFunction", "UndocumentedPublicClass")
@file:Suppress("UndocumentedPublicFunction", "UndocumentedPublicClass", "MagicNumber")

package me.uport.sdk.ethrdid

Expand Down
2 changes: 1 addition & 1 deletion ethr-did/src/main/java/me/uport/sdk/ethrdid/EthrDID.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("UndocumentedPublicFunction", "UndocumentedPublicClass")
@file:Suppress("UndocumentedPublicFunction", "UndocumentedPublicClass", "MagicNumber")

package me.uport.sdk.ethrdid

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ fun EthNetwork.toEthrDIDNetwork() =
chainId = networkId,
registryAddress = ethrDidRegistry,
rpc = JsonRPC(rpcUrl)
)
)
22 changes: 15 additions & 7 deletions ethr-did/src/main/java/me/uport/sdk/ethrdid/EthrDIDResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ open class EthrDIDResolver : DIDResolver {
_registryMap[networkIdentifier]
} catch (e: IllegalArgumentException) {
throw IllegalArgumentException(
"Missing registry configuration for `$networkIdentifier`." +
" To resolve did:ethr:$networkIdentifier:0x... you need to register an `EthrDIDNetwork`" +
" in the EthrDIDResolver.Builder"
"Missing registry configuration for `$networkIdentifier`. To resolve " +
"did:ethr:$networkIdentifier:0x... you need to register an `EthrDIDNetwork` " +
"in the EthrDIDResolver.Builder"
)
}

Expand All @@ -114,7 +114,8 @@ open class EthrDIDResolver : DIDResolver {
}

/**
* Obtains the block number when the given identity was last changed, or [BigInteger.ZERO] if no change was ever made
* Obtains the block number when the given identity was last changed, or [BigInteger.ZERO] if
* no change was ever made
*
* @hide
*/
Expand All @@ -129,16 +130,19 @@ open class EthrDIDResolver : DIDResolver {
rpc.ethCall(registryAddress, encodedCall)
} catch (err: JsonRpcException) {
throw DidResolverError(
"Unable to evaluate when or if the $identity was lastChanged because RPC endpoint responded with an error",
"Unable to evaluate when or if the $identity was lastChanged because RPC" +
" endpoint responded with an error",
err
)
}
}

/**
* Builds a simple_list of events associated with the [identity] in the ether-did-registry contract that resides at [registryAddress]
* Builds a simple_list of events associated with the [identity] in the ether-did-registry
* contract that resides at [registryAddress]
*
* Since the Event classes are generated by bivrost-kotlin, they don't have a specific type so the simple_list id of type [Any]
* Since the Event classes are generated by bivrost-kotlin, they don't have a specific type
* so the simple_list id of type [Any]
*
* @hide
*/
Expand Down Expand Up @@ -252,6 +256,7 @@ open class EthrDIDResolver : DIDResolver {
)
}

@Suppress("MagicNumber", "ReturnCount")
internal fun processAttributeChanged(
event: DIDAttributeChanged.Arguments,
delegateCount: Int,
Expand Down Expand Up @@ -329,6 +334,7 @@ open class EthrDIDResolver : DIDResolver {
val key = "DIDDelegateChanged-$delegateType-$delegate"
val validTo = event.validto.value.toLong()

@Suppress("MagicNumber")
if (validTo >= _timeProvider.nowMs() / 1000L) {
delegateIndex++

Expand Down Expand Up @@ -380,6 +386,7 @@ open class EthrDIDResolver : DIDResolver {
private val didParsePattern =
"^(did:)?((\\w+):)?((\\w+):)?((0x)([0-9a-fA-F]{40}))".toRegex()

@Suppress("ReturnCount")
internal fun normalizeDid(did: String): String {
val matchResult = didParsePattern.find(did) ?: return ""
val (didHeader, _, didType, _, network, _, _, hexDigits) = matchResult.destructured
Expand Down Expand Up @@ -413,6 +420,7 @@ open class EthrDIDResolver : DIDResolver {
* Allows the use of a different clock than the system time.
* This is usable for "was valid at" type of queries, and for deterministic checks.
*/
@Suppress("unused")
fun setTimeProvider(timeProvider: ITimeProvider): Builder {
_clock = timeProvider
return this
Expand Down
4 changes: 1 addition & 3 deletions ethr-did/src/test/java/me/uport/sdk/ethrdid/DDOTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,5 @@ class DDOTest {
assertThat {
EthrDIDDocument.fromJson(docText)
}.isSuccess()

}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("UnnecessaryVariable")
@file:Suppress("UnnecessaryVariable", "LargeClass", "LongMethod")

package me.uport.sdk.ethrdid

Expand All @@ -18,6 +18,7 @@ import assertk.assertions.isNotEqualTo
import assertk.assertions.isNotNull
import assertk.assertions.isSuccess
import assertk.assertions.isTrue
import assertk.assertions.message
import io.mockk.coEvery
import io.mockk.mockk
import io.mockk.slot
Expand Down Expand Up @@ -719,6 +720,7 @@ class EthrDIDResolverTest {
resolver.resolve("did:ethr:unknown:0xb9c5714089478a327f09197987f16f9e5d936e8a")
}.isFailure().all {
isInstanceOf(IllegalArgumentException::class)
println(this.message())
hasMessage("Missing registry configuration for `unknown`. To resolve did:ethr:unknown:0x... you need to register an `EthrDIDNetwork` in the EthrDIDResolver.Builder")
}
}
Expand Down
2 changes: 1 addition & 1 deletion ethr-did/src/test/java/me/uport/sdk/ethrdid/EthrDIDTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ class EthrDIDTest {

}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.uport.sdk.ethr_status
package me.uport.sdk.ethrstatus

import me.uport.credential_status.CredentialStatus
import me.uport.credential_status.StatusEntry
import me.uport.credential_status.StatusResolver
import me.uport.credential_status.getStatusEntry
import me.uport.credentialstatus.CredentialStatus
import me.uport.credentialstatus.StatusEntry
import me.uport.credentialstatus.StatusResolver
import me.uport.credentialstatus.getStatusEntry
import me.uport.sdk.core.Networks
import me.uport.sdk.core.hexToBigInteger
import me.uport.sdk.jsonrpc.JsonRPC
Expand Down Expand Up @@ -111,4 +111,4 @@ data class EthrStatus(
* The block number when it was first revoked by the issuer, or [BigInteger.ZERO] if it was never revoked
**/
val blockNumber: BigInteger
) : CredentialStatus
) : CredentialStatus
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:Suppress("UndocumentedPublicFunction", "UndocumentedPublicClass", "unused")

package me.uport.sdk.ethr_status
package me.uport.sdk.ethrstatus

import pm.gnosis.model.Solidity
import pm.gnosis.model.SolidityBase
Expand Down Expand Up @@ -41,4 +41,4 @@ class RevocationContract {

data class Arguments(val issuer: Solidity.Address, val digest: Solidity.Bytes32)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:Suppress("UndocumentedPublicFunction", "UndocumentedPublicClass", "StringLiteralDuplication")

package me.uport.sdk.ethr_status
package me.uport.sdk.ethrstatus

import assertk.all
import assertk.assertThat
Expand Down Expand Up @@ -92,4 +92,4 @@ class EthrStatusResolverTests {
isInstanceOf(IllegalStateException::class)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:Suppress("UndocumentedPublicFunction", "UndocumentedPublicClass", "StringLiteralDuplication")

package me.uport.sdk.ethr_status
package me.uport.sdk.ethrstatus

import assertk.all
import assertk.assertThat
Expand Down Expand Up @@ -64,4 +64,4 @@ class ParseRegistryIdTests {
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:Suppress("UndocumentedPublicFunction", "UndocumentedPublicClass", "StringLiteralDuplication")

package me.uport.sdk.ethr_status
package me.uport.sdk.ethrstatus

import assertk.assertThat
import assertk.assertions.isEqualTo
Expand Down Expand Up @@ -140,4 +140,4 @@ class ValidRevokersTests {
val revokers = ethrStatus.getValidRevokers(didDoc)
assertThat(revokers).isEqualTo(listOf("0x108209f4247b7fe6605b0f58f9145ec3269d0154"))
}
}
}
Loading

0 comments on commit 497cfde

Please sign in to comment.