Skip to content

Commit

Permalink
Treat warnings as errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbrooks committed Oct 20, 2023
1 parent 34cf5b1 commit d3c1d26
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 40 deletions.
4 changes: 4 additions & 0 deletions extensions/google-java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ plugins {
id("com.vanniktech.maven.publish.base")
}

kotlin {
compilerOptions.allWarningsAsErrors.set(true)
}

sourceSets {
main {
java {
Expand Down
4 changes: 4 additions & 0 deletions extensions/google-javalite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ plugins {
id("com.vanniktech.maven.publish.base")
}

kotlin {
compilerOptions.allWarningsAsErrors.set(true)
}

dependencies {
testImplementation(libs.assertj)
testImplementation(libs.junit)
Expand Down
4 changes: 4 additions & 0 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ plugins {
alias(libs.plugins.ksp)
}

kotlin {
compilerOptions.allWarningsAsErrors.set(true)
}

dependencies {
testImplementation(libs.assertj)
testImplementation(libs.junit)
Expand Down
4 changes: 4 additions & 0 deletions okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions protoc-gen-connect-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ application {
mainClass.set("com.connectrpc.protocgen.connect.Main")
}

kotlin {
compilerOptions.allWarningsAsErrors.set(true)
}

tasks {
jar {
manifest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ class PluginGenerationTest {

@Test
fun evilCommentsCompiles() {
val client = EvilCommentsServiceClient(mock { })
EvilCommentsServiceClient(mock { })
}
}

0 comments on commit d3c1d26

Please sign in to comment.