Skip to content

Commit bc04f9a

Browse files
committed
refactor: clean up whitespace and formatting across multiple files #453
1 parent ce0f5fe commit bc04f9a

File tree

54 files changed

+2499
-2170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2499
-2170
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ gradleIntelliJPlugin = "2.1.0"
66
qodana = "0.1.13"
77
kover = "0.7.5"
88
compose = "1.8.0"
9+
ktlint = "13.1.0"
910

1011
chapi = "2.1.2"
1112
jtokkit = "1.1.0"
@@ -25,5 +26,6 @@ kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref =
2526
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
2627
qodana = { id = "org.jetbrains.qodana", version.ref = "qodana" }
2728
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
29+
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
2830

2931
[bundles]

mpp-ui/.editorconfig

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
max_line_length = 120
10+
tab_width = 4
11+
trim_trailing_whitespace = true
12+
13+
[*.{kt,kts}]
14+
indent_size = 4
15+
continuation_indent_size = 4
16+
max_line_length = 120
17+
insert_final_newline = true
18+
19+
# Ktlint rules
20+
ktlint_standard_no-wildcard-imports = disabled
21+
ktlint_standard_filename = disabled
22+
ktlint_standard_trailing-comma-on-call-site = disabled
23+
ktlint_standard_trailing-comma-on-declaration-site = disabled
24+
ktlint_standard_argument-list-wrapping = disabled
25+
ktlint_standard_function-naming = disabled
26+
ktlint_standard_function-signature = disabled
27+
ktlint_standard_string-template-indent = disabled
28+
29+
[*.{json,yml,yaml}]
30+
indent_size = 2
31+
32+
[*.md]
33+
max_line_length = off
34+
trim_trailing_whitespace = false

mpp-ui/build.gradle.kts

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id("org.jetbrains.compose")
44
id("org.jetbrains.kotlin.plugin.compose")
55
id("com.android.application")
6+
alias(libs.plugins.ktlint)
67
}
78

