diff --git a/extensions/google-java/build.gradle.kts b/extensions/google-java/build.gradle.kts index 1219bcb8..fa9e1bab 100644 --- a/extensions/google-java/build.gradle.kts +++ b/extensions/google-java/build.gradle.kts @@ -8,6 +8,10 @@ plugins { id("com.vanniktech.maven.publish.base") } +kotlin { + compilerOptions.allWarningsAsErrors.set(true) +} + sourceSets { main { java { diff --git a/extensions/google-javalite/build.gradle.kts b/extensions/google-javalite/build.gradle.kts index 3695ac37..1347b4b6 100644 --- a/extensions/google-javalite/build.gradle.kts +++ b/extensions/google-javalite/build.gradle.kts @@ -8,6 +8,10 @@ plugins { id("com.vanniktech.maven.publish.base") } +kotlin { + compilerOptions.allWarningsAsErrors.set(true) +} + dependencies { testImplementation(libs.assertj) testImplementation(libs.junit) diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 17adb3be..20c2680c 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -8,6 +8,10 @@ plugins { alias(libs.plugins.ksp) } +kotlin { + compilerOptions.allWarningsAsErrors.set(true) +} + dependencies { testImplementation(libs.assertj) testImplementation(libs.junit) diff --git a/okhttp/build.gradle.kts b/okhttp/build.gradle.kts index a365e6f5..4b96f1fc 100644 --- a/okhttp/build.gradle.kts +++ b/okhttp/build.gradle.kts @@ -7,6 +7,10 @@ plugins { id("com.vanniktech.maven.publish.base") } +kotlin { + compilerOptions.allWarningsAsErrors.set(true) +} + dependencies { api(libs.okhttp.core) implementation(libs.kotlin.coroutines.core) diff --git a/protoc-gen-connect-kotlin/build.gradle.kts b/protoc-gen-connect-kotlin/build.gradle.kts index 41cc9269..a6398322 100644 --- a/protoc-gen-connect-kotlin/build.gradle.kts +++ b/protoc-gen-connect-kotlin/build.gradle.kts @@ -14,6 +14,10 @@ application { mainClass.set("com.connectrpc.protocgen.connect.Main") } +kotlin { + compilerOptions.allWarningsAsErrors.set(true) +} + tasks { jar { manifest { diff --git a/protoc-gen-connect-kotlin/src/main/kotlin/com/connectrpc/protocgen/connect/internal/ProtoHelpers.kt b/protoc-gen-connect-kotlin/src/main/kotlin/com/connectrpc/protocgen/connect/internal/ProtoHelpers.kt index 16168fae..b1ae1504 100644 --- a/protoc-gen-connect-kotlin/src/main/kotlin/com/connectrpc/protocgen/connect/internal/ProtoHelpers.kt +++ b/protoc-gen-connect-kotlin/src/main/kotlin/com/connectrpc/protocgen/connect/internal/ProtoHelpers.kt @@ -76,14 +76,14 @@ internal fun parseGeneratorParameter( * `java_multiple_files` options specified in the .proto file. */ internal fun getProtocJavaFileName(descriptor: Descriptors.Descriptor): String { - var descriptor = descriptor val fullName: String if (descriptor.file.options.javaMultipleFiles) { var containingType: Descriptors.Descriptor - while (descriptor.containingType.also { containingType = it } != null) { - descriptor = containingType + var currentDescriptor = descriptor + while (currentDescriptor.containingType.also { containingType = it } != null) { + currentDescriptor = containingType } - fullName = getClassName(descriptor) + fullName = getClassName(currentDescriptor) } else { fullName = getClassNameForFile(descriptor.file) } @@ -214,14 +214,14 @@ internal fun getFileJavaPackage(file: FileDescriptor): String { * `java_multiple_files` options specified in the .proto file. */ fun getJavaFileName(descriptor: Descriptors.Descriptor): String { - var descriptor: Descriptors.Descriptor = descriptor val fullName: String if (descriptor.file.options.javaMultipleFiles) { + var currentDescriptor = descriptor var containingType: Descriptors.Descriptor? - while (descriptor.containingType.also { containingType = it } != null) { - descriptor = containingType!! + while (currentDescriptor.containingType.also { containingType = it } != null) { + currentDescriptor = containingType!! } - fullName = getClassName(descriptor) + fullName = getClassName(currentDescriptor) } else { fullName = getClassNameForFile(descriptor.file) } @@ -317,44 +317,44 @@ private fun getFieldName(field: Descriptors.FieldDescriptor): String { * letter should be upper-case or lower-case. * * @param input string to be converted - * @param capNextLetter `true` if the first letter should be turned to + * @param capFirstLetter `true` if the first letter should be turned to * upper-case. * @return the camel-cased string */ private fun underscoresToCamelCaseImpl( input: String, - capNextLetter: Boolean, -): String { - var capNextLetter = capNextLetter - val result = StringBuilder(input.length) - var i = 0 - val l = input.length - while (i < l) { - val c = input[i] - capNextLetter = if ('a' <= c && c <= 'z') { - if (capNextLetter) { - result.append((c.code + ('A'.code - 'a'.code)).toChar()) - } else { - result.append(c) + capFirstLetter: Boolean, +): String = buildString(input.length) { + var capNextLetter = capFirstLetter + for ((i, c) in input.withIndex()) { + capNextLetter = when (c) { + in 'a'..'z' -> { + if (capNextLetter) { + append(c.uppercaseChar()) + } else { + append(c) + } + false } - false - } else if ('A' <= c && c <= 'Z') { - if (i == 0 && !capNextLetter) { - // Force first letter to lower-case unless explicitly told - // to capitalize it. - result.append((c.code + ('a'.code - 'A'.code)).toChar()) - } else { - // Capital letters after the first are left as-is. - result.append(c) + + in 'A'..'Z' -> { + if (i == 0 && !capNextLetter) { + // Force first letter to lower-case unless explicitly told + // to capitalize it. + append(c.lowercaseChar()) + } else { + // Capital letters after the first are left as-is. + append(c) + } + false } - false - } else if ('0' <= c && c <= '9') { - result.append(c) - true - } else { - true + + in '0'..'9' -> { + append(c) + true + } + + else -> true } - i++ } - return result.toString() } diff --git a/protoc-gen-connect-kotlin/src/test/kotlin/PluginGenerationTest.kt b/protoc-gen-connect-kotlin/src/test/kotlin/PluginGenerationTest.kt index 832dcd89..f1699b17 100644 --- a/protoc-gen-connect-kotlin/src/test/kotlin/PluginGenerationTest.kt +++ b/protoc-gen-connect-kotlin/src/test/kotlin/PluginGenerationTest.kt @@ -111,6 +111,6 @@ class PluginGenerationTest { @Test fun evilCommentsCompiles() { - val client = EvilCommentsServiceClient(mock { }) + EvilCommentsServiceClient(mock { }) } }