Skip to content

Commit a3f3528

Browse files
authored
Merge pull request #4 from DevelopersBreach/shreyas/implement-ktlint
Configure Ktlint - integration for code formatting and linting automation
2 parents e703c73 + 930ffe8 commit a3f3528

File tree

17 files changed

+90
-48
lines changed

17 files changed

+90
-48
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*.{kt,kts}]
4+
5+
ktlint_code_style = ktlint_official
6+
insert_final_newline = false
7+
ij_kotlin_packages_to_use_import_on_demand = false
8+
ij_kotlin_allow_trailing_comma = true
9+
ij_kotlin_allow_trailing_comma_on_call_site = true
10+
max_line_length = off
11+
ktlint_function_naming_ignore_when_annotated_with = Composable
12+
ktlint_standard_import-ordering = disabled
13+
ktlint_standard_no-empty-first-line-in-class-body = disabled
14+
ktlint_standard_annotation = disabled
15+
ktlint_standard_multiline-expression-wrapping = disabled
16+
ktlint_standard_string-template-indent = disabled

composeApp/build.gradle.kts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@ import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
33
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
44
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
55
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
6+
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
67

78
plugins {
89
alias(libs.plugins.kotlinMultiplatform)
910
alias(libs.plugins.androidApplication)
1011
alias(libs.plugins.composeMultiplatform)
1112
alias(libs.plugins.composeCompiler)
1213
alias(libs.plugins.serialization)
14+
alias(libs.plugins.ktlint)
15+
}
16+
17+
ktlint {
18+
android = true
19+
ignoreFailures = false
20+
reporters {
21+
reporter(ReporterType.PLAIN)
22+
reporter(ReporterType.CHECKSTYLE)
23+
reporter(ReporterType.SARIF)
24+
}
1325
}
1426

1527
kotlin {
@@ -19,20 +31,20 @@ kotlin {
1931
jvmTarget.set(JvmTarget.JVM_11)
2032
}
2133
}
22-
34+
2335
listOf(
2436
iosX64(),
2537
iosArm64(),
26-
iosSimulatorArm64()
38+
iosSimulatorArm64(),
2739
).forEach { iosTarget ->
2840
iosTarget.binaries.framework {
2941
baseName = "ComposeApp"
3042
isStatic = true
3143
}
3244
}
33-
45+
3446
jvm("desktop")
35-
47+
3648
@OptIn(ExperimentalWasmDsl::class)
3749
wasmJs {
3850
moduleName = "composeApp"
@@ -52,10 +64,10 @@ kotlin {
5264
}
5365
binaries.executable()
5466
}
55-
67+
5668
sourceSets {
5769
val desktopMain by getting
58-
70+
5971
androidMain.dependencies {
6072
implementation(compose.preview)
6173
implementation(libs.androidx.activity.compose)
@@ -135,4 +147,4 @@ compose.desktop {
135147
packageVersion = "1.0.0"
136148
}
137149
}
138-
}
150+
}

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.developersbreach.kotlindictionarymultiplatform
22

33
import androidx.compose.material.MaterialTheme
4-
import androidx.compose.runtime.*
4+
import androidx.compose.runtime.Composable
55
import com.developersbreach.kotlindictionarymultiplatform.ui.navigation.AppNavigation
66

77
@Composable
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package com.developersbreach.kotlindictionarymultiplatform.core
22

3-
const val API_KEY =""
3+
const val API_KEY = ""

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/core/KtorHttpClient.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import kotlinx.serialization.json.Json
2020
import kotlinx.serialization.json.decodeFromJsonElement
2121
import kotlinx.serialization.json.jsonObject
2222

23-
2423
object KtorHttpClient {
2524
private val json = Json { ignoreUnknownKeys = true }
2625

@@ -76,33 +75,36 @@ object KtorHttpClient {
7675
},
7776
"required": ["topicId","topicName","intro","syntax","sections"]
7877
}
79-
""".trimIndent()
78+
""".trimIndent(),
8079
)
8180

8281
private val functionDef = FunctionDefinition(
8382
name = "generate_kotlin_topic_details",
8483
description = "Return a fully-featured Kotlin documentation object for a given topic",
85-
parameters = functionSchema
84+
parameters = functionSchema,
8685
)
8786

