Skip to content

Commit

Permalink
Merge pull request #53 from VahidGarousi/43-add-detekt-task
Browse files Browse the repository at this point in the history
Adding Detekt for #43
  • Loading branch information
VahidGarousi authored Jan 27, 2023
2 parents 9252053 + d5f0696 commit 794c55e
Show file tree
Hide file tree
Showing 22 changed files with 811 additions and 52 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/android_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ jobs:
run: chmod +x ./gradlew

- name: Build Project
run: ./gradlew assemble
run: ./gradlew assemble

- name: Static Analysis
run: ./gradlew ktlintCheck detekt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("TooManyFunctions")
package dev.garousi.stockwatcher.feature.watchlist.data

import com.lightstreamer.client.ItemUpdate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("LongParameterList", "TooManyFunctions")

package dev.garousi.stockwatcher.feature.watchlist.data

import android.util.Log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.transform

sealed class StatefulData<out T : Any> {
data class Success<T : Any>(val result: T) : StatefulData<T>()
data class Error(val msg: String) : StatefulData<Nothing>()
Expand Down Expand Up @@ -35,14 +36,23 @@ fun <T : Any> Flow<T>.wrapWithStatefulData(): Flow<StatefulData<T>> = transform
return@transform emit(StatefulData.Success(value))
}

inline fun <T : Any, R : Any> Flow<StatefulData<T>>.mapState(crossinline transform: suspend (value: T) -> R): Flow<StatefulData<R>> = transform { value ->
return@transform emit(value.suspendMap(transform))
}
inline fun <T : Any, R : Any> Flow<StatefulData<T>>.mapState(
crossinline transform: suspend (value: T) -> R
): Flow<StatefulData<R>> =
transform { value ->
return@transform emit(value.suspendMap(transform))
}

inline fun <T : Any> Flow<StatefulData<T>>.onSuccessState(crossinline action: suspend (value: T) -> Unit): Flow<StatefulData<T>> = onEach {
if (it is StatefulData.Success) action(it.result)
}
inline fun <T : Any> Flow<StatefulData<T>>.onSuccessState(
crossinline action: suspend (value: T) -> Unit
): Flow<StatefulData<T>> =
onEach {
if (it is StatefulData.Success) action(it.result)
}

