Konsist: check if sealed class could be sealed interface and fix existing issues.
This commit is contained in:
parent
ddc1e1d0cc
commit
3092ca23f0
14 changed files with 66 additions and 55 deletions
|
|
@ -170,9 +170,8 @@ private fun CustomSheetState.getIntOffset(): Int? = try {
|
|||
null
|
||||
}
|
||||
|
||||
private sealed class Slot {
|
||||
data class SheetContent(val key: Int?) : Slot()
|
||||
data object DragHandle : Slot()
|
||||
data object Scaffold : Slot()
|
||||
private sealed interface Slot {
|
||||
data class SheetContent(val key: Int?) : Slot
|
||||
data object DragHandle : Slot
|
||||
data object Scaffold : Slot
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -103,11 +103,11 @@ fun MessagesReactionButton(
|
|||
}
|
||||
}
|
||||
|
||||
sealed class MessagesReactionsButtonContent {
|
||||
data class Text(val text: String) : MessagesReactionsButtonContent()
|
||||
data class Icon(@DrawableRes val resourceId: Int) : MessagesReactionsButtonContent()
|
||||
sealed interface MessagesReactionsButtonContent {
|
||||
data class Text(val text: String) : MessagesReactionsButtonContent
|
||||
data class Icon(@DrawableRes val resourceId: Int) : MessagesReactionsButtonContent
|
||||
|
||||
data class Reaction(val reaction: AggregatedReaction) : MessagesReactionsButtonContent()
|
||||
data class Reaction(val reaction: AggregatedReaction) : MessagesReactionsButtonContent
|
||||
|
||||
val isHighlighted get() = this is Reaction && reaction.isHighlighted
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ import android.os.SystemClock
|
|||
class FirstThrottler(private val minimumInterval: Long = 800) {
|
||||
private var lastDate = 0L
|
||||
|
||||
sealed class CanHandleResult {
|
||||
data object Yes : CanHandleResult()
|
||||
data class No(val shouldWaitMillis: Long) : CanHandleResult()
|
||||
sealed interface CanHandleResult {
|
||||
data object Yes : CanHandleResult
|
||||
data class No(val shouldWaitMillis: Long) : CanHandleResult
|
||||
|
||||
fun waitMillis(): Long {
|
||||
return when (this) {
|
||||
|
|
|
|||
|
|
@ -22,14 +22,14 @@ import android.net.Uri
|
|||
* This sealed class represents all the permalink cases.
|
||||
* You don't have to instantiate yourself but should use [PermalinkParser] instead.
|
||||
*/
|
||||
sealed class PermalinkData {
|
||||
sealed interface PermalinkData {
|
||||
|
||||
data class RoomLink(
|
||||
val roomIdOrAlias: String,
|
||||
val isRoomAlias: Boolean,
|
||||
val eventId: String?,
|
||||
val viaParameters: List<String>
|
||||
) : PermalinkData()
|
||||
) : PermalinkData
|
||||
|
||||
/*
|
||||
* &room_name=Team2
|
||||
|
|
@ -47,9 +47,9 @@ sealed class PermalinkData {
|
|||
val token: String,
|
||||
val privateKey: String,
|
||||
val roomType: String?
|
||||
) : PermalinkData()
|
||||
) : PermalinkData
|
||||
|
||||
data class UserLink(val userId: String) : PermalinkData()
|
||||
data class UserLink(val userId: String) : PermalinkData
|
||||
|
||||
data class FallbackLink(val uri: Uri, val isLegacyGroupLink: Boolean = false) : PermalinkData()
|
||||
data class FallbackLink(val uri: Uri, val isLegacyGroupLink: Boolean = false) : PermalinkData
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ import kotlin.time.Duration
|
|||
* Can be retrieved from [RoomListService] methods.
|
||||
*/
|
||||
interface RoomList {
|
||||
sealed class LoadingState {
|
||||
data object NotLoaded : LoadingState()
|
||||
data class Loaded(val numberOfRooms: Int) : LoadingState()
|
||||
sealed interface LoadingState {
|
||||
data object NotLoaded : LoadingState
|
||||
data class Loaded(val numberOfRooms: Int) : LoadingState
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,16 +25,16 @@ import kotlinx.coroutines.flow.StateFlow
|
|||
*/
|
||||
interface RoomListService {
|
||||
|
||||
sealed class State {
|
||||
data object Idle : State()
|
||||
data object Running : State()
|
||||
data object Error : State()
|
||||
data object Terminated : State()
|
||||
sealed interface State {
|
||||
data object Idle : State
|
||||
data object Running : State
|
||||
data object Error : State
|
||||
data object Terminated : State
|
||||
}
|
||||
|
||||
sealed class SyncIndicator {
|
||||
data object Show : SyncIndicator()
|
||||
data object Hide : SyncIndicator()
|
||||
sealed interface SyncIndicator {
|
||||
data object Show : SyncIndicator
|
||||
data object Hide : SyncIndicator
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.tracing
|
||||
|
||||
sealed class WriteToFilesConfiguration {
|
||||
data object Disabled : WriteToFilesConfiguration()
|
||||
data class Enabled(val directory: String, val filenamePrefix: String) : WriteToFilesConfiguration()
|
||||
sealed interface WriteToFilesConfiguration {
|
||||
data object Disabled : WriteToFilesConfiguration
|
||||
data class Enabled(val directory: String, val filenamePrefix: String) : WriteToFilesConfiguration
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package io.element.android.libraries.textcomposer.model
|
||||
|
||||
sealed class PressEvent {
|
||||
data object PressStart: PressEvent()
|
||||
data object Tapped: PressEvent()
|
||||
data object LongPressEnd: PressEvent()
|
||||
sealed interface PressEvent {
|
||||
data object PressStart: PressEvent
|
||||
data object Tapped: PressEvent
|
||||
data object LongPressEnd: PressEvent
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
package io.element.android.libraries.textcomposer.model
|
||||
|
||||
sealed class VoiceMessagePlayerEvent {
|
||||
data object Play: VoiceMessagePlayerEvent()
|
||||
data object Pause: VoiceMessagePlayerEvent()
|
||||
sealed interface VoiceMessagePlayerEvent {
|
||||
data object Play: VoiceMessagePlayerEvent
|
||||
data object Pause: VoiceMessagePlayerEvent
|
||||
|
||||
data class Seek(
|
||||
val position: Float
|
||||
): VoiceMessagePlayerEvent()
|
||||
): VoiceMessagePlayerEvent
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ package io.element.android.libraries.textcomposer.model
|
|||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlin.time.Duration
|
||||
|
||||
sealed class VoiceMessageState {
|
||||
data object Idle: VoiceMessageState()
|
||||
sealed interface VoiceMessageState {
|
||||
data object Idle: VoiceMessageState
|
||||
|
||||
data class Preview(
|
||||
val isSending: Boolean,
|
||||
|
|
@ -29,10 +29,10 @@ sealed class VoiceMessageState {
|
|||
val playbackProgress: Float,
|
||||
val time: Duration,
|
||||
val waveform: ImmutableList<Float>,
|
||||
): VoiceMessageState()
|
||||
): VoiceMessageState
|
||||
|
||||
data class Recording(
|
||||
val duration: Duration,
|
||||
val levels: ImmutableList<Float>,
|
||||
): VoiceMessageState()
|
||||
): VoiceMessageState
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,13 +19,13 @@ package io.element.android.libraries.textcomposer.utils
|
|||
/**
|
||||
* State of a press gesture.
|
||||
*/
|
||||
internal sealed class PressState {
|
||||
internal sealed interface PressState {
|
||||
data class Idle(
|
||||
val lastPress: Pressing?
|
||||
) : PressState()
|
||||
) : PressState
|
||||
|
||||
sealed class Pressing : PressState()
|
||||
data object Tapping : Pressing()
|
||||
data object LongPressing : Pressing()
|
||||
sealed interface Pressing : PressState
|
||||
data object Tapping : Pressing
|
||||
data object LongPressing : Pressing
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ package io.element.android.libraries.voicerecorder.api
|
|||
import java.io.File
|
||||
import kotlin.time.Duration
|
||||
|
||||
sealed class VoiceRecorderState {
|
||||
sealed interface VoiceRecorderState {
|
||||
/**
|
||||
* The recorder is idle and not recording.
|
||||
*/
|
||||
data object Idle : VoiceRecorderState()
|
||||
data object Idle : VoiceRecorderState
|
||||
|
||||
/**
|
||||
* The recorder is currently recording.
|
||||
|
|
@ -31,7 +31,7 @@ sealed class VoiceRecorderState {
|
|||
* @property elapsedTime The elapsed time since the recording started.
|
||||
* @property levels The current audio levels of the recording as a fraction of 1.
|
||||
*/
|
||||
data class Recording(val elapsedTime: Duration, val levels: List<Float>) : VoiceRecorderState()
|
||||
data class Recording(val elapsedTime: Duration, val levels: List<Float>) : VoiceRecorderState
|
||||
|
||||
/**
|
||||
* The recorder has finished recording.
|
||||
|
|
@ -46,5 +46,5 @@ sealed class VoiceRecorderState {
|
|||
val mimeType: String,
|
||||
val waveform: List<Float>,
|
||||
val duration: Duration,
|
||||
) : VoiceRecorderState()
|
||||
) : VoiceRecorderState
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@
|
|||
|
||||
package io.element.android.libraries.voicerecorder.impl.audio
|
||||
|
||||
sealed class Audio {
|
||||
sealed interface Audio {
|
||||
class Data(
|
||||
val readSize: Int,
|
||||
val buffer: ShortArray,
|
||||
) : Audio()
|
||||
) : Audio
|
||||
|
||||
data class Error(
|
||||
val audioRecordErrorCode: Int
|
||||
) : Audio()
|
||||
) : Audio
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ import com.lemonappdev.konsist.api.ext.list.constructors
|
|||
import com.lemonappdev.konsist.api.ext.list.modifierprovider.withSealedModifier
|
||||
import com.lemonappdev.konsist.api.ext.list.parameters
|
||||
import com.lemonappdev.konsist.api.ext.list.withNameEndingWith
|
||||
import com.lemonappdev.konsist.api.ext.list.withoutConstructors
|
||||
import com.lemonappdev.konsist.api.ext.list.withoutName
|
||||
import com.lemonappdev.konsist.api.ext.list.withoutParents
|
||||
import com.lemonappdev.konsist.api.verify.assertEmpty
|
||||
import com.lemonappdev.konsist.api.verify.assertTrue
|
||||
import org.junit.Test
|
||||
|
|
@ -55,4 +57,14 @@ class KonsistArchitectureTest {
|
|||
.withNameEndingWith("Events")
|
||||
.assertEmpty(additionalMessage = "Events class MUST be sealed interface")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Sealed class without constructor and without parent MUST be sealed interface`() {
|
||||
Konsist.scopeFromProject()
|
||||
.classes()
|
||||
.withSealedModifier()
|
||||
.withoutConstructors()
|
||||
.withoutParents()
|
||||
.assertEmpty(additionalMessage = "Sealed class without constructor MUST be sealed interface")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue