Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat warnings as errors in tool and library code #133

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I was in this function addressing the warning, I also changed parts of it to use kotlin idioms and standard library APIs. Those changes could easily be removed if you like, but they seem a little nicer to me.

): 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 { })
}
}