Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code-Formatter] Ktlint + Detekt Added! #20

Merged
merged 1 commit into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/src/main/java/com/himanshoe/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import com.himanshoe.kalendar.endlos.ui.Kalendar


class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Kalendar(
onCurrentDayClick = { date, event ->

},
errorMessage = {})
errorMessage = {}
)
}
}
}
15 changes: 15 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id(Plugins.detekt).version(Versions.detekt)
}
buildscript {
repositories {
google()
mavenCentral()
maven("https://plugins.gradle.org/m2/")

}
dependencies {
classpath(Deps.Gradle.androidGradlePlugin)
classpath(Deps.Gradle.kotlinGradlePlugin)
classpath(Deps.Gradle.vanniktechGradlePlugin)
classpath(Deps.Gradle.detektGradlePlugin)
classpath(Deps.Gradle.ktlintGradlePlugin)
}
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
subprojects {
apply(plugin = Plugins.ktlint)
apply(plugin = Plugins.detekt)

// detekt {
// config = files("$rootDir/${ModuleExtension.FilePath.detekt}")
// buildUponDefaultConfig = true
// }
}
allprojects {
pluginManager.withPlugin(Plugins.vanniktechPublish) {
extensions.getByType(com.vanniktech.maven.publish.MavenPublishPluginExtension::class.java)
Expand Down
5 changes: 4 additions & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ object Plugins {
val android by lazy { "android" }
val kotlinAndroid by lazy { "kotlin-android" }
val vanniktechPublish by lazy { "com.vanniktech.maven.publish" }
val ktlint by lazy { "org.jlleitschuh.gradle.ktlint" }
val detekt by lazy { "io.gitlab.arturbosch.detekt" }
}

object Deps {
Expand Down Expand Up @@ -44,10 +46,11 @@ object Deps {
val kotlinGradlePlugin by lazy { "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}" }
val androidGradlePlugin by lazy { "com.android.tools.build:gradle:${Versions.androidGradlePlugin}" }
val vanniktechGradlePlugin by lazy { "com.vanniktech:gradle-maven-publish-plugin:${Versions.vanniktechGradlePlugin}" }
val ktlintGradlePlugin by lazy { "org.jlleitschuh.gradle:ktlint-gradle:${Versions.ktlint}" }
val detektGradlePlugin by lazy { "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${Versions.detekt}" }
}
}

object ProjectPath {
const val designCore = ":design-core"
const val kalendar = ":kalendar"
}
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ object Versions {
const val kotlin = "1.5.31"
const val activity = "1.3.1"
const val material = "1.4.0"
const val paging = "1.0.0-alpha14"
const val jUnit = "4.13.2"
const val jUnitExtensions = "1.1.3"
const val espresso = "3.4.0"
const val core = "1.7.0"
const val ktlint = "10.2.0"
const val detekt = "1.19.0"
}
21 changes: 21 additions & 0 deletions gradle/config/detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
naming:
TopLevelPropertyNaming:
constantPattern: '[A-Z][A-Za-z0-9]*'
FunctionNaming:
functionPattern: '([A-Za-z][a-zA-Z0-9]*)|(`.*`)'
MatchingDeclarationName:
active: false

style:
MagicNumber:
ignorePropertyDeclaration: true
UnusedPrivateMember:
ignoreAnnotated: [ 'Preview' ]

complexity:
LongParameterList:
functionThreshold: 25
constructorThreshold: 25
ignoreDefaultParameters: true
TooManyFunctions:
thresholdInFiles: 20
33 changes: 33 additions & 0 deletions gradle/scripts/git-hooks.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
tasks {
register<Copy>("copyGitHooks") {
description = "Copies the git hooks from scripts/git-hooks to the .git folder."
group = "plugins.git-hook"
from("$rootDir/scripts/git-hooks/") {
include("**/*.sh")
rename("(.*).sh", "$1")
}
into("$rootDir/.git/hooks")
}

register<Exec>("installGitHooks") {
description = "Installs the scripts git hooks from scripts/git-hooks."
group = "plugins.git-hook"
workingDir(rootDir)
commandLine("chmod")
args("-R", "+x", ".git/hooks/")
dependsOn(named("copyGitHooks"))
doLast {
print("Git hooks installed successfully.")
}
}

register<Delete>("deleteGitHooks") {
description = "Delete the scripts git hooks."
group = "plugins.git-hook"
delete(fileTree(".git/hooks/"))
}

afterEvaluate {
tasks["clean"].dependsOn(tasks.named("installGitHooks"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ sealed class KalendarSelector(
override val selectedTextColor: Color = KalendarTheme.colors.white,
override val textColor: Color = KalendarTheme.colors.black,
override val textHeaderColor: Color = KalendarTheme.colors.black,
) : KalendarSelector(CircleShape,
) : KalendarSelector(
CircleShape,
selectedColor,
defaultColor,
todayColor,
selectedTextColor,
textColor,
eventTextColor,
textHeaderColor)
textHeaderColor
)

data class Dot(
override val selectedColor: Color = KalendarTheme.colors.selectedColor,
Expand All @@ -67,13 +69,15 @@ sealed class KalendarSelector(
override val selectedTextColor: Color = KalendarTheme.colors.selectedColor,
override val textColor: Color = KalendarTheme.colors.black,
override val textHeaderColor: Color = KalendarTheme.colors.black,
) : KalendarSelector(CircleShape,
) : KalendarSelector(
CircleShape,
selectedColor,
defaultColor,
todayColor,
selectedTextColor,
textColor,
eventTextColor, textHeaderColor)
eventTextColor, textHeaderColor
)

data class Square(
override val selectedColor: Color = KalendarTheme.colors.selectedColor,
Expand All @@ -83,13 +87,15 @@ sealed class KalendarSelector(
override val selectedTextColor: Color = KalendarTheme.colors.white,
override val textColor: Color = KalendarTheme.colors.black,
override val textHeaderColor: Color = KalendarTheme.colors.black,
) : KalendarSelector(RectangleShape,
) : KalendarSelector(
RectangleShape,
selectedColor,
defaultColor,
todayColor,
selectedTextColor,
textColor,
eventTextColor, textHeaderColor)
eventTextColor, textHeaderColor
)

data class Rounded(
override val selectedColor: Color = KalendarTheme.colors.selectedColor,
Expand All @@ -99,11 +105,13 @@ sealed class KalendarSelector(
override val selectedTextColor: Color = KalendarTheme.colors.white,
override val textColor: Color = KalendarTheme.colors.black,
override val textHeaderColor: Color = KalendarTheme.colors.black,
) : KalendarSelector(RoundedCornerShape(Grid.OneHalf),
) : KalendarSelector(
RoundedCornerShape(Grid.OneHalf),
selectedColor,
defaultColor,
todayColor,
selectedTextColor,
textColor,
eventTextColor, textHeaderColor)
eventTextColor, textHeaderColor
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ fun debugColors(
onError = debugColor,
isLight = !darkTheme
)

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ fun ProvideKalendarTheme(
CompositionLocalProvider(
content = content
)

}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ internal fun KalendarDot(
isToday: Boolean,
kalendarSelector: KalendarSelector,
) {
Surface(shape = kalendarSelector.shape,
Surface(
shape = kalendarSelector.shape,
color = getColor(isSelected, isToday, kalendarSelector),
modifier = Modifier
.size(Grid.One), content = {})
.size(Grid.One),
content = {}
)
}

private fun getColor(
Expand All @@ -54,5 +57,3 @@ private fun getColor(
else -> kalendarSelector.defaultColor
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ internal fun KalendarDay(
)
)
if (isDot) {
KalendarDot(kalendarSelector = kalendarSelector,
KalendarDot(
kalendarSelector = kalendarSelector,
isSelected = isSelected,
isToday = isToday)
isToday = isToday
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ internal fun KalendarEmptyDay(modifier: Modifier = Modifier) {
textAlign = TextAlign.Center
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ internal fun KalendarEndlos(
KalendarTheme {
val color = kalendarStyle.kalendarColor ?: KalendarTheme.colors.background

Box(modifier = Modifier
.background(color = color)) {
Box(
modifier = Modifier
.background(color = color)
) {

KalendarView(
kalendarKonfig = kalendarKonfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.himanshoe.kalendar.endlos.ui

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Divider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
Expand Down Expand Up @@ -58,8 +64,8 @@ internal fun KalendarMonth(
val isFromCurrentMonth = YearMonth.from(localDate) == monthState.value
if (isFromCurrentMonth) {
val isSelected = monthState.value.month == clickedDay.value.month &&
monthState.value.year == clickedDay.value.year &&
localDate == clickedDay.value
monthState.value.year == clickedDay.value.year &&
localDate == clickedDay.value

KalendarDay(
size = size,
Expand All @@ -82,9 +88,11 @@ internal fun KalendarMonth(
}
}

Divider(color = kalendarSelector.selectedColor,
Divider(
color = kalendarSelector.selectedColor,
modifier = Modifier.alpha(0.5F),
thickness = 1.dp)
thickness = 1.dp
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ package com.himanshoe.kalendar.endlos.ui
* SOFTWARE.
*/

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.requiredWidth
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -62,5 +67,3 @@ internal fun KalendarWeekDay(
Text(text = text, modifier = Modifier.alpha(0.5F), style = MaterialTheme.typography.body1)
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ object CalendarMonthSource {
}
}
}

Loading