Skip to content

Commit 2b45842

Browse files
committed
detekt
1 parent a161d93 commit 2b45842

File tree

10 files changed

+59
-23
lines changed

10 files changed

+59
-23
lines changed

gradle-plugin/src/main/kotlin/kotlinx/rpc/buf/tasks/GenerateBufGenYaml.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ internal fun Project.registerGenerateBufGenYamlTask(
140140
configure: GenerateBufGenYaml.() -> Unit = {},
141141
): TaskProvider<GenerateBufGenYaml> {
142142
val capitalizeName = name.replaceFirstChar { it.uppercase() }
143-
val task = project.tasks.register("${GenerateBufGenYaml.NAME_PREFIX}$capitalizeName", GenerateBufGenYaml::class, properties)
143+
val task = project.tasks.register(
144+
"${GenerateBufGenYaml.NAME_PREFIX}$capitalizeName",
145+
GenerateBufGenYaml::class,
146+
properties,
147+
)
144148

145149
task.configure {
146150
val pluginsProvider = project.provider {

gradle-plugin/src/main/kotlin/kotlinx/rpc/protoc/DefaultProtoSourceSet.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,13 @@ internal open class DefaultProtoSourceSet(
175175
return
176176
}
177177

178-
if (this == protoSourceSet) {
179-
throw IllegalArgumentException("$name proto source set cannot extend from self")
178+
require(this != protoSourceSet) {
179+
"$name proto source set cannot extend from self"
180180
}
181181

182-
if (protoSourceSet !is DefaultProtoSourceSet) {
183-
throw IllegalArgumentException(
184-
"$name proto source set can only extend from other default proto source sets." +
185-
"${protoSourceSet.name} is not a ${DefaultProtoSourceSet::class.simpleName}",
186-
)
182+
require(protoSourceSet is DefaultProtoSourceSet) {
183+
"$name proto source set can only extend from other default proto source sets." +
184+
"${protoSourceSet.name} is not a ${DefaultProtoSourceSet::class.simpleName}"
187185
}
188186

189187
extendsFrom += protoSourceSet
@@ -209,8 +207,8 @@ internal open class DefaultProtoSourceSet(
209207
}
210208

211209
private fun ProtoSourceSet.checkSelfImport(): ProtoSourceSet {
212-
if (this@DefaultProtoSourceSet == this) {
213-
throw IllegalArgumentException("${this@DefaultProtoSourceSet.name} proto source set cannot import from itself")
210+
require(this@DefaultProtoSourceSet != this) {
211+
"${this@DefaultProtoSourceSet.name} proto source set cannot import from itself"
214212
}
215213

216214
return this

gradle-plugin/src/main/kotlin/kotlinx/rpc/protoc/DefaultProtocExtension.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ internal open class DefaultProtocExtension @Inject constructor(
336336
languageSets.filterIsInstance<AndroidSourceSet>().forEach { sourceSet ->
337337
// todo fails with
338338
//
339-
// Caused by: org.gradle.internal.typeconversion.UnsupportedNotationException: Cannot convert the provided notation to a File: [].
339+
// Caused by: org.gradle.internal.typeconversion.UnsupportedNotationException:
340+
// Cannot convert the provided notation to a File: [].
340341
// The following types/formats are supported:
341342
// - A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
342343
// - A String or CharSequence URI, for example 'file:/usr/include'.
@@ -366,6 +367,7 @@ internal open class DefaultProtocExtension @Inject constructor(
366367
}
367368
}
368369

370+
@Suppress("detekt.LongParameterList")
369371
private fun configureCustomTasks(
370372
protoSourceSet: DefaultProtoSourceSet,
371373
buildSourceSetsDir: File,
@@ -441,7 +443,9 @@ internal open class DefaultProtocExtension @Inject constructor(
441443
}
442444
}
443445

444-
private fun DefaultProtoSourceSet.getDependsOnImports(protoSourceSets: ProtoSourceSets): Provider<List<ProtoSourceSet>> {
446+
private fun DefaultProtoSourceSet.getDependsOnImports(
447+
protoSourceSets: ProtoSourceSets,
448+
): Provider<List<ProtoSourceSet>> {
445449
return languageSourceSets.map { list ->
446450
val kotlin = list.filterIsInstance<KotlinSourceSet>()
447451

@@ -564,6 +568,7 @@ private fun Project.configureMultiplatformWithAndroidSourceSets(body: (DefaultPr
564568
}
565569
}
566570

571+
@Suppress("detekt.CyclomaticComplexMethod")
567572
private fun AndroidComponents.configureLegacyAndroidVariants(
568573
project: Project,
569574
isKmp: Boolean,
@@ -603,7 +608,9 @@ private fun AndroidComponents.configureLegacyAndroidVariants(
603608
// but testFixtures still have source sets based on flavors
604609
val testFixtureSetNames = if (rootName != LegacyAndroidRootSourceSets.Main) {
605610
variant.dependencySourceSets(LegacyAndroidRootSourceSets.TestFixtures)
606-
} else emptyList()
611+
} else {
612+
emptyList()
613+
}
607614

608615
val dependencySourceSetNames = variant.dependencySourceSets(rootName)
609616
val variantSourceSetName = dependencySourceSetNames.lastOrNull()

gradle-plugin/src/main/kotlin/kotlinx/rpc/protoc/ProtoTask.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public interface ProtoTask : Task {
3030
*
3131
* For Kotlin/JVM it has only one source set (`main`, or `test`, for example).
3232
*
33-
* For Kotlin/Multiplatform it also has only one source set (`commonMain`, `commonTest`, or `jsMain`, for example).
33+
* For Kotlin/Multiplatform it also has only one source set
34+
* (`commonMain`, `commonTest`, or `jsMain`, for example).
3435
*
3536
* For Android, Kotlin/Android, and Kotlin/Multiplatform + Android it can have multiple source sets:
3637
* - `["androidMain", "androidDebug", "main", "debug"]`

gradle-plugin/src/main/kotlin/kotlinx/rpc/protoc/ProtoTasks.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ internal open class ProtoTasksImpl<ProtoTaskT : ProtoTask>(
257257
return matchingSourceSet(sourceSet.name)
258258
}
259259

260-
override fun matchingKotlinSourceSet(sourceSet: NamedDomainObjectProvider<KotlinSourceSet>): ProtoTasks<ProtoTaskT> {
260+
override fun matchingKotlinSourceSet(
261+
sourceSet: NamedDomainObjectProvider<KotlinSourceSet>,
262+
): ProtoTasks<ProtoTaskT> {
261263
return matchingSourceSet(sourceSet.name)
262264
}
263265

gradle-plugin/src/main/kotlin/kotlinx/rpc/protoc/android/variants.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ internal fun String.kotlinProxyFromAndroidOriginSourceSetName(rootName: LegacyAn
8989
"androidInstrumented${removePrefix("android").replaceFirstChar { it.uppercase() }}"
9090
}
9191

92-
LegacyAndroidRootSourceSets.TestFixtures -> null
92+
LegacyAndroidRootSourceSets.TestFixtures -> {
93+
null
94+
}
9395
}
9496
}
9597

gradle-plugin/src/main/kotlin/kotlinx/rpc/util/kgp.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ internal fun Project.withLegacyAndroid(action: LegacyAndroidApplied.() -> Unit)
8888

8989
internal class LegacyAndroidApplied(val project: Project, val id: String)
9090

91-
internal fun LegacyAndroidApplied.withAndroidSourceSets(action: (NamedDomainObjectContainer<out AndroidSourceSet>) -> Unit) {
91+
internal fun LegacyAndroidApplied.withAndroidSourceSets(
92+
action: (NamedDomainObjectContainer<out AndroidSourceSet>) -> Unit,
93+
) {
9294
action(project.the<BaseExtension>().sourceSets)
9395
}
9496

gradle-plugin/src/test/kotlin/kotlinx/rpc/GrpcAndroidProjectTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
@file:Suppress("detekt.LongMethod", "detekt.LargeClass")
6+
57
package kotlinx.rpc
68

79
import kotlinx.rpc.base.GrpcBaseTest

gradle-plugin/src/test/kotlin/kotlinx/rpc/GrpcKmpProjectTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
@file:Suppress("detekt.LongMethod", "detekt.LargeClass")
6+
57
package kotlinx.rpc
68

79
import kotlinx.rpc.base.GrpcBaseTest

gradle-plugin/src/test/kotlin/kotlinx/rpc/base/GrpcBaseTest.kt

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,20 @@ abstract class GrpcBaseTest : BaseTest() {
355355
extendedProto: List<SSets>,
356356
) {
357357
if (!sourceSet.applicable()) {
358-
println("Skipping ${sourceSet.capital} source set because it's not applicable for the current Kotlin version")
358+
println(
359+
"Skipping ${sourceSet.capital} source set " +
360+
"because it's not applicable for the current Kotlin version"
361+
)
359362
return
360363
}
361364

362365
val importsSet = imports
363366
.onEach {
364367
if (!it.applicable()) {
365-
println("Skipping ${it.capital} import source set because it's not applicable for the current Kotlin version")
368+
println(
369+
"Skipping ${it.capital} import source set " +
370+
"because it's not applicable for the current Kotlin version"
371+
)
366372
}
367373
}
368374
.filter { it.applicable() }
@@ -603,10 +609,16 @@ private val SSets.capital get() = name.replaceFirstChar { it.titlecase() }
603609

604610
private fun SSets.compileTaskName(mode: CompileTaskMode): String {
605611
return when (mode) {
606-
CompileTaskMode.Jvm -> if (name == "main") "compileKotlin" else "compileTestKotlin"
612+
CompileTaskMode.Jvm -> {
613+
if (name == "main") "compileKotlin" else "compileTestKotlin"
614+
}
607615
CompileTaskMode.Kmp -> {
608616
val platform = capital.removeSuffix("Main").removeSuffix("Test")
609-
if (name.endsWith("Test")) "compileTestKotlin$platform" else "compileKotlin$platform"
617+
if (name.endsWith("Test")) {
618+
"compileTestKotlin$platform"
619+
} else {
620+
"compileKotlin$platform"
621+
}
610622
}
611623

612624
CompileTaskMode.Android -> {
@@ -622,7 +634,9 @@ private fun SSets.compileTaskName(mode: CompileTaskMode): String {
622634
"compile${name.removePrefix("test")}UnitTestKotlin"
623635
}
624636

625-
else -> "compile${capital}Kotlin"
637+
else -> {
638+
"compile${capital}Kotlin"
639+
}
626640
}
627641
}
628642

@@ -640,7 +654,9 @@ private fun SSets.compileTaskName(mode: CompileTaskMode): String {
640654
"compile${withoutPrefix.removePrefix("UnitTest")}UnitTestKotlinAndroid"
641655
}
642656

643-
else -> "compile${withoutPrefix}KotlinAndroid"
657+
else -> {
658+
"compile${withoutPrefix}KotlinAndroid"
659+
}
644660
}
645661
}
646662

0 commit comments

Comments
 (0)