89
repositories {
@@ -19,14 +20,14 @@ kotlin {
1920
freeCompilerArgs.add("-opt-in=androidx.compose.material3.ExperimentalMaterial3Api")
2021
}
2122
}
22-
23+
2324
androidTarget {
2425
compilerOptions {
2526
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
2627
freeCompilerArgs.add("-opt-in=androidx.compose.material3.ExperimentalMaterial3Api")
2728
}
2829
}
29-
30+
3031
js(IR) {
3132
browser {
3233
commonWebpackConfig {
@@ -41,7 +42,7 @@ kotlin {
4142
freeCompilerArgs.add("-opt-in=androidx.compose.material3.ExperimentalMaterial3Api")
4243
}
4344
}
44-
45+
4546
sourceSets {
4647
val commonMain by getting {
4748
dependencies {
@@ -66,44 +67,44 @@ kotlin {
6667
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
6768
}
6869
}
69-
70+
7071
val commonTest by getting {
7172
dependencies {
7273
implementation(kotlin("test"))
7374
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.2")
7475
}
7576
}
76-
77+
7778
val jvmMain by getting {
7879
dependencies {
7980
implementation(compose.desktop.currentOs)
8081
// Rich text editor for Compose Desktop
8182
implementation("com.mohamedrejeb.richeditor:richeditor-compose:1.0.0-rc13")
82-
83+
8384
// Multiplatform Markdown Renderer for JVM
8485
implementation("com.mikepenz:multiplatform-markdown-renderer:0.38.1")
8586
implementation("com.mikepenz:multiplatform-markdown-renderer-m3:0.38.1")
8687
}
8788
}
88-
89+
8990
val jvmTest by getting {
9091
dependencies {
9192
implementation(kotlin("test-junit"))
9293
}
9394
}
94-
95+
9596
val androidMain by getting {
9697
dependencies {
9798
implementation("androidx.activity:activity-compose:1.11.0")
9899
implementation("androidx.appcompat:appcompat:1.6.1")
99100
implementation("androidx.core:core-ktx:1.17.0")
100-
101+
101102
// Multiplatform Markdown Renderer for Android
102103
implementation("com.mikepenz:multiplatform-markdown-renderer:0.38.1")
103104
implementation("com.mikepenz:multiplatform-markdown-renderer-m3:0.38.1")
104105
}
105106
}
106-
107+
107108
val jsMain by getting {
108109
dependencies {
109110
implementation(compose.html.core)
@@ -131,18 +132,19 @@ android {
131132

132133
packaging {
133134
resources {
134-
excludes += setOf(
135-
"META-INF/INDEX.LIST",
136-
"META-INF/DEPENDENCIES",
137-
"META-INF/LICENSE",
138-
"META-INF/LICENSE.txt",
139-
"META-INF/license.txt",
140-
"META-INF/NOTICE",
141-
"META-INF/NOTICE.txt",
142-
"META-INF/notice.txt",
143-
"META-INF/*.kotlin_module",
144-
"META-INF/io.netty.versions.properties"
145-
)
135+
excludes +=
136+
setOf(
137+
"META-INF/INDEX.LIST",
138+
"META-INF/DEPENDENCIES",
139+
"META-INF/LICENSE",
140+
"META-INF/LICENSE.txt",
141+
"META-INF/license.txt",
142+
"META-INF/NOTICE",
143+
"META-INF/NOTICE.txt",
144+
"META-INF/notice.txt",
145+
"META-INF/*.kotlin_module",
146+
"META-INF/io.netty.versions.properties"
147+
)
146148
}
147149
}
148150

@@ -184,3 +186,16 @@ tasks.register("printClasspath") {
184186
println(configurations["jvmRuntimeClasspath"].asPath)
185187
}
186188
}
189+
190+
// Ktlint configuration
191+
configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
192+
version.set("1.0.1")
193+
android.set(true)
194+
outputToConsole.set(true)
195+
ignoreFailures.set(true)
196+
197+
filter {
198+
exclude("**/generated/**")
199+
exclude("**/build/**")
200+
}
201+
}

mpp-ui/src/androidMain/kotlin/cc/unitmesh/devins/ui/MainActivity.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,3 @@ class MainActivity : ComponentActivity() {
2929
}
3030
}
3131
}
32-
33-
34-

mpp-ui/src/androidMain/kotlin/cc/unitmesh/devins/ui/compose/sketch/MarkdownSketchRenderer.android.kt

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,30 @@ import com.mikepenz.markdown.m3.Markdown
1717
* 使用 Compose + multiplatform-markdown-renderer
1818
*/
1919
actual object MarkdownSketchRenderer {
20-
2120
@Composable
2221
actual fun RenderResponse(
2322
content: String,
2423
isComplete: Boolean,
2524
modifier: Modifier
2625
) {
2726
val scrollState = rememberScrollState()
28-
27+
2928
// 自动滚动到底部
3029
LaunchedEffect(content) {
3130
if (content.isNotEmpty()) {
3231
scrollState.animateScrollTo(scrollState.maxValue)
3332
}
3433
}
35-
34+
3635
Column(
37-
modifier = modifier
38-
.verticalScroll(scrollState)
39-
.padding(16.dp)
36+
modifier =
37+
modifier
38+
.verticalScroll(scrollState)
39+
.padding(16.dp)
4040
) {
4141
// 使用 CodeFence 解析内容
4242
val codeFences = CodeFence.parseAll(content)
43-
43+
4444
codeFences.forEach { fence ->
4545
when (fence.languageId.lowercase()) {
4646
"markdown", "md", "" -> {
@@ -69,7 +69,7 @@ actual object MarkdownSketchRenderer {
6969
}
7070
}
7171
}
72-
72+
7373
// 如果未完成,显示加载指示器
7474
if (!isComplete && content.isNotEmpty()) {
7575
Spacer(modifier = Modifier.height(8.dp))
@@ -79,7 +79,7 @@ actual object MarkdownSketchRenderer {
7979
}
8080
}
8181
}
82-
82+
8383
/**
8484
* 渲染 Markdown 文本
8585
* 使用 multiplatform-markdown-renderer 的 Markdown 组件
@@ -89,9 +89,10 @@ actual object MarkdownSketchRenderer {
8989
Card(
9090
modifier = Modifier.fillMaxWidth(),
9191
shape = RoundedCornerShape(8.dp),
92-
colors = CardDefaults.cardColors(
93-
containerColor = MaterialTheme.colorScheme.surface
94-
),
92+
colors =
93+
CardDefaults.cardColors(
94+
containerColor = MaterialTheme.colorScheme.surface
95+
),
9596
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
9697
) {
9798
// 使用 multiplatform-markdown-renderer 渲染 Markdown
@@ -101,32 +102,39 @@ actual object MarkdownSketchRenderer {
101102
)
102103
}
103104
}
104-
105+
105106
/**
106107
* 渲染代码块
107108
* 使用 Material Card 包装,显示语言标签和代码内容
108109
*/
109110
@Composable
110-
private fun CodeBlockRenderer(code: String, language: String, displayName: String = language) {
111+
private fun CodeBlockRenderer(
112+
code: String,
113+
language: String,
114+
displayName: String = language
115+
) {
111116
Card(
112117
modifier = Modifier.fillMaxWidth(),
113118
shape = RoundedCornerShape(8.dp),
114-
colors = CardDefaults.cardColors(
115-
containerColor = MaterialTheme.colorScheme.surfaceVariant
116-
),
119+
colors =
120+
CardDefaults.cardColors(
121+
containerColor = MaterialTheme.colorScheme.surfaceVariant
122+
),
117123
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
118124
) {
119125
Column(
120-
modifier = Modifier
121-
.fillMaxWidth()
122-
.padding(16.dp)
126+
modifier =
127+
Modifier
128+
.fillMaxWidth()
129+
.padding(16.dp)
123130
) {
124131
// 语言标签
125132
if (displayName.isNotEmpty() && displayName != "markdown") {
126133
Row(
127-
modifier = Modifier
128-
.fillMaxWidth()
129-
.padding(bottom = 12.dp),
134+
modifier =
135+
Modifier
136+
.fillMaxWidth()
137+
.padding(bottom = 12.dp),
130138
horizontalArrangement = Arrangement.SpaceBetween
131139
) {
132140
Text(
@@ -140,22 +148,23 @@ actual object MarkdownSketchRenderer {
140148
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.2f)
141149
)
142150
}
143-
151+
144152
// 将代码内容用 Markdown 代码块格式包装,让 Markdown 渲染器处理
145-
val codeBlock = if (displayName.isNotEmpty() && displayName != "markdown") {
146-
"```$language\n$code\n```"
147-
} else {
148-
"```\n$code\n```"
149-
}
150-
153+
val codeBlock =
154+
if (displayName.isNotEmpty() && displayName != "markdown") {
155+
"```$language\n$code\n```"
156+
} else {
157+
"```\n$code\n```"
158+
}
159+
151160
Markdown(
152161
content = codeBlock,
153162
modifier = Modifier.fillMaxWidth()
154163
)
155164
}
156165
}
157166
}
158-
167+
159168
@Composable
160169
actual fun RenderPlainText(
161170
text: String,
@@ -164,9 +173,10 @@ actual object MarkdownSketchRenderer {
164173
Card(
165174
modifier = modifier.fillMaxWidth(),
166175
shape = RoundedCornerShape(8.dp),
167-
colors = CardDefaults.cardColors(
168-
containerColor = MaterialTheme.colorScheme.surface
169-
)
176+
colors =
177+
CardDefaults.cardColors(
178+
containerColor = MaterialTheme.colorScheme.surface
179+
)
170180
) {
171181
Text(
172182
text = text,
@@ -176,7 +186,7 @@ actual object MarkdownSketchRenderer {
176186
)
177187
}
178188
}
179-
189+
180190
@Composable
181191
actual fun RenderMarkdown(
182192
markdown: String,
@@ -188,5 +198,3 @@ actual object MarkdownSketchRenderer {
188198
)
189199
}
190200
}
191-
192-

0 commit comments

Comments
 (0)