8887
/**
8988
* Calls the OpenAI ChatCompletion with function-calling to get topic details.
9089
* @param topicId the topic identifier, e.g. "variables".
9190
* @param apiKey your OpenAI API key.
9291
*/
93-
suspend fun generateTopicDetails(topicId: String, apiKey: String): KotlinTopicDetails {
92+
suspend fun generateTopicDetails(
93+
topicId: String,
94+
apiKey: String,
95+
): KotlinTopicDetails {
9496
// Prepare messages
9597
val messages = listOf(
9698
ChatMessage("system", "You are a Kotlin documentation generator."),
97-
ChatMessage("user", "Generate full Kotlin documentation for topic \"$topicId\".")
99+
ChatMessage("user", "Generate full Kotlin documentation for topic \"$topicId\"."),
98100
)
99101

100102
// Build request body
101103
val request = ChatCompletionRequest(
102104
model = "gpt-4o-mini",
103105
messages = messages,
104106
functions = listOf(functionDef),
105-
functionCall = mapOf("name" to functionDef.name)
107+
functionCall = mapOf("name" to functionDef.name),
106108
)
107109

108110
// Execute HTTP request

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/detail/KotlinTopicDetails.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,65 @@ data class KotlinTopicDetails(
1313
val sections: List<Section>,
1414
val pitfalls: List<String> = emptyList(),
1515
val relatedTopics: List<String> = emptyList(),
16-
val metadata: Map<String, JsonElement> = emptyMap()
16+
val metadata: Map<String, JsonElement> = emptyMap(),
1717
)
1818

1919
@Serializable
2020
data class Syntax(
2121
val signature: String,
22-
val notes: String? = null
22+
val notes: String? = null,
2323
)
2424

2525
@Serializable
2626
data class Section(
2727
val heading: String? = null,
2828
val content: String? = null,
29-
val codeExamples: List<CodeExample> = emptyList()
29+
val codeExamples: List<CodeExample> = emptyList(),
3030
)
3131

3232
@Serializable
3333
data class CodeExample(
3434
val description: String? = null,
3535
val code: String,
36-
val language: String = "kotlin"
36+
val language: String = "kotlin",
3737
)
3838

3939
// --- Request/Response schema for OpenAI Chat Completion ---
4040
@Serializable
4141
data class ChatMessage(
4242
val role: String,
43-
val content: String
43+
val content: String,
4444
)
4545

4646
@Serializable
4747
data class FunctionDefinition(
4848
val name: String,
4949
val description: String,
50-
val parameters: JsonElement
50+
val parameters: JsonElement,
5151
)
5252

5353
@Serializable
5454
data class FunctionCall(
5555
val name: String,
56-
val arguments: String
56+
val arguments: String,
5757
)
5858

5959
@Serializable
6060
data class ChatCompletionChoice(
61-
val message: ChatCompletionResponseMessage
61+
val message: ChatCompletionResponseMessage,
6262
)
6363

6464
@Serializable
6565
data class ChatCompletionResponseMessage(
6666
val role: String,
6767
val content: String? = null,
6868
@SerialName("function_call")
69-
val functionCall: FunctionCall? = null
69+
val functionCall: FunctionCall? = null,
7070
)
7171

7272
@Serializable
7373
data class ChatCompletionResponse(
74-
val choices: List<ChatCompletionChoice>?
74+
val choices: List<ChatCompletionChoice>?,
7575
)
7676

7777
@Serializable
@@ -80,5 +80,5 @@ data class ChatCompletionRequest(
8080
val messages: List<ChatMessage>,
8181
val functions: List<FunctionDefinition>,
8282
@SerialName("function_call")
83-
val functionCall: Map<String, String>
83+
val functionCall: Map<String, String>,
8484
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.developersbreach.kotlindictionarymultiplatform.data.topic.model
22

33
data class Topic(
4-
val name: String
4+
val name: String,
55
)

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/topic/repository/TopicRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ object TopicRepository {
1818
Topic("Delegation"),
1919
Topic("Sealed Classes"),
2020
Topic("Generics"),
21-
Topic("Annotations")
21+
Topic("Annotations"),
2222
)
2323
}

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppNavigation.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fun AppNavigation(
1616
startDestination: AppDestinations = AppDestinations.TopicList,
1717
) {
1818
val navController = rememberNavController()
19-
val actions = remember(navController) { NavigationActions(navController) }
19+
val actions = remember(navController) { NavigationAction(navController) }
2020

2121
NavHost(
2222
navController = navController,
@@ -28,7 +28,7 @@ fun AppNavigation(
2828
onTopicClick = { selectedTopicId ->
2929
actions.navigateToDetail(selectedTopicId)
3030
},
31-
viewModel = viewModel
31+
viewModel = viewModel,
3232
)
3333
}
3434

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/NavigationAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.developersbreach.kotlindictionarymultiplatform.ui.navigation
22

33
import androidx.navigation.NavHostController
44

5-
class NavigationActions(private val navController: NavHostController) {
5+
class NavigationAction(private val navController: NavHostController) {
66

77
val navigateToDetail: (String) -> Unit = { topicId ->
88
navController.navigate(AppDestinations.Detail(topicId))

0 commit comments

Comments
 (0)