Skip to content

Commit

Permalink
Detekt -fix (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz authored Oct 22, 2024
1 parent ae985ce commit d66c6b5
Show file tree
Hide file tree
Showing 50 changed files with 294 additions and 243 deletions.
17 changes: 8 additions & 9 deletions app/src/main/kotlin/xyz/ksharma/krail/navigation/KrailNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand Down Expand Up @@ -63,7 +62,7 @@ fun KrailNavHost() {
NavHost(
navController = navController,
startDestination = SplashScreen,
modifier = Modifier.fillMaxSize()
modifier = Modifier.fillMaxSize(),
) {
tripPlannerDestinations(navController = navController)

Expand All @@ -74,7 +73,7 @@ fun KrailNavHost() {
navOptions = NavOptions.Builder()
.setLaunchSingleTop(true)
.setPopUpTo<SplashScreen>(inclusive = true)
.build()
.build(),
)
})
}
Expand Down Expand Up @@ -112,7 +111,7 @@ fun AnimatedKrailLogo(modifier: Modifier = Modifier) {
modifier = modifier
.fillMaxWidth()
.wrapContentSize(),
horizontalArrangement = Arrangement.Center
horizontalArrangement = Arrangement.Center,
) {
AnimatedLetter("K", animationStarted)
AnimatedLetter("R", animationStarted)
Expand All @@ -139,8 +138,9 @@ fun AnimatedLetter(letter: String, animationStarted: Boolean) {
1.0f at 1000 using FastOutSlowInEasing // Settle back to normal scale
1.0f at 1100 using LinearEasing // Keep at normal scale
},
repeatMode = RepeatMode.Reverse
), label = "animeAnimation"
repeatMode = RepeatMode.Reverse,
),
label = "animeAnimation",
)

val letterScale = if (animationStarted) scale else 1f
Expand All @@ -154,21 +154,20 @@ fun AnimatedLetter(letter: String, animationStarted: Boolean) {
fontWeight = FontWeight.ExtraBold,
drawStyle = Stroke(
width = 8f, // Adjust stroke width for desired thickness
)
),
),
modifier = Modifier
.graphicsLayer {
scaleX = letterScale
scaleY = letterScale
}
.padding(4.dp)
.padding(4.dp),
)
}

@Serializable
data object SplashScreen


