diff --git a/detekt.yml b/detekt.yml index b5534fe8..87873f46 100644 --- a/detekt.yml +++ b/detekt.yml @@ -1,4 +1,4 @@ -# https://github.com/detekt/detekt/blob/v1.14.2/detekt-core/src/main/resources/default-detekt-config.yml +# https://github.com/detekt/detekt/blob/v1.17.1/detekt-core/src/main/resources/default-detekt-config.yml comments: active: false @@ -36,6 +36,8 @@ complexity: ignoreAnnotated: [] MethodOverloading: active: false + NamedArguments: + active: false NestedBlockDepth: active: true threshold: 4 @@ -66,6 +68,8 @@ coroutines: active: false RedundantSuspendModifier: active: true + SleepInsteadOfDelay: + active: true SuspendFunWithFlowReturnType: active: true @@ -113,8 +117,10 @@ exceptions: active: false NotImplementedDeclaration: active: true + ObjectExtendsThrowable: + active: true PrintStackTrace: - active: false + active: true RethrowCaughtException: active: false ReturnFromFinally: @@ -179,11 +185,13 @@ formatting: ImportOrdering: active: true autoCorrect: true - layout: 'idea' + layout: '*,java.**,javax.**,kotlin.**,^' Indentation: active: false MaximumLineLength: - active: false + active: true + maxLineLength: 120 + ignoreBackTickedIdentifier: false ModifierOrdering: active: true autoCorrect: true @@ -229,6 +237,9 @@ formatting: autoCorrect: true ParameterListWrapping: active: false + SpacingAroundAngleBrackets: + active: true + autoCorrect: true SpacingAroundColon: active: true autoCorrect: true @@ -256,6 +267,9 @@ formatting: SpacingAroundRangeOperator: active: true autoCorrect: true + SpacingAroundUnaryOperator: + active: true + autoCorrect: true SpacingBetweenDeclarationsWithAnnotations: active: false SpacingBetweenDeclarationsWithComments: @@ -306,12 +320,15 @@ naming: ignoreOverridden: true InvalidPackageDeclaration: active: true + excludes: ['buildSrc/**', '**/*.kts'] rootPackage: '' MatchingDeclarationName: active: true mustBeFirst: true MemberNameEqualsClassName: active: false + NoNameShadowing: + active: true NonBooleanPropertyPrefixedWithIs: active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] @@ -327,7 +344,7 @@ naming: packagePattern: '[a-z]+(\.[a-z][A-Za-z0-9]*)*' TopLevelPropertyNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['buildSrc/**', '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] constantPattern: '[A-Z][_A-Z0-9]*' propertyPattern: '[A-Za-z][_A-Za-z0-9]*' privatePropertyPattern: '_?[A-Za-z][_A-Za-z0-9]*' @@ -359,14 +376,22 @@ performance: potential-bugs: active: true + CastToNullableType: + active: false Deprecation: active: true + DontDowncastCollectionTypes: + active: true + DoubleMutabilityForCollection: + active: true DuplicateCaseInWhenExpression: active: true EqualsAlwaysReturnsTrueOrFalse: active: true EqualsWithHashCodeExist: active: true + ExitOutsideMain: + active: true ExplicitGarbageCollectionCall: active: true HasPlatformType: @@ -398,15 +423,19 @@ potential-bugs: UnconditionalJumpStatementInLoop: active: true UnnecessaryNotNullOperator: - active: false + active: true UnnecessarySafeCall: - active: false + active: true + UnreachableCatchBlock: + active: true UnreachableCode: active: true UnsafeCallOnNullableType: active: true UnsafeCast: - active: false + active: true + UnusedUnaryOperator: + active: true UselessPostfixExpression: active: true WrongEqualsTypeParameter: @@ -422,6 +451,8 @@ style: active: false DataClassShouldBeImmutable: active: false + DestructuringDeclarationWithTooManyEntries: + active: false EqualsNullCall: active: true EqualsOnSignatureLine: @@ -446,6 +477,7 @@ style: methods: ['kotlin.io.println', 'kotlin.io.print'] ForbiddenPublicDataClass: active: true + excludes: ['**'] ignorePackages: ['*.internal', '*.internal.*'] ForbiddenVoid: active: true @@ -454,12 +486,15 @@ style: FunctionOnlyReturningConstant: active: true ignoreOverridableFunction: true + ignoreActualFunction: true excludedFunctions: 'describeContents' excludeAnnotatedFunction: ['dagger.Provides'] LibraryCodeMustSpecifyReturnType: active: true + excludes: ['**'] LibraryEntitiesShouldNotBePublic: active: true + excludes: ['**'] LoopWithTooManyJumpStatements: active: true maxJumpCount: 1 @@ -479,12 +514,16 @@ style: active: true ModifierOrder: active: true + MultilineLambdaItParameter: + active: false NestedClassesVisibility: active: true NewLineAtEndOfFile: active: true NoTabs: active: true + ObjectLiteralToLambda: + active: true OptionalAbstractKeyword: active: true OptionalUnit: @@ -497,6 +536,8 @@ style: active: true RedundantExplicitType: active: true + RedundantHigherOrderMapUsage: + active: true RedundantVisibilityModifierRule: active: true ReturnCount: @@ -520,6 +561,8 @@ style: active: true UnnecessaryApply: active: true + UnnecessaryFilter: + active: true UnnecessaryInheritance: active: true UnnecessaryLet: @@ -545,8 +588,14 @@ style: active: false UseEmptyCounterpart: active: true + UseIfEmptyOrIfBlank: + active: true UseIfInsteadOfWhen: active: false + UseIsNullOrEmpty: + active: true + UseOrEmpty: + active: true UseRequire: active: true UseRequireNotNull: diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt index 6eb9ae62..7853b199 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt @@ -29,21 +29,19 @@ value class MacAddressCompat(val addr: Long) { * @return the MacAddress corresponding to the given byte array representation. * @throws IllegalArgumentException if the given byte array is not a valid representation. */ - fun fromBytes(addr: ByteArray) = ByteBuffer.allocate(Long.SIZE_BYTES).run { - order(ByteOrder.LITTLE_ENDIAN) - put(when (addr.size) { - ETHER_ADDR_LEN -> addr + fun fromBytes(addr: ByteArray): MacAddressCompat { + val buffer = when (addr.size) { + ETHER_ADDR_LEN -> ByteBuffer.allocate(Long.SIZE_BYTES).order(ByteOrder.LITTLE_ENDIAN).put(addr) 8 -> { require(addr.take(2).all { it == 0.toByte() }) { "Unrecognized padding " + addr.joinToString(":") { "%02x".format(it) } } - addr.drop(2).toByteArray() + ByteBuffer.allocate(Long.SIZE_BYTES).order(ByteOrder.LITTLE_ENDIAN).put(addr, 2, ETHER_ADDR_LEN) } - else -> throw IllegalArgumentException(addr.joinToString(":") { "%02x".format(it) } + - " was not a valid MAC address") - }) - rewind() - MacAddressCompat(long) + else -> return fromString(String(addr)) + } + buffer.rewind() + return MacAddressCompat(buffer.long) } /** * Creates a MacAddress from the given String representation. A valid String representation diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt index 6597cb9e..9f0739fd 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt @@ -63,7 +63,7 @@ object DefaultNetworkMonitor : UpstreamMonitor() { } else -> try { Services.connectivity.requestNetwork(networkRequest, networkCallback) - } catch (e: SecurityException) { + } catch (e: RuntimeException) { // SecurityException would be thrown in requestNetwork on Android 6.0 thanks to Google's stupid bug if (Build.VERSION.SDK_INT != 23) throw e GlobalScope.launch { callback.onFallback() }