Skip to content

Commit cc887f5

Browse files
authored
SOLR-17672: Enable spotless for Kotlin files (#3450)
* Add spotless for kotlin and kotlin DSL (multiplatform) * Format source code * Add explicit import layout rule Add explicit import layout rule with alphabetical ordering and alias imports at the end.
1 parent 585b1d0 commit cc887f5

58 files changed

Lines changed: 241 additions & 190 deletions

File tree

Some content is hidden

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

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,20 @@ ij_java_wrap_first_method_in_call_chain = false
348348
ij_java_wrap_long_lines = true
349349
ij_java_wrap_semicolon_after_call_chain = false
350350

351+
[{*.kt,*.kts}]
352+
indent_size = 4
353+
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
354+
355+
# Disable wildcard imports entirely
356+
ij_kotlin_name_count_to_use_star_import = 2147483647
357+
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
358+
ij_kotlin_packages_to_use_import_on_demand = unset
359+
360+
ktlint_code_style = intellij_idea
361+
ktlint_function_naming_ignore_when_annotated_with = Composable
362+
compose_allowed_composition_locals = LocalExtendedColorScheme, LocalExtendedTypography
363+
ij_kotlin_imports_layout=*,^
364+
351365
[*.adoc]
352366
indent_size = 4
353367
ij_asciidoc_blank_lines_after_header = 1

gradle/libs.versions.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ compose = "1.8.2"
7777
cutterslade-analyze = "1.10.0"
7878
cybozulabs-langdetect = "1.1-20120112"
7979
decompose = "3.3.0"
80-
diffplug-spotless = "6.5.2"
80+
diffplug-spotless = "7.2.1"
8181
dropwizard-metrics = "4.2.26"
8282
eclipse-ecj = "3.39.0"
8383
eclipse-jetty = "12.0.19"
@@ -150,6 +150,8 @@ kotlinx-browser = "0.3"
150150
kotlinx-coroutines = "1.10.1"
151151
kotlinx-datetime = "0.7.1"
152152
kotlinx-serialization = "1.9.0"
153+
# @keep used by spotless
154+
ktlint = "1.7.1"
153155
ktor = "3.2.2"
154156
langchain4j = "0.35.0"
155157
# @keep Link checker version used in ref-guide
@@ -165,6 +167,7 @@ netty = "4.1.114.Final"
165167
# @keep for version alignment
166168
netty-tcnative = "2.0.66.Final"
167169
nimbusds-josejwt = "9.48"
170+
nlopez-compose = "0.4.26"
168171
nodegradle-node = "7.0.1"
169172
# @keep Node JS version used in node.gradle (LTS)
170173
nodejs = "16.20.2"
@@ -469,6 +472,7 @@ netty-transport-classes-epoll = { module = "io.netty:netty-transport-classes-epo
469472
# @keep transitive dependency for version alignment
470473
netty-transport-native-epoll = { module = "io.netty:netty-transport-native-epoll", version.ref = "netty" }
471474
nimbusds-josejwt = { module = "com.nimbusds:nimbus-jose-jwt", version.ref = "nimbusds-josejwt" }
475+
nlopez-compose-ktlintrules = { module = "io.nlopez.compose.rules:ktlint", version.ref = "nlopez-compose" }
472476
openjdk-jmh-core = { module = "org.openjdk.jmh:jmh-core", version.ref = "openjdk-jmh" }
473477
openjdk-jmh-generatorannprocess = { module = "org.openjdk.jmh:jmh-generator-annprocess", version.ref = "openjdk-jmh" }
474478
opentelemetry-api = { module = "io.opentelemetry:opentelemetry-api", version.ref = "opentelemetry" }

gradle/validation/spotless.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ configure(allprojects) { prj ->
8787
}
8888
}
8989

90+
// Configure spotless for kotlin sources
91+
plugins.withId("org.jetbrains.kotlin.multiplatform") {
92+
prj.apply plugin: libs.plugins.diffplug.spotless.get().pluginId
93+
94+
spotless {
95+
kotlin {
96+
// Apply to all Kotlin and Kotlin DSL files
97+
target "**/*.kt", "**/*.kts"
98+
99+
ktlint(libs.versions.ktlint.get())
100+
.customRuleSets([libs.nlopez.compose.ktlintrules.get().toString()])
101+
}
102+
}
103+
}
104+
90105
// Emit a custom message about how to fix formatting errors.
91106
tasks.matching { task -> task.name == "spotlessJavaCheck" }.configureEach {
92107
it.runToFixMessage.set("\nIMPORTANT: run the top-level './gradlew tidy' to format code automatically (see help/formatting.txt for more info).")

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/auth/store/BasicAuthStoreProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.arkivanov.mvikotlin.core.store.SimpleBootstrapper
2222
import com.arkivanov.mvikotlin.core.store.Store
2323
import com.arkivanov.mvikotlin.core.store.StoreFactory
2424
import com.arkivanov.mvikotlin.extensions.coroutines.CoroutineExecutor
25+
import kotlin.coroutines.CoroutineContext
2526
import kotlinx.coroutines.CoroutineExceptionHandler
2627
import kotlinx.coroutines.launch
2728
import kotlinx.coroutines.withContext
@@ -31,8 +32,7 @@ import org.apache.solr.ui.components.auth.store.BasicAuthStore.State
3132
import org.apache.solr.ui.domain.AuthMethod
3233
import org.apache.solr.ui.errors.InvalidCredentialsException
3334
import org.apache.solr.ui.errors.UnauthorizedException
34-
import org.apache.solr.ui.errors.parseError
35-
import kotlin.coroutines.CoroutineContext
35+
import org.apache.solr.ui.utils.parseError
3636

3737
class BasicAuthStoreProvider(
3838
private val storeFactory: StoreFactory,

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/EnvironmentComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ interface EnvironmentComponent {
3737
val jvm: JvmData = JvmData(),
3838
val javaProperties: List<JavaProperty> = emptyList(),
3939
)
40-
}
40+
}

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/data/JvmMemoryRaw.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ data class JvmMemoryRaw(
2828
val used: Int = 0,
2929
@SerialName("used%")
3030
val usedPercentage: Double = 0.0,
31-
)
31+
)

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/data/SecurityConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ import kotlinx.serialization.Serializable
2222
@Serializable
2323
data class SecurityConfig(
2424
val tls: Boolean = false,
25-
)
25+
)

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/data/SystemInformation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ data class SystemInformation(
3939
val totalSwapSpaceSize: Long = 0,
4040
val maxFileDescriptorCount: Long = 0,
4141
val openFileDescriptorCount: Long = 0,
42-
)
42+
)

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/data/SystemMode.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import kotlinx.serialization.Serializable
2323
@Serializable
2424
enum class SystemMode {
2525
Unknown,
26+
2627
@SerialName("solrcloud")
2728
SolrCloud,
29+
2830
@SerialName("std")
2931
Standalone,
3032
}

solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/integration/DefaultEnvironmentComponent.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class DefaultEnvironmentComponent(
3636
componentContext: AppComponentContext,
3737
storeFactory: StoreFactory,
3838
httpClient: HttpClient,
39-
) : EnvironmentComponent, AppComponentContext by componentContext {
39+
) : EnvironmentComponent,
40+
AppComponentContext by componentContext {
4041

4142
private val mainScope = coroutineScope(SupervisorJob() + mainContext)
4243
private val ioScope = coroutineScope(SupervisorJob() + ioContext)

0 commit comments

Comments
 (0)