inline fun <T : Any> Flow<StatefulData<T>>.onErrorState(crossinline action: suspend (error: String) -> Unit): Flow<StatefulData<T>> = onEach {
if (it is StatefulData.Error) action(it.msg)
}
inline fun <T : Any> Flow<StatefulData<T>>.onErrorState(
crossinline action: suspend (error: String) -> Unit
): Flow<StatefulData<T>> =
onEach {
if (it is StatefulData.Error) action(it.msg)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@file:Suppress("UnusedPrivateMember")
package dev.garousi.stockwatcher.feature.watchlist.data

enum class SubscriptionMode(mode: String) {
Merge("MERGE"),
Command("COMMAND"),
enum class SubscriptionMode {
Merge,
Command,
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("UnnecessaryAbstractClass")

package dev.garousi.stockwatcher.feature.watchlist.di

import dagger.Binds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("UnnecessaryAbstractClass")
package dev.garousi.stockwatcher.feature.watchlist.di

import dagger.Binds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("MagicNumber", "LongMethod", "FunctionNaming", "CyclomaticComplexMethod")

package dev.garousi.stockwatcher.feature.watchlist.presentation

import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -159,7 +161,10 @@ fun StockItem(
textAlign = TextAlign.Center,
)
Icon(
imageVector = if (stock.change > 0) Icons.Filled.KeyboardArrowUp else Icons.Filled.KeyboardArrowDown,
imageVector = if (stock.change > 0)
Icons.Filled.KeyboardArrowUp
else
Icons.Filled.KeyboardArrowDown,
contentDescription = null,
tint = if (stock.change > 0) Color(0XFF48BE62) else Color(0XFFBE4848),
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("FunctionNaming")
package dev.garousi.stockwatcher.feature.watchlist.presentation

import androidx.compose.foundation.Image
Expand Down Expand Up @@ -40,7 +41,7 @@ fun StockList(
) {
itemsIndexed(
items = stocks,
key = { index, item -> item.itemName },
key = { _, item -> item.itemName },
) { index, stock ->
StockItem(
stock = stock,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("FunctionNaming", "LongParameterList")

package dev.garousi.stockwatcher.feature.watchlist.presentation

import androidx.compose.animation.AnimatedVisibility
Expand Down Expand Up @@ -26,7 +28,6 @@ import androidx.compose.material.primarySurface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.Center
import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -130,26 +131,3 @@ private fun WatchlistTopAppBar(
)
}
}

@Composable
private fun LoadingView() {
Box(
modifier = Modifier.fillMaxSize(),
) {
CircularProgressIndicator(
modifier = Modifier.align(Alignment.Center),
)
}
}

@Composable
private fun ErrorView() {
Box(
modifier = Modifier.fillMaxSize(),
) {
Text(
text = "Error Happened",
modifier = Modifier.align(Alignment.Center),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("MagicNumber", "ForEachOnRange")
package dev.garousi.stockwatcher.feature.watchlist.presentation

import dev.garousi.stockwatcher.feature.watchlist.domain.models.Stock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("CyclomaticComplexMethod")
package dev.garousi.stockwatcher.feature.watchlist.presentation

import android.util.Log
Expand Down Expand Up @@ -32,9 +33,6 @@ class WatchlistViewModel @Inject constructor(
stockListLightStreamerService
.subscribe()
.flow
.catch { cause: Throwable ->
Log.i("LOGGER", "" + cause.localizedMessage.orEmpty())
}
.map { stock ->
_uiState.update { it.copy(isLoading = false) }
stock.itemPos?.let { updatedItemIndex ->
Expand All @@ -60,6 +58,9 @@ class WatchlistViewModel @Inject constructor(
}
}
}
.catch { cause: Throwable ->
Log.i("LOGGER", "" + cause.localizedMessage.orEmpty())
}
.stateIn(
scope = viewModelScope,
initialValue = StockListDto(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("FunctionNaming")
/*
* Copyright 2022 The Android Open Source Project
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("FunctionNaming")
package dev.garousi.stockwatcher.navigation

import androidx.compose.runtime.Composable
Expand All @@ -8,7 +9,6 @@ import androidx.navigation.compose.NavHost
@Composable
fun StockWatcherNavHost(
navController: NavHostController,
onBackClick: () -> Unit,
modifier: Modifier = Modifier,
startDestination: String = watchlistGraphRoutePattern,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("FunctionNaming")
package dev.garousi.stockwatcher.ui

import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -32,8 +33,6 @@ fun StockWatcherApp(
testTagsAsResourceId = true
},
bottomBar = {
if (appState.shouldShowBottomBar) {
}
},
) { padding ->
Row(
Expand All @@ -49,12 +48,8 @@ fun StockWatcherApp(
) {
Column(Modifier.fillMaxSize()) {
// Show the top app bar on top level destinations.
val destination = appState.currentTopLevelDestination
if (destination != null) {
}
StockWatcherNavHost(
navController = appState.navController,
onBackClick = appState::onBackClick,
navController = appState.navController
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("FunctionNaming")
package dev.garousi.stockwatcher.ui

import androidx.compose.runtime.Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("MagicNumber")
package dev.garousi.stockwatcher.ui.theme

import androidx.compose.ui.graphics.Color
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("MagicNumber", "FunctionNaming")
package dev.garousi.stockwatcher.ui.theme

import androidx.compose.foundation.isSystemInDarkTheme
Expand Down
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ plugins {
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
id 'com.google.dagger.hilt.android' version '2.44.2' apply false
id "com.github.ben-manes.versions" version "0.44.0"
id "com.diffplug.spotless" version "6.12.1"
// id "com.diffplug.spotless" version "6.12.1"
id "io.gitlab.arturbosch.detekt" version "1.22.0"
id "org.jlleitschuh.gradle.ktlint" version "10.2.0"
}

subprojects {
apply from: "../buildscripts/ktlint.gradle"
apply from: "../buildscripts/detekt.gradle"
apply from: "../buildscripts/versionsplugin.gradle"
apply from: "../buildscripts/spotless.gradle"
}
14 changes: 14 additions & 0 deletions buildscripts/detekt.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apply plugin: "io.gitlab.arturbosch.detekt"

detekt {
config = files("${rootProject.rootDir}/config/detekt/detekt.yml")
}


tasks.named("detekt").configure {
reports {
html.enabled = true
xml.enabled = true
txt.enabled = true
}
}
14 changes: 14 additions & 0 deletions buildscripts/ktlint.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apply plugin: "org.jlleitschuh.gradle.ktlint"

ktlint {
// https://github.com/pinterest/ktlint/releases
version = "0.45.2"

reporters {
reporter "plain"
reporter "checkstyle"
reporter "html"
}

outputColorName = "RED"
}
Loading

0 comments on commit 794c55e

Please sign in to comment.