Skip to content

Commit d3c1d26

Browse files
committed
Treat warnings as errors
1 parent 34cf5b1 commit d3c1d26

File tree

7 files changed

+60
-40
lines changed

7 files changed

+60
-40
lines changed

extensions/google-java/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ plugins {
88
id("com.vanniktech.maven.publish.base")
99
}
1010

11+
kotlin {
12+
compilerOptions.allWarningsAsErrors.set(true)
13+
}
14+
1115
sourceSets {
1216
main {
1317
java {

extensions/google-javalite/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ plugins {
88
id("com.vanniktech.maven.publish.base")
99
}
1010

11+
kotlin {
12+
compilerOptions.allWarningsAsErrors.set(true)
13+
}
14+
1115
dependencies {
1216
testImplementation(libs.assertj)
1317
testImplementation(libs.junit)

library/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ plugins {
88
alias(libs.plugins.ksp)
99
}
1010

11+
kotlin {
12+
compilerOptions.allWarningsAsErrors.set(true)
13+
}
14+
1115
dependencies {
1216
testImplementation(libs.assertj)
1317
testImplementation(libs.junit)

okhttp/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ plugins {
77
id("com.vanniktech.maven.publish.base")
88
}
99

10+
kotlin {
11+
compilerOptions.allWarningsAsErrors.set(true)
12+
}
13+
1014
dependencies {
1115
api(libs.okhttp.core)
1216
implementation(libs.kotlin.coroutines.core)

protoc-gen-connect-kotlin/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ application {
1414
mainClass.set("com.connectrpc.protocgen.connect.Main")
1515
}
1616

17+
kotlin {
18+
compilerOptions.allWarningsAsErrors.set(true)
19+
}
20+
1721
tasks {
1822
jar {
1923
manifest {

protoc-gen-connect-kotlin/src/main/kotlin/com/connectrpc/protocgen/connect/internal/ProtoHelpers.kt

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ internal fun parseGeneratorParameter(
7676
* `java_multiple_files` options specified in the .proto file.
7777
*/
7878
internal fun getProtocJavaFileName(descriptor: Descriptors.Descriptor): String {
79-
var descriptor = descriptor
8079
val fullName: String
8180
if (descriptor.file.options.javaMultipleFiles) {
8281
var containingType: Descriptors.Descriptor
83-
while (descriptor.containingType.also { containingType = it } != null) {
84-
descriptor = containingType
82+
var currentDescriptor = descriptor
83+
while (currentDescriptor.containingType.also { containingType = it } != null) {
84+
currentDescriptor = containingType
8585
}
86-
fullName = getClassName(descriptor)
86+
fullName = getClassName(currentDescriptor)
8787
} else {
8888
fullName = getClassNameForFile(descriptor.file)
8989
}
@@ -214,14 +214,14 @@ internal fun getFileJavaPackage(file: FileDescriptor): String {
214214
* `java_multiple_files` options specified in the .proto file.
215215
*/
216216
fun getJavaFileName(descriptor: Descriptors.Descriptor): String {
217-
var descriptor: Descriptors.Descriptor = descriptor
218217
val fullName: String
219218
if (descriptor.file.options.javaMultipleFiles) {
219+
var currentDescriptor = descriptor
220220
var containingType: Descriptors.Descriptor?
221-
while (descriptor.containingType.also { containingType = it } != null) {
222-
descriptor = containingType!!
221+
while (currentDescriptor.containingType.also { containingType = it } != null) {
222+
currentDescriptor = containingType!!
223223
}
224-
fullName = getClassName(descriptor)
224+
fullName = getClassName(currentDescriptor)
225225
} else {
226226
fullName = getClassNameForFile(descriptor.file)
227227
}
@@ -317,44 +317,44 @@ private fun getFieldName(field: Descriptors.FieldDescriptor): String {
317317
* letter should be upper-case or lower-case.
318318
*
319319
* @param input string to be converted
320-
* @param capNextLetter `true` if the first letter should be turned to
320+
* @param capFirstLetter `true` if the first letter should be turned to
321321
* upper-case.
322322
* @return the camel-cased string
323323
*/
324324
private fun underscoresToCamelCaseImpl(
325325
input: String,
326-
capNextLetter: Boolean,
327-
): String {
328-
var capNextLetter = capNextLetter
329-
val result = StringBuilder(input.length)
330-
var i = 0
331-
val l = input.length
332-
while (i < l) {
333-
val c = input[i]
334-
capNextLetter = if ('a' <= c && c <= 'z') {
335-
if (capNextLetter) {
336-
result.append((c.code + ('A'.code - 'a'.code)).toChar())
337-
} else {
338-
result.append(c)
326+
capFirstLetter: Boolean,
327+
): String = buildString(input.length) {
328+
var capNextLetter = capFirstLetter
329+
for ((i, c) in input.withIndex()) {
330+
capNextLetter = when (c) {
331+
in 'a'..'z' -> {
332+
if (capNextLetter) {
333+
append(c.uppercaseChar())
334+
} else {
335+
append(c)
336+
}
337+
false
339338
}
340-
false
341-
} else if ('A' <= c && c <= 'Z') {
342-
if (i == 0 && !capNextLetter) {
343-
// Force first letter to lower-case unless explicitly told
344-
// to capitalize it.
345-
result.append((c.code + ('a'.code - 'A'.code)).toChar())
346-
} else {
347-
// Capital letters after the first are left as-is.
348-
result.append(c)
339+
340+
in 'A'..'Z' -> {
341+
if (i == 0 && !capNextLetter) {
342+
// Force first letter to lower-case unless explicitly told
343+
// to capitalize it.
344+
append(c.lowercaseChar())
345+
} else {
346+
// Capital letters after the first are left as-is.
347+
append(c)
348+
}
349+
false
349350
}
350-
false
351-
} else if ('0' <= c && c <= '9') {
352-
result.append(c)
353-
true
354-
} else {
355-
true
351+
352+
in '0'..'9' -> {
353+
append(c)
354+
true
355+
}
356+
357+
else -> true
356358
}
357-
i++
358359
}
359-
return result.toString()
360360
}

protoc-gen-connect-kotlin/src/test/kotlin/PluginGenerationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ class PluginGenerationTest {
111111

112112
@Test
113113
fun evilCommentsCompiles() {
114-
val client = EvilCommentsServiceClient(mock { })
114+
EvilCommentsServiceClient(mock { })
115115
}
116116
}

0 commit comments

Comments
 (0)