From 1836f53d7b46b9124939f03d7df1429017fba78d Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Thu, 17 Jul 2025 22:45:52 +0200 Subject: [PATCH] Fix some inspection issues --- .../main/kotlin/ch/dissem/android/MainActivity.kt | 3 +-- .../kotlin/ch/dissem/yaep/ui/common/App.android.kt | 2 +- .../kotlin/ch/dissem/yaep/ui/common/App.kt | 10 +++++----- .../dissem/yaep/ui/common/adaptive game layout.kt | 8 ++++---- .../kotlin/ch/dissem/yaep/ui/common/App.jvm.kt | 2 +- .../main/kotlin/ch/dissem/yaep/ui/desktop/main.kt | 3 +-- .../kotlin/ch/dissem/yaep/domain/Game.kt | 7 ++++--- .../kotlin/ch/dissem/yaep/domain/GameCell.kt | 3 --- .../kotlin/ch/dissem/yaep/domain/GameRow.kt | 2 ++ .../kotlin/ch/dissem/yaep/domain/Grid.kt | 4 ++-- .../kotlin/ch/dissem/yaep/domain/ObservableSet.kt | 1 + .../kotlin/ch/dissem/yaep/domain/clues.kt | 8 ++++---- .../kotlin/ch/dissem/yaep/domain/items.kt | 14 +++++++------- .../kotlin/ch/dissem/yaep/domain/ClueTest.kt | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- 15 files changed, 36 insertions(+), 37 deletions(-) diff --git a/android/src/main/kotlin/ch/dissem/android/MainActivity.kt b/android/src/main/kotlin/ch/dissem/android/MainActivity.kt index 5418057..7934fdc 100644 --- a/android/src/main/kotlin/ch/dissem/android/MainActivity.kt +++ b/android/src/main/kotlin/ch/dissem/android/MainActivity.kt @@ -18,7 +18,6 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import ch.dissem.yaep.domain.Game import ch.dissem.yaep.domain.generateGame import ch.dissem.yaep.ui.common.App import org.jetbrains.compose.resources.painterResource @@ -34,7 +33,7 @@ class MainActivity : ComponentActivity() { super.onCreate(savedInstanceState) setContent { - var game by remember { mutableStateOf(generateGame()) } + var game by remember { mutableStateOf(generateGame()) } var resetCluesBeacon by remember { mutableStateOf(Any()) } Scaffold( diff --git a/commonUI/src/androidMain/kotlin/ch/dissem/yaep/ui/common/App.android.kt b/commonUI/src/androidMain/kotlin/ch/dissem/yaep/ui/common/App.android.kt index da6a7ab..a0d195f 100644 --- a/commonUI/src/androidMain/kotlin/ch/dissem/yaep/ui/common/App.android.kt +++ b/commonUI/src/androidMain/kotlin/ch/dissem/yaep/ui/common/App.android.kt @@ -4,7 +4,7 @@ import ch.dissem.yaep.domain.Game import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.CoroutineScope -val log = KotlinLogging.logger {} +private val log = KotlinLogging.logger {} actual fun CoroutineScope.logGame(game: Game) { log.debug { "Game: $game" } diff --git a/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/App.kt b/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/App.kt index 8a741f8..ae202a6 100644 --- a/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/App.kt +++ b/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/App.kt @@ -180,17 +180,17 @@ fun PuzzleGrid( item.options.add(it) }, selectedItem = selection, - onSelectItem = { - if (it != null) { + onSelectItem = { selectedItem -> + if (selectedItem != null) { grid.snapshot() - item.selection = it + item.selection = selectedItem row.cleanupOptions() } else { while (item.selection != null) { if (!grid.undo()) break } - options.forEach { - it.enabled = item.options.contains(it.item) + options.forEach { option -> + option.enabled = item.options.contains(option.item) } } } diff --git a/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/adaptive game layout.kt b/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/adaptive game layout.kt index f3b219f..f446f55 100644 --- a/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/adaptive game layout.kt +++ b/commonUI/src/commonMain/kotlin/ch/dissem/yaep/ui/common/adaptive game layout.kt @@ -22,14 +22,14 @@ private enum class AspectRatio { PORTRAIT, LANDSCAPE, SQUARISH; companion object { - private const val landscapeRatio = 1.4f - private const val portraitRatio = 1 / landscapeRatio + private const val ASPECT_RATIO_LANDSCAPE = 1.4f + private const val ASPECT_RATIO_PORTRAIT = 1 / ASPECT_RATIO_LANDSCAPE fun from(constraints: Constraints): AspectRatio { val ratio = constraints.maxWidth.toFloat() / constraints.maxHeight.toFloat() return when { - ratio < portraitRatio -> PORTRAIT - ratio > landscapeRatio -> LANDSCAPE + ratio < ASPECT_RATIO_PORTRAIT -> PORTRAIT + ratio > ASPECT_RATIO_LANDSCAPE -> LANDSCAPE else -> SQUARISH } } diff --git a/commonUI/src/jvmMain/kotlin/ch/dissem/yaep/ui/common/App.jvm.kt b/commonUI/src/jvmMain/kotlin/ch/dissem/yaep/ui/common/App.jvm.kt index 791eb6b..e1ea328 100644 --- a/commonUI/src/jvmMain/kotlin/ch/dissem/yaep/ui/common/App.jvm.kt +++ b/commonUI/src/jvmMain/kotlin/ch/dissem/yaep/ui/common/App.jvm.kt @@ -12,7 +12,7 @@ import kotlin.io.path.writeText import kotlin.time.Clock import kotlin.time.ExperimentalTime -val log = KotlinLogging.logger {} +private val log = KotlinLogging.logger {} @OptIn(ExperimentalTime::class) actual fun CoroutineScope.logGame(game: Game) { diff --git a/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/main.kt b/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/main.kt index 3ea59ae..0c2b3c9 100644 --- a/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/main.kt +++ b/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/main.kt @@ -16,7 +16,6 @@ import androidx.compose.ui.window.Window import androidx.compose.ui.window.WindowPlacement import androidx.compose.ui.window.application import androidx.compose.ui.window.rememberWindowState -import ch.dissem.yaep.domain.Game import ch.dissem.yaep.domain.generateGame import ch.dissem.yaep.ui.common.App import ch.dissem.yaep.ui.common.theme.emojiFontFamily @@ -39,7 +38,7 @@ fun main(): Unit = application { placement = WindowPlacement.Floating, size = DpSize(1250.dp, 800.dp) ) - var game by remember { mutableStateOf(generateGame()) } + var game by remember { mutableStateOf(generateGame()) } Window( onCloseRequest = ::exitApplication, diff --git a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/Game.kt b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/Game.kt index fe480b2..fe4d8f3 100644 --- a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/Game.kt +++ b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/Game.kt @@ -6,9 +6,10 @@ class Game( val grid: Grid, val clues: Collection ) { - val log = KotlinLogging.logger { } - val horizontalClues = clues.filterIsInstance() - val verticalClues = clues.filterIsInstance, ItemClass<*>>>() + private val log = KotlinLogging.logger { } + val horizontalClues: List = clues.filterIsInstance() + val verticalClues: List, ItemClass<*>>> = + clues.filterIsInstance, ItemClass<*>>>() private val onStartListeners = mutableListOf<() -> Unit>() private val onSolvedListeners = mutableListOf<() -> Unit>() diff --git a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/GameCell.kt b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/GameCell.kt index 3db325b..e5aada4 100644 --- a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/GameCell.kt +++ b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/GameCell.kt @@ -44,9 +44,6 @@ fun > GameCell?.mayBe(item: Item, mayHaveSelection: Boole this != null && ((mayHaveSelection && selection == item) || (selection == null && options.contains(item))) -fun > GameCell?.isA(item: Item): Boolean = - this != null && selection == item - fun > GameCell?.hasNoSelection(): Boolean = this != null && this.selection == null diff --git a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/GameRow.kt b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/GameRow.kt index 2bed349..3befc53 100644 --- a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/GameRow.kt +++ b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/GameRow.kt @@ -1,5 +1,6 @@ package ch.dissem.yaep.domain +@Suppress("JavaDefaultMethodsNotOverriddenByDelegation") class GameRow>( val category: ItemClassCompanion, val options: List>, @@ -79,4 +80,5 @@ class GameRow>( } return didChange } + } diff --git a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/Grid.kt b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/Grid.kt index 270f4ae..4da05a8 100644 --- a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/Grid.kt +++ b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/Grid.kt @@ -1,6 +1,6 @@ package ch.dissem.yaep.domain -@Suppress("UNCHECKED_CAST") +@Suppress("UNCHECKED_CAST", "JavaDefaultMethodsNotOverriddenByDelegation") class Grid( val rows: List> ) : List>> by rows as List>> { @@ -41,7 +41,7 @@ class Grid( } } -fun List>>>.toGrid() = Grid( +fun List>>>.toGrid(): Grid = Grid( map { row -> GameRow( category = row.first().itemType.companion, diff --git a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/ObservableSet.kt b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/ObservableSet.kt index 0c43351..72f58d5 100644 --- a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/ObservableSet.kt +++ b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/ObservableSet.kt @@ -1,5 +1,6 @@ package ch.dissem.yaep.domain +@Suppress("JavaDefaultMethodsNotOverriddenByDelegation") class ObservableSet private constructor( private val mutableSet: MutableSet, private val onElementChanged: (before: Set, after: Set) -> Unit diff --git a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/clues.kt b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/clues.kt index c732318..0f19db0 100644 --- a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/clues.kt +++ b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/clues.kt @@ -85,7 +85,7 @@ class NeighbourClue, B : ItemClass>(val a: Item, val b: I return removed } - override fun toString() = "$aType is next to $bType" + override fun toString(): String = "$aType is next to $bType" companion object : ClueParser { override fun > parse( @@ -147,7 +147,7 @@ class OrderClue, R : ItemClass>(val left: Item, val right return removed } - override fun toString() = "$leftType is left of $rightType" + override fun toString(): String = "$leftType is left of $rightType" companion object : ClueParser { override fun > parse( @@ -377,7 +377,7 @@ class SameColumnClue, B : ItemClass>(val a: Item, val b: } class PositionClue>(val item: Item, val index: Int) : Clue() { - val itemType = item.itemType + val itemType: C = item.itemType override fun isValid(grid: Grid): Boolean { val i = grid.indexOf(item.itemType) @@ -401,7 +401,7 @@ class PositionClue>(val item: Item, val index: Int) : Clue() return removed } - override fun toString() = "$itemType is at position $index" + override fun toString(): String = "$itemType is at position $index" companion object : ClueParser { override fun > parse( diff --git a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/items.kt b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/items.kt index 9ee3157..86a309d 100644 --- a/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/items.kt +++ b/domain/src/commonMain/kotlin/ch/dissem/yaep/domain/items.kt @@ -11,7 +11,7 @@ enum class Animal(symbol: String) : ItemClass { override val symbols: Array = arrayOf(symbol) - override val companion + override val companion: Animal.Companion get() = Animal companion object : ItemClassCompanion { @@ -31,7 +31,7 @@ enum class Nationality(symbol: String) : ItemClass { override val symbols: Array = arrayOf(symbol) - override val companion + override val companion: Nationality.Companion get() = Nationality companion object : ItemClassCompanion { @@ -50,7 +50,7 @@ enum class Drink(symbol: String) : ItemClass { override val symbols: Array = arrayOf(symbol) - override val companion + override val companion: Drink.Companion get() = Drink companion object : ItemClassCompanion { @@ -70,7 +70,7 @@ enum class Profession(symbol: String) : ItemClass { override val symbols: Array = idic(symbol) - override val companion + override val companion: Profession.Companion get() = Profession companion object : ItemClassCompanion { @@ -92,7 +92,7 @@ enum class Fruit(symbol: String) : ItemClass { override val symbols: Array = arrayOf(symbol) - override val companion + override val companion: Fruit.Companion get() = Fruit companion object : ItemClassCompanion { @@ -113,7 +113,7 @@ enum class Dessert(symbol: String) : ItemClass { override val symbols: Array = arrayOf(symbol) - override val companion + override val companion: Dessert.Companion get() = Dessert companion object : ItemClassCompanion { @@ -132,7 +132,7 @@ enum class Transportation(symbol: String) : ItemClass { override val symbols: Array = arrayOf(symbol) - override val companion + override val companion: Transportation.Companion get() = Transportation companion object : ItemClassCompanion { diff --git a/domain/src/commonTest/kotlin/ch/dissem/yaep/domain/ClueTest.kt b/domain/src/commonTest/kotlin/ch/dissem/yaep/domain/ClueTest.kt index 95e40ca..b4149a1 100644 --- a/domain/src/commonTest/kotlin/ch/dissem/yaep/domain/ClueTest.kt +++ b/domain/src/commonTest/kotlin/ch/dissem/yaep/domain/ClueTest.kt @@ -1,11 +1,11 @@ package ch.dissem.yaep.domain abstract class ClueTest { - protected val size = 6 + protected val size: Int = 6 protected fun createGrid( selection: (Item>) -> Item>? = { it } - ) = Grid( + ): Grid = Grid( ItemClass.randomClasses(size) .map { it.randomItems(size).map { item -> Item(item) } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37f853b..d4081da 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME