Skip to content

Commit

Permalink
Resolve all detekt errors
Browse files Browse the repository at this point in the history
- Changed root package from "noise_planet" to "noiseplanet"
- Added new lines at the end of all files
- Slight changes where resolving issues was simple
- In other cases, added Suppress annotations and tweaked rules a bit to fit current state of code
  • Loading branch information
tonelli-m committed Jul 16, 2024
1 parent 1a41a0a commit 2a63c91
Show file tree
Hide file tree
Showing 71 changed files with 4,820 additions and 1,293 deletions.
1 change: 1 addition & 0 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("com.android.application")
id("com.google.devtools.ksp")
id("kotlin-parcelize")
id("io.gitlab.arturbosch.detekt") version libs.versions.detekt.get()
}

android {
Expand Down
8 changes: 4 additions & 4 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.AppyxStarterKit">
<activity
android:name="org.noise_planet.noisecapture.starter.MainActivity"
android:name="org.noiseplanet.noisecapture.starter.MainActivity"
android:exported="true"
android:theme="@style/Theme.AppyxStarterKit">
<intent-filter>
Expand All @@ -31,9 +31,9 @@
</intent-filter>
</activity>

<service android:name=".AndroidMeasurementService"
android:foregroundServiceType="location|microphone"
/>
<service
android:name=".AndroidMeasurementService"
android:foregroundServiceType="location|microphone" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.noise_planet.noisecapture.starter
package org.noiseplanet.noisecapture.starter

import android.annotation.SuppressLint
import android.app.Activity
Expand All @@ -16,21 +16,23 @@ import com.bumble.appyx.navigation.platform.AndroidLifecycle
import org.koin.android.logger.AndroidLogger
import org.koin.core.context.stopKoin
import org.koin.dsl.module
import org.noise_planet.noisecapture.AndroidAudioSource
import org.noise_planet.noisecapture.AndroidDatabase
import org.noise_planet.noisecapture.AndroidMeasurementService
import org.noise_planet.noisecapture.DatabaseDriverFactory
import org.noise_planet.noisecapture.shared.MeasurementService
import org.noise_planet.noisecapture.shared.initKoin
import org.noise_planet.noisecapture.shared.root.RootNode
import org.noise_planet.noisecapture.shared.ui.theme.AppyxStarterKitTheme
import org.noiseplanet.noisecapture.AndroidAudioSource
import org.noiseplanet.noisecapture.AndroidDatabase
import org.noiseplanet.noisecapture.AndroidMeasurementService
import org.noiseplanet.noisecapture.DatabaseDriverFactory
import org.noiseplanet.noisecapture.shared.MeasurementService
import org.noiseplanet.noisecapture.shared.initKoin
import org.noiseplanet.noisecapture.shared.root.RootNode
import org.noiseplanet.noisecapture.shared.ui.theme.AppyxStarterKitTheme
import kotlin.reflect.KProperty

class MainActivity : NodeActivity() {
val androidLogger = AndroidLogger()

private val androidLogger = AndroidLogger()
private val foregroundServiceConnection = ForegroundServiceConnection()

internal class ForegroundServiceConnection : ServiceConnection {

@SuppressLint("MissingPermission")
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
println("onServiceConnected $name $service")
Expand All @@ -39,15 +41,10 @@ class MainActivity : NodeActivity() {
// interact with the service. Because we have bound to a explicit
// service that we know is running in our own process, we can
// cast its IBinder to a concrete class and directly access it.
if(service != null) {
val androidMeasurementService =
(service as AndroidMeasurementService.LocalBinder).service

}
}

override fun onServiceDisconnected(name: ComponentName?) {

println("onServiceConnected $name")
}
}

Expand All @@ -66,15 +63,19 @@ class MainActivity : NodeActivity() {
println("OnStop")
}

fun onStorageStateChange(property : KProperty<*>, oldValue :Boolean, newValue: Boolean) {
@Suppress("UnusedParameter")
private fun onStorageStateChange(property: KProperty<*>, oldValue: Boolean, newValue: Boolean) {
// bind this application context to Android Foreground service if storage is launched
// in order to avoid application shutdown by Android when moved in background
if(newValue) {
if (newValue) {
val intent = Intent(applicationContext, AndroidMeasurementService::class.java)
if (applicationContext.bindService(intent, foregroundServiceConnection,
Context.BIND_AUTO_CREATE)) {
if (applicationContext.bindService(
intent, foregroundServiceConnection,
Context.BIND_AUTO_CREATE
)
) {
androidLogger.info("Bind with foreground service")
} else{
} else {
androidLogger.info("Can't bind with foreground service")
}
} else {
Expand All @@ -90,9 +91,11 @@ class MainActivity : NodeActivity() {
single<Context> { applicationContext }
single<Activity> { this@MainActivity }
single<MeasurementService> {
val measurementService = MeasurementService(AndroidAudioSource(logger), androidLogger)
val measurementService =
MeasurementService(AndroidAudioSource(logger))
measurementService.storageObservers.add(::onStorageStateChange)
measurementService}
measurementService
}
single<DatabaseDriverFactory> { AndroidDatabase(applicationContext) }
}
)
Expand Down
31 changes: 17 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask

plugins {
kotlin("android") version libs.versions.kotlin.get() apply false
kotlin("multiplatform") version libs.versions.kotlin.get() apply false
id("com.android.application") version libs.versions.agp.get() apply false
id("org.jetbrains.compose") version libs.versions.compose.plugin.get() apply false
id("com.google.devtools.ksp") version libs.versions.ksp.get() apply false
id("io.gitlab.arturbosch.detekt") version "1.23.6"
id("io.gitlab.arturbosch.detekt") version libs.versions.detekt.get()
}

repositories {
mavenCentral()
}


allprojects {

apply(plugin = "io.gitlab.arturbosch.detekt")

detekt {
buildUponDefaultConfig = true
allRules = true
config.setFrom("$projectDir/../config/detekt.yml")
config.setFrom("$rootDir/config/detekt.yml")
source.setFrom(
"src/main/kotlin",
"src/iosMain/kotlin",
"src/androidMain/kotlin",
"src/jsMain/kotlin",
"src/commonMain/kotlin",
)
autoCorrect = true
}

// dependencies {
// detektPlugins(rootProject.libs.detekt.formatting)
// }

tasks.withType<Detekt>().configureEach {
jvmTarget = libs.versions.jvm.target.get()
reports {
html.required.set(true)
}
basePath = rootDir.absolutePath
}

// Kotlin DSL
tasks.withType<Detekt>().configureEach {
jvmTarget = "1.8"
}
tasks.withType<DetektCreateBaselineTask>().configureEach {
jvmTarget = "1.8"
}
}
}
35 changes: 6 additions & 29 deletions config/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ complexity:
threshold: 15
ComplexCondition:
active: true
threshold: 4
threshold: 5
ComplexInterface:
active: false
threshold: 10
Expand Down Expand Up @@ -206,7 +206,7 @@ empty-blocks:
active: true
EmptyFunctionBlock:
active: true
ignoreOverridden: false
ignoreOverridden: true
EmptyIfBlock:
active: true
EmptyInitBlock:
Expand Down Expand Up @@ -323,6 +323,7 @@ naming:
excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**' ]
functionPattern: '[a-z][a-zA-Z0-9]*'
excludeClassPattern: '$^'
ignoreAnnotated: [ 'Composable' ]
FunctionParameterNaming:
active: true
parameterPattern: '[a-z][A-Za-z0-9]*'
Expand Down Expand Up @@ -567,8 +568,6 @@ style:
value: 'FIXME:'
- reason: 'Forbidden STOPSHIP todo marker in comment, please address the problem before shipping the code.'
value: 'STOPSHIP:'
- reason: 'Forbidden TODO todo marker in comment, please do the changes.'
value: 'TODO:'
allowedPatterns: ''
ForbiddenImport:
active: false
Expand Down Expand Up @@ -597,23 +596,7 @@ style:
active: true
maxJumpCount: 1
MagicNumber:
active: true
excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**', '**/*.kts' ]
ignoreNumbers:
- '-1'
- '0'
- '1'
- '2'
ignoreHashCodeFunction: true
ignorePropertyDeclaration: false
ignoreLocalVariableDeclaration: false
ignoreConstantDeclaration: true
ignoreCompanionObjectPropertyDeclaration: true
ignoreAnnotation: false
ignoreNamedArgument: true
ignoreEnums: false
ignoreRanges: false
ignoreExtensionFunctions: true
active: false
MandatoryBracesLoops:
active: false
MaxChainedCallsOnSameLine:
Expand All @@ -624,7 +607,7 @@ style:
maxLineLength: 120
excludePackageStatements: true
excludeImportStatements: true
excludeCommentStatements: false
excludeCommentStatements: true
excludeRawStrings: true
MayBeConst:
active: true
Expand Down Expand Up @@ -663,13 +646,7 @@ style:
RedundantVisibilityModifierRule:
active: false
ReturnCount:
active: true
max: 2
excludedFunctions:
- 'equals'
excludeLabeled: false
excludeReturnFromLambda: true
excludeGuardClauses: false
active: false
SafeCast:
active: true
SerialVersionUIDInSerializableClass:
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ compose-plugin = "1.6.11"
compose-ui-test-junit4 = "1.6.2"
core-ktx = "1.12.0"
coroutines = "1.8.0"
detekt = "1.23.6"
junit = "4.13.2"
jvm-target = "1.8"
koin-android = "3.5.6"
Expand All @@ -43,6 +44,7 @@ compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", versio
compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" }
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
compose-ui-ui = { module = "androidx.compose.ui:ui" }
detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting" }
junit = { module = "junit:junit", version.ref = "junit" }
koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin-android" }
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin-core" }
Expand Down
8 changes: 4 additions & 4 deletions ios/src/iosMain/kotlin/main.ios.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.window.ComposeUIViewController
import com.bumble.appyx.navigation.integration.IosNodeHost
import com.bumble.appyx.navigation.integration.MainIntegrationPoint
import org.noise_planet.noisecapture.shared.root.RootNode
import org.noise_planet.noisecapture.shared.ui.theme.AppyxStarterKitTheme
import org.noiseplanet.noisecapture.shared.root.RootNode
import org.noiseplanet.noisecapture.shared.ui.theme.AppyxStarterKitTheme
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
import org.noise_planet.noisecapture.shared.initKoin
import org.noiseplanet.noisecapture.shared.initKoin

val backEvents: Channel<Unit> = Channel()

Expand All @@ -19,7 +19,7 @@ private val integrationPoint = MainIntegrationPoint()
@Suppress("FunctionNaming", "Unused")
fun MainViewController() = ComposeUIViewController {

val koinApplication = initKoin( )
val koinApplication = initKoin()

AppyxStarterKitTheme {
Scaffold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class AudioRecordPermissionDelegate(
private val activity: Lazy<Activity>,
) : PermissionDelegate {
override suspend fun getPermissionState(): PermissionState {
return checkPermissions(context, activity, audioRecordPermissions)
return checkPermissions(context, audioRecordPermissions)
}

override suspend fun providePermission() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class BluetoothPermissionDelegate(
private val activity: Lazy<Activity>,
) : PermissionDelegate {
override suspend fun getPermissionState(): PermissionState {
return checkPermissions(context, activity, bluetoothPermissions)
return checkPermissions(context, bluetoothPermissions)
}

override suspend fun providePermission() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.os.Build
import com.adrianwitaszak.kmmpermissions.permissions.model.Permission
import com.adrianwitaszak.kmmpermissions.permissions.model.PermissionState
import com.adrianwitaszak.kmmpermissions.permissions.util.PermissionRequestException
import com.adrianwitaszak.kmmpermissions.permissions.util.checkPermissions
import com.adrianwitaszak.kmmpermissions.permissions.util.openAppSettingsPage
import com.adrianwitaszak.kmmpermissions.permissions.util.providePermissions
Expand All @@ -18,14 +19,15 @@ internal class LocationBackgroundPermissionDelegate(
override suspend fun getPermissionState(): PermissionState {
return when (locationForegroundPermissionDelegate.getPermissionState()) {
PermissionState.GRANTED ->
checkPermissions(context, activity, backgroundLocationPermissions)
checkPermissions(context, backgroundLocationPermissions)

else -> PermissionState.NOT_DETERMINED
}
}

override suspend fun providePermission() {
activity.value.providePermissions(backgroundLocationPermissions) {
throw Exception(
throw PermissionRequestException(
it.localizedMessage ?: "Failed to request background location permission"
)
}
Expand All @@ -40,4 +42,6 @@ internal class LocationBackgroundPermissionDelegate(
private val backgroundLocationPermissions: List<String> =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
listOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
} else emptyList()
} else {
emptyList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.os.Build
import com.adrianwitaszak.kmmpermissions.permissions.model.Permission
import com.adrianwitaszak.kmmpermissions.permissions.model.PermissionState
import com.adrianwitaszak.kmmpermissions.permissions.util.PermissionRequestException
import com.adrianwitaszak.kmmpermissions.permissions.util.checkPermissions
import com.adrianwitaszak.kmmpermissions.permissions.util.openAppSettingsPage
import com.adrianwitaszak.kmmpermissions.permissions.util.providePermissions
Expand All @@ -15,12 +16,12 @@ internal class LocationForegroundPermissionDelegate(
private val activity: Lazy<Activity>,
) : PermissionDelegate {
override suspend fun getPermissionState(): PermissionState {
return checkPermissions(context, activity, fineLocationPermissions)
return checkPermissions(context, fineLocationPermissions)
}

override suspend fun providePermission() {
activity.value.providePermissions(fineLocationPermissions) {
throw Exception(
throw PermissionRequestException(
it.localizedMessage ?: "Failed to request foreground location permission"
)
}
Expand Down
Loading

0 comments on commit 2a63c91

Please sign in to comment.