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