From c3e41a68c25f889b535592882ecf877da76e1ad0 Mon Sep 17 00:00:00 2001 From: Honza Rychnovsky Date: Mon, 19 Dec 2022 08:08:25 +0100 Subject: [PATCH] [#795] Detekt 1.22.0 * [#795] Detekt 1.22.0 * Fix rules/its findings --- .../android/sdk/demoapp/util/NetworkExt.kt | 1 + gradle.properties | 2 +- .../sdk/internal/db/SQLiteDatabaseExt.kt | 6 +- .../z/ecc/android/sdk/model/BlockHeight.kt | 8 +-- tools/detekt.yml | 65 +++++++++++-------- 5 files changed, 47 insertions(+), 35 deletions(-) diff --git a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/util/NetworkExt.kt b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/util/NetworkExt.kt index 3f8332df..f42c2ee5 100644 --- a/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/util/NetworkExt.kt +++ b/demo-app/src/main/java/cash/z/ecc/android/sdk/demoapp/util/NetworkExt.kt @@ -9,6 +9,7 @@ import java.util.Locale fun ZcashNetwork.Companion.fromResources(context: Context): ZcashNetwork { val networkNameFromResources = context.getString(R.string.network_name).lowercase(Locale.ROOT) + @Suppress("UseRequire") return if (networkNameFromResources == Testnet.networkName) { Testnet } else if (networkNameFromResources.lowercase(Locale.ROOT) == Mainnet.networkName) { diff --git a/gradle.properties b/gradle.properties index aa46c8cc..36ea648b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -75,7 +75,7 @@ ANDROID_COMPILE_SDK_VERSION=33 ANDROID_NDK_VERSION=22.1.7171670 ANDROID_GRADLE_PLUGIN_VERSION=7.3.0 -DETEKT_VERSION=1.21.0 +DETEKT_VERSION=1.22.0 DOKKA_VERSION=1.7.20 EMULATOR_WTF_GRADLE_PLUGIN_VERSION=0.0.12 FLANK_VERSION=22.10.0 diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/db/SQLiteDatabaseExt.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/db/SQLiteDatabaseExt.kt index 10ed9856..deb0f1f4 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/db/SQLiteDatabaseExt.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/db/SQLiteDatabaseExt.kt @@ -32,10 +32,10 @@ internal fun SQLiteDatabase.queryAndMap( cursorParser: CursorParser ) = flow { // TODO [#703]: Support blobs for argument binding - // https://github.com/zcash/zcash-android-wallet-sdk/issues/703 + // TODO [#703]: https://github.com/zcash/zcash-android-wallet-sdk/issues/703 val mappedSelectionArgs = selectionArgs?.onEach { - if (it is ByteArray) { - throw IllegalArgumentException("ByteArray is not supported") + require(it !is ByteArray) { + "ByteArray is not supported" } }?.map { it.toString() }?.toTypedArray() diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/BlockHeight.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/BlockHeight.kt index 8adb9b72..9e66c184 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/BlockHeight.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/BlockHeight.kt @@ -24,16 +24,16 @@ data class BlockHeight internal constructor(val value: Long) : Comparable= 0) { + "Cannot add negative value $other to BlockHeight" } return BlockHeight(value + other.toLong()) } operator fun plus(other: Long): BlockHeight { - if (other < 0) { - throw IllegalArgumentException("Cannot add negative value $other to BlockHeight") + require(other >= 0) { + "Cannot add negative value $other to BlockHeight" } return BlockHeight(value + other) diff --git a/tools/detekt.yml b/tools/detekt.yml index 57340021..45250bb4 100644 --- a/tools/detekt.yml +++ b/tools/detekt.yml @@ -10,6 +10,7 @@ build: config: validation: true warningsAsErrors: false + checkExhaustiveness: false # when writing own rules with new properties, exclude the property path e.g.: 'my_rule_set,.*>.*>[my_property]' excludes: '' @@ -78,15 +79,21 @@ comments: searchInInnerClass: true searchInInnerObject: true searchInInnerInterface: true + searchInProtectedClass: false UndocumentedPublicFunction: active: false excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + searchProtectedFunction: false UndocumentedPublicProperty: active: false excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + searchProtectedProperty: false complexity: active: true + CognitiveComplexMethod: + active: false + threshold: 15 ComplexCondition: active: true threshold: 4 @@ -95,7 +102,8 @@ complexity: threshold: 10 includeStaticDeclarations: false includePrivateDeclarations: false - ComplexMethod: + ignoreOverloaded: false + CyclomaticComplexMethod: active: true threshold: 15 ignoreSingleWhenExpression: false @@ -386,6 +394,8 @@ performance: SpreadOperator: active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + UnnecessaryPartOfBinaryExpression: + active: false UnnecessaryTemporaryInstantiation: active: true @@ -412,8 +422,6 @@ potential-bugs: - 'java.util.HashSet' - 'java.util.LinkedHashMap' - 'java.util.HashMap' - DuplicateCaseInWhenExpression: - active: true ElseCaseInsteadOfExhaustiveWhen: active: false EqualsAlwaysReturnsTrueOrFalse: @@ -428,12 +436,16 @@ potential-bugs: active: true IgnoredReturnValue: active: true - restrictToAnnotatedMethods: true + restrictToConfig: true returnValueAnnotations: - '*.CheckResult' - '*.CheckReturnValue' ignoreReturnValueAnnotations: - '*.CanIgnoreReturnValue' + returnValueTypes: + - 'kotlin.sequences.Sequence' + - 'kotlinx.coroutines.flow.*Flow' + - 'java.util.stream.*Stream' ignoreFunctionCall: [] ImplicitDefaultLocale: active: true @@ -455,17 +467,14 @@ potential-bugs: MissingPackageDeclaration: active: false excludes: ['**/*.kts'] - MissingWhenCase: - active: true - allowElseExpression: true NullCheckOnMutableProperty: active: false NullableToStringCall: active: false - RedundantElseInWhen: - active: true UnconditionalJumpStatementInLoop: active: false + UnnecessaryNotNullCheck: + active: false UnnecessaryNotNullOperator: active: true UnnecessarySafeCall: @@ -488,6 +497,8 @@ potential-bugs: style: active: true + AlsoCouldBeApply: + active: false CanBeNonNullable: active: false CascadingCallWrapping: @@ -499,7 +510,8 @@ style: active: false DataClassContainsFunctions: active: false - conversionFunctionPrefix: 'to' + conversionFunctionPrefix: + - 'to' DataClassShouldBeImmutable: active: false DestructuringDeclarationWithTooManyEntries: @@ -531,14 +543,10 @@ style: ForbiddenMethodCall: active: false methods: - - 'kotlin.io.print' - - 'kotlin.io.println' - ForbiddenPublicDataClass: - active: true - excludes: ['**'] - ignorePackages: - - '*.internal' - - '*.internal.*' + - reason: 'print does not allow you to configure the output stream. Use a logger instead.' + value: 'kotlin.io.print' + - reason: 'println does not allow you to configure the output stream. Use a logger instead.' + value: 'kotlin.io.println' ForbiddenSuppress: active: false rules: [] @@ -550,13 +558,7 @@ style: active: true ignoreOverridableFunction: true ignoreActualFunction: true - excludedFunctions: '' - LibraryCodeMustSpecifyReturnType: - active: true - excludes: ['**'] - LibraryEntitiesShouldNotBePublic: - active: true - excludes: ['**'] + excludedFunctions: [] LoopWithTooManyJumpStatements: active: true maxJumpCount: 1 @@ -591,12 +593,16 @@ style: excludePackageStatements: true excludeImportStatements: true excludeCommentStatements: false + excludeRawStrings: true MayBeConst: active: true ModifierOrder: active: true MultilineLambdaItParameter: active: false + MultilineRawStringIndentation: + active: false + indentSize: 4 NestedClassesVisibility: active: true NewLineAtEndOfFile: @@ -626,7 +632,8 @@ style: ReturnCount: active: true max: 2 - excludedFunctions: 'equals' + excludedFunctions: + - 'equals' excludeLabeled: false excludeReturnFromLambda: true excludeGuardClauses: false @@ -642,6 +649,8 @@ style: excludeGuardClauses: false TrailingWhitespace: active: false + TrimMultilineRawString: + active: false UnderscoresInNumericLiterals: active: false acceptableLength: 4 @@ -664,6 +673,7 @@ style: active: false UnnecessaryParentheses: active: false + allowForUnclearPrecedence: false UntilInsteadOfRangeTo: active: false UnusedImports: @@ -698,6 +708,8 @@ style: active: true UseRequireNotNull: active: true + UseSumOfInsteadOfFlatMapSize: + active: false UselessCallOnNotNull: active: true UtilityClassWithPublicConstructor: @@ -707,6 +719,5 @@ style: ignoreLateinitVar: false WildcardImport: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] excludeImports: - 'java.util.*'