@PreviewLightDark
@Composable
private fun PreviewSplashScreen() {
Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ tasks {
config.setFrom(files("$rootDir/config/detekt/detekt.yaml"))
baseline.set(file("$rootDir/config/detekt/detekt-baseline.xml"))

autoCorrect = true
buildUponDefaultConfig = true
parallel = true
debug = true
Expand Down Expand Up @@ -78,6 +79,7 @@ tasks {
project.detekt {
basePath = rootProject.projectDir.absolutePath
toolVersion = libs.versions.detekt.get()
autoCorrect = true
}
}

Expand Down
17 changes: 16 additions & 1 deletion config/detekt/detekt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ complexity:
excludeStringsWithLessThan5Characters: true
ignoreStringsRegex: '$^'
ComplexInterface:
active: true
active: false
threshold: 10
includeStaticDeclarations: false
includePrivateDeclarations: false
Expand All @@ -141,7 +141,15 @@ complexity:
MethodOverloading:
active: true
TooManyFunctions:
ignoreAnnotatedFunctions: ['Composable']
excludes: ['**/test/**', '**/functionalTest/**']
LongMethod:
active: true
threshold: 60
ignoreAnnotated: ['Composable']
LongParameterList:
active: true
ignoreAnnotated: ['Composable', 'Test', 'GET', 'POST']

coroutines:
active: true
Expand Down Expand Up @@ -188,6 +196,13 @@ formatting:
active: true
TypeParameterListSpacing:
active: true
Indentation:
active: true
indentSize: 4
TrailingCommaOnCallSite:
active: true
TrailingCommaOnDeclarationSite:
active: true

naming:
ClassNaming:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import kotlin.coroutines.cancellation.CancellationException
* @param block The block of code to execute.
* @return A [Result] object containing the result of the block execution or the exception that was thrown.
*/
@Suppress("TooGenericExceptionCaught")
suspend fun <T, R> T.safeResult(
dispatcher: CoroutineDispatcher,
block: T.() -> R
block: T.() -> R,
): Result<R> = withContext(dispatcher) {
try {
Result.success(block())
Expand All @@ -43,9 +44,10 @@ suspend fun <T, R> T.safeResult(
* @return A [Result] object containing the success or failure of the block execution.
*
*/
@Suppress("TooGenericExceptionCaught")
suspend fun <T, R> T.suspendSafeResult(
dispatcher: CoroutineDispatcher,
block: suspend T.() -> Result<R>
block: suspend T.() -> Result<R>,
): Result<R> = withContext(dispatcher) {
try {
block()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ object DateTimeHelper {
val formattedDifference = when {
totalMinutes < 0 -> "${totalMinutes.absoluteValue} mins ago"
totalMinutes == 0L -> "Now"
hours == 1L -> "in ${hours.absoluteValue}h ${partialMinutes.absoluteValue}m"
hours == 1L -> "in ${hours.absoluteValue}h ${partialMinutes.absoluteValue}m"
hours >= 2 -> "in ${hours.absoluteValue} hrs"
else -> "in ${totalMinutes.absoluteValue} ${if(totalMinutes.absoluteValue == 1L) "min" else "mins"}"
else -> "in ${totalMinutes.absoluteValue} ${if (totalMinutes.absoluteValue == 1L) "min" else "mins"}"
}
Timber.d("\t minutes: $partialMinutes, hours: $hours, formattedDifference: $formattedDifference -> originTime")
return formattedDifference
Expand All @@ -89,7 +89,7 @@ object DateTimeHelper {

val formattedDifference = when {
hours >= 1 -> "${hours.absoluteValue}h ${partialMinutes.absoluteValue}m"
else -> "${totalMinutes.absoluteValue} ${if(totalMinutes.absoluteValue == 1L) "min" else "mins"}"
else -> "${totalMinutes.absoluteValue} ${if (totalMinutes.absoluteValue == 1L) "min" else "mins"}"
}
return formattedDifference
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ fun Dp.toAdaptiveSize(): Dp {
@Composable
fun Dp.toAdaptiveDecorativeIconSize(): Dp {
val density = LocalDensity.current
return if (density.fontScale > 1.5f) this.times(density.fontScale * 0.7f)
else this.times(density.fontScale)
return if (density.fontScale > 1.5f) {
this.times(density.fontScale * 0.7f)
} else {
this.times(density.fontScale)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import xyz.ksharma.krail.design.system.preview.ComponentPreviews
import xyz.ksharma.krail.design.system.preview.PreviewComponent
import xyz.ksharma.krail.design.system.theme.KrailTheme

@Composable
Expand All @@ -27,13 +27,13 @@ fun BasicJourneyCard(
.clip(RoundedCornerShape(12.dp))
.background(backgroundColor)
.semantics(mergeDescendants = true) {}
.padding(horizontal = 16.dp, vertical = 8.dp)
.padding(horizontal = 16.dp, vertical = 8.dp),
) {
content()
}
}

@ComponentPreviews
@PreviewComponent
@Composable
private fun BasicJourneyCardPreview() {
KrailTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ fun Divider(
Modifier
.fillMaxHeight()
.width(1.dp)
}
},
)
.background(color = color ?: LocalContentColor.current)
.background(color = color ?: LocalContentColor.current),
)
}
}

enum class DividerType {
HORIZONTAL,
VERTICAL
VERTICAL,
}

@PreviewLightDark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import androidx.compose.ui.semantics.Role
import xyz.ksharma.krail.design.system.LocalContentColor
import xyz.ksharma.krail.design.system.LocalOnContentColor
import xyz.ksharma.krail.design.system.R
import xyz.ksharma.krail.design.system.preview.ComponentPreviews
import xyz.ksharma.krail.design.system.preview.PreviewComponent
import xyz.ksharma.krail.design.system.theme.KrailTheme
import xyz.ksharma.krail.design.system.tokens.ButtonTokens.RoundButtonSize

Expand Down Expand Up @@ -62,7 +62,7 @@ fun RoundIconButton(

// region Previews

@ComponentPreviews
@PreviewComponent
@Composable
private fun RoundIconButtonPreview() {
KrailTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import xyz.ksharma.krail.design.system.preview.ComponentPreviews
import xyz.ksharma.krail.design.system.preview.PreviewComponent
import xyz.ksharma.krail.design.system.theme.KrailTheme
import xyz.ksharma.krail.design.system.toAdaptiveSize

Expand All @@ -27,14 +27,14 @@ fun SeparatorIcon(modifier: Modifier = Modifier, color: Color = KrailTheme.color

// region Previews

@ComponentPreviews
@PreviewComponent
@Composable
private fun SeparatorIconPreview() {
KrailTheme {
Box(
modifier = Modifier
.background(KrailTheme.colors.surface)
.padding(10.dp)
.padding(10.dp),
) {
SeparatorIcon()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.compose.ui.text.style.TextOverflow
import xyz.ksharma.krail.design.system.LocalContentAlpha
import xyz.ksharma.krail.design.system.LocalTextColor
import xyz.ksharma.krail.design.system.LocalTextStyle
import xyz.ksharma.krail.design.system.preview.ComponentPreviews
import xyz.ksharma.krail.design.system.preview.PreviewComponent
import xyz.ksharma.krail.design.system.theme.KrailTheme

@Composable
Expand All @@ -26,7 +26,7 @@ fun Text(
textAlign: TextAlign = TextAlign.Start,
maxLines: Int = Int.MAX_VALUE,
overflow: TextOverflow = if (maxLines == Int.MAX_VALUE) TextOverflow.Clip else TextOverflow.Ellipsis,
fontFamily: FontFamily?= null,
fontFamily: FontFamily? = null,
) {
val contentAlpha = LocalContentAlpha.current
CompositionLocalProvider(
Expand All @@ -49,7 +49,7 @@ fun Text(

// region Previews

@ComponentPreviews
@PreviewComponent
@Composable
private fun TextPreview() {
KrailTheme {
Expand All @@ -62,7 +62,7 @@ private fun TextPreview() {
}
}

@ComponentPreviews
@PreviewComponent
@Composable
private fun TextWithColorPreview() {
KrailTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fun TextField(
val textFieldState = rememberTextFieldState(initialText.orEmpty())
val textSelectionColors = TextSelectionColors(
handleColor = KrailTheme.colors.tertiary,
backgroundColor = KrailTheme.colors.tertiary.copy(alpha = TextSelectionBackgroundOpacity)
backgroundColor = KrailTheme.colors.tertiary.copy(alpha = TextSelectionBackgroundOpacity),
)

LaunchedEffect(textFieldState.text) {
Expand All @@ -84,7 +84,7 @@ fun TextField(
// This will change the colors of the innerTextField() composable.
textStyle = textStyle
?: LocalTextStyle.current.copy(
color = LocalTextColor.current.copy(alpha = contentAlpha)
color = LocalTextColor.current.copy(alpha = contentAlpha),
),
keyboardOptions = KeyboardOptions(
capitalization = KeyboardCapitalization.None,
Expand All @@ -102,7 +102,7 @@ fun TextField(
modifier = Modifier
.background(
shape = RoundedCornerShape(TextFieldHeight.div(2)),
color = KrailTheme.colors.secondaryContainer
color = KrailTheme.colors.secondaryContainer,
)
.padding(horizontal = 16.dp, vertical = 4.dp),
horizontalArrangement = Arrangement.Start,
Expand All @@ -124,7 +124,7 @@ fun TextField(
// add trailing icon here / Clear - todo
}
}
}
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import androidx.compose.ui.unit.dp
import xyz.ksharma.krail.design.system.LocalContentAlpha
import xyz.ksharma.krail.design.system.LocalTextColor
import xyz.ksharma.krail.design.system.LocalTextStyle
import xyz.ksharma.krail.design.system.preview.ComponentPreviews
import xyz.ksharma.krail.design.system.preview.PreviewComponent
import xyz.ksharma.krail.design.system.theme.KrailTheme
import xyz.ksharma.krail.design.system.tokens.TextFieldTokens
import xyz.ksharma.krail.design.system.tokens.TextFieldTokens.TextFieldHeight
Expand Down Expand Up @@ -62,7 +62,7 @@ fun TextFieldButton(

// region Previews

@ComponentPreviews
@PreviewComponent
@Composable
private fun TextFieldButtonPreview() {
KrailTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import xyz.ksharma.krail.design.system.LocalTextColor
import xyz.ksharma.krail.design.system.LocalTextStyle
import xyz.ksharma.krail.design.system.preview.ComponentPreviews
import xyz.ksharma.krail.design.system.preview.PreviewComponent
import xyz.ksharma.krail.design.system.theme.KrailTheme

@Composable
Expand All @@ -23,7 +23,7 @@ fun TitleBar(
modifier = modifier
.statusBarsPadding()
.fillMaxWidth()
.padding(vertical = 16.dp, horizontal = 16.dp)
.padding(vertical = 16.dp, horizontal = 16.dp),
) {
CompositionLocalProvider(
LocalTextColor provides KrailTheme.colors.onBackground,
Expand All @@ -36,15 +36,15 @@ fun TitleBar(

// region Previews

@ComponentPreviews
@PreviewComponent
@Composable
private fun TitleBarPreview() {
KrailTheme {
TitleBar(
title = {
Text(text = "Title")
},
modifier = Modifier.background(color = KrailTheme.colors.background)
modifier = Modifier.background(color = KrailTheme.colors.background),
)
}
}
Expand Down
Loading

0 comments on commit d66c6b5

Please sign in to comment.