Skip to content

Commit

Permalink
Update kotlinter to v4 (#4488)
Browse files Browse the repository at this point in the history
* Use Suppress annotation for ktlint rules
* Fix enum-wrapping
* Fix comments
* Fix backing-property-naming
* Fix function-naming
* Fix if-else-wrapping and if-else-bracing
* Fix no-empty-file
* Fix try-catch-finally-spacing
* Fix multiline-loop
* Fix statement-wrapping
* Remove redundant opt-ins
* Fix condition-wrapping

---------
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Osip Fatkullin <[email protected]>
  • Loading branch information
renovate[bot] authored Dec 11, 2024
1 parent 7c881cb commit 17839c5
Show file tree
Hide file tree
Showing 309 changed files with 1,145 additions and 919 deletions.
17 changes: 13 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ indent_size = 2
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
ij_kotlin_packages_to_use_import_on_demand = java.util.*, io.ktor.**

ktlint_code_style = intellij_idea
ktlint_standard_annotation = disabled
ktlint_standard_class-naming = disabled
ktlint_standard_class-signature = disabled
ktlint_standard_comment-wrapping = disabled
ktlint_standard_filename = disabled
ktlint_standard_function-expression-body = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_if-else-bracing = enabled
ktlint_standard_if-else-wrapping = enabled
ktlint_standard_no-consecutive-comments = enabled
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_property-naming = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_filename = disabled
ktlint_standard_class-naming = disabled
ktlint_standard_annotation = disabled
ktlint_standard_comment-wrapping = disabled
ktlint_standard_try-catch-finally-spacing = enabled

[*.kts]
# Always use wildcard imports in scripts
Expand Down
12 changes: 1 addition & 11 deletions buildSrc/src/main/kotlin/KotlinExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
import org.gradle.api.*
import org.gradle.kotlin.dsl.*
Expand Down Expand Up @@ -47,16 +47,6 @@ fun NamedDomainObjectContainer<KotlinSourceSet>.jvmAndPosixTest(block: KotlinSou
block(sourceSet)
}

fun NamedDomainObjectContainer<KotlinSourceSet>.jvmAndNixMain(block: KotlinSourceSet.() -> Unit) {
val sourceSet = findByName("jvmAndNixMain") ?: getByName("jvmMain")
block(sourceSet)
}

fun NamedDomainObjectContainer<KotlinSourceSet>.jvmAndNixTest(block: KotlinSourceSet.() -> Unit) {
val sourceSet = findByName("jvmAndNixTest") ?: getByName("jvmTest")
block(sourceSet)
}

fun NamedDomainObjectContainer<KotlinSourceSet>.nixTest(block: KotlinSourceSet.() -> Unit) {
val sourceSet = findByName("nixTest") ?: return
block(sourceSet)
Expand Down
10 changes: 2 additions & 8 deletions buildSrc/src/main/kotlin/TargetsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ import java.io.*
private val Project.files: Array<File> get() = project.projectDir.listFiles() ?: emptyArray()
val Project.hasCommon: Boolean get() = files.any { it.name == "common" }
val Project.hasJvmAndPosix: Boolean get() = hasCommon || files.any { it.name == "jvmAndPosix" }
val Project.hasJvmAndNix: Boolean get() = hasCommon || files.any { it.name == "jvmAndNix" }
val Project.hasPosix: Boolean get() = hasCommon || hasJvmAndPosix || files.any { it.name == "posix" }
val Project.hasDesktop: Boolean get() = hasPosix || files.any { it.name == "desktop" }
val Project.hasNix: Boolean get() = hasPosix || hasJvmAndNix || files.any { it.name == "nix" }
val Project.hasNix: Boolean get() = hasPosix || files.any { it.name == "nix" }
val Project.hasLinux: Boolean get() = hasNix || files.any { it.name == "linux" }
val Project.hasDarwin: Boolean get() = hasNix || files.any { it.name == "darwin" }
val Project.hasAndroidNative: Boolean get() = hasPosix || files.any { it.name == "androidNative" }
val Project.hasWindows: Boolean get() = hasPosix || files.any { it.name == "windows" }
val Project.hasJsAndWasmShared: Boolean get() = files.any { it.name == "jsAndWasmShared" }
val Project.hasJs: Boolean get() = hasCommon || files.any { it.name == "js" } || hasJsAndWasmShared
val Project.hasWasmJs: Boolean get() = hasCommon || files.any { it.name == "wasmJs" } || hasJsAndWasmShared
val Project.hasJvm: Boolean get() = hasCommon || hasJvmAndNix || hasJvmAndPosix || files.any { it.name == "jvm" }
val Project.hasJvm: Boolean get() = hasCommon || hasJvmAndPosix || files.any { it.name == "jvm" }

val Project.hasExplicitNative: Boolean
get() = hasNix || hasPosix || hasLinux || hasAndroidNative || hasDarwin || hasDesktop || hasWindows
Expand Down Expand Up @@ -110,11 +109,6 @@ private val hierarchyTemplate = KotlinHierarchyTemplate {
group("posix")
}

group("jvmAndNix") {
withJvm()
group("nix")
}

group("desktop") {
group("linux")
group("windows")
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/test/server/tests/Events.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package test.server.tests

import io.ktor.http.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*

@OptIn(ExperimentalStdlibApi::class)
internal fun Application.serializationTestServer() {
routing {
route("/json") {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serialization = "1.7.3"
binaryCompatibilityValidator = "0.16.3"
dokka = "1.9.20"
kover = "0.8.3"
ktlint = "3.15.0"
ktlint = "4.5.0"
kotlinx-browser = "0.2"

# Used for test server in buildSrc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package io.ktor.client.engine.apache

import io.ktor.client.engine.*
import org.apache.http.client.config.*
import org.apache.http.impl.nio.client.*
import javax.net.ssl.*
import org.apache.http.client.config.RequestConfig
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder
import javax.net.ssl.SSLContext

/**
* A configuration for the [Apache] client engine.
Expand Down Expand Up @@ -64,14 +64,14 @@ public class ApacheEngineConfig : HttpClientEngineConfig() {
*/
public fun customizeRequest(block: RequestConfig.Builder.() -> Unit) {
val current = customRequest
customRequest = { current(); block(); this }
customRequest = { current().apply(block) }
}

/**
* Customizes a [HttpAsyncClientBuilder] in the specified [block].
*/
public fun customizeClient(block: HttpAsyncClientBuilder.() -> Unit) {
val current = customClient
customClient = { current(); block(); this }
customClient = { current().apply(block) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class RequestProducerTest {
producer.close()
}

@OptIn(DelicateCoroutinesApi::class, InternalAPI::class)
@OptIn(DelicateCoroutinesApi::class)
@Test
fun testProducingReadChannelContent() = runTest {
val content = ByteChannel(true)
Expand Down Expand Up @@ -171,8 +171,9 @@ class RequestProducerTest {
repeat(1000) {
val body = ChannelWriterContent(
body = {
for (i in 0 until sampleSize)
for (i in 0 until sampleSize) {
writeByte(i.toByte())
}
},
contentType = null
)
Expand Down Expand Up @@ -231,7 +232,6 @@ private class TestEncoder : ContentEncoder {
src.limit()
}

@OptIn(InternalAPI::class)
override fun complete() {
channel.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package io.ktor.client.engine.apache5

import io.ktor.client.engine.*
import org.apache.hc.client5.http.config.*
import org.apache.hc.client5.http.impl.async.*
import javax.net.ssl.*
import org.apache.hc.client5.http.config.RequestConfig
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder
import javax.net.ssl.SSLContext

/**
* A configuration for the [Apache5] client engine.
Expand Down Expand Up @@ -56,14 +56,14 @@ public class Apache5EngineConfig : HttpClientEngineConfig() {
*/
public fun customizeRequest(block: RequestConfig.Builder.() -> Unit) {
val current = customRequest
customRequest = { current(); block(); this }
customRequest = { current().apply(block) }
}

/**
* Customizes a [HttpAsyncClientBuilder] in the specified [block].
*/
public fun customizeClient(block: HttpAsyncClientBuilder.() -> Unit) {
val current = customClient
customClient = { current(); block(); this }
customClient = { current().apply(block) }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.client.engine.apache5
Expand All @@ -22,6 +22,7 @@ import java.nio.*
import java.util.concurrent.*
import kotlin.coroutines.*

@Suppress("FunctionName")
@OptIn(InternalAPI::class)
internal fun ApacheRequestProducer(
requestData: HttpRequestData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ internal class ApacheResponseConsumer(
responseChannel.cancel(mappedCause)
}

@OptIn(InternalAPI::class)
internal fun close() {
channel.close()
consumerJob.complete()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.client.engine.cio

Expand All @@ -18,7 +18,7 @@ import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.sync.*
import kotlinx.io.EOFException
import kotlinx.io.*
import java.nio.channels.*
import kotlin.coroutines.*
import io.ktor.utils.io.ByteChannel as KtorByteChannel
Expand Down Expand Up @@ -61,9 +61,7 @@ internal actual class ConnectionPipeline actual constructor(
} catch (_: CancellationException) {
} finally {
responseChannel.close()
/**
* Workaround bug with socket.close
*/
// Workaround bug with socket.close
// outputChannel.close()
}
}
Expand Down Expand Up @@ -109,7 +107,9 @@ internal actual class ConnectionPipeline actual constructor(
val proxyChannel = KtorByteChannel()
skipTask = skipCancels(responseChannel, proxyChannel)
proxyChannel
} else ByteReadChannel.Empty
} else {
ByteReadChannel.Empty
}

callJob.invokeOnCompletion {
body.cancel()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.client.plugins.websocket.cio
Expand Down Expand Up @@ -37,7 +37,9 @@ public suspend fun HttpClient.webSocketRawSession(
session.outgoing.invokeOnClose {
if (it != null) {
sessionCompleted.completeExceptionally(it)
} else sessionCompleted.complete(Unit)
} else {
sessionCompleted.complete(Unit)
}
}
sessionCompleted.await()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class ConnectErrorsTest {
}
client.getInputStream().readBytes()
}
} catch (_: Exception) { }
} catch (_: Exception) {
}
}
assertEquals("OK", client.get("http://localhost:${serverSocket.localPort}/").body())
thread.join()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ktlint-disable filename
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.client.engine.cio

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import io.ktor.util.collections.*
import io.ktor.util.network.*
import io.ktor.utils.io.*
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
import kotlin.coroutines.*
import kotlinx.coroutines.channels.ClosedSendChannelException
import kotlin.coroutines.CoroutineContext

@OptIn(InternalAPI::class, DelicateCoroutinesApi::class)
internal class CIOEngine(
Expand Down Expand Up @@ -61,7 +61,6 @@ internal class CIOEngine(
val requestJob = requestField[Job]!!
val selector = selectorManager

@OptIn(ExperimentalCoroutinesApi::class)
GlobalScope.launch(parentContext, start = CoroutineStart.ATOMIC) {
try {
requestJob.join()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ktlint-disable filename
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.client.engine.cio

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ internal class Endpoint(
deliveryPoint.send(task)
}

@OptIn(InternalAPI::class)
private suspend fun makeDedicatedRequest(
request: HttpRequestData,
callContext: CoroutineContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.util.date.*
import io.ktor.utils.io.*
import kotlinx.coroutines.*
import kotlin.coroutines.*
import kotlinx.coroutines.CompletableDeferred
import kotlin.coroutines.CoroutineContext

internal data class RequestTask(
val request: HttpRequestData,
Expand All @@ -19,9 +19,11 @@ internal data class RequestTask(
)

@OptIn(InternalAPI::class)
internal fun HttpRequestData.requiresDedicatedConnection(): Boolean = listOf(headers, body.headers).any {
it[HttpHeaders.Connection] == "close" || it.contains(HttpHeaders.Upgrade)
} || method !in listOf(HttpMethod.Get, HttpMethod.Head) || containsCustomTimeouts() || isSseRequest()
internal fun HttpRequestData.requiresDedicatedConnection(): Boolean =
listOf(headers, body.headers).any { it[HttpHeaders.Connection] == "close" || it.contains(HttpHeaders.Upgrade) } ||
method !in listOf(HttpMethod.Get, HttpMethod.Head) ||
containsCustomTimeouts() ||
isSseRequest()

internal data class ConnectionResponseTask(
val requestTime: GMTDate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ktlint-disable filename
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.client.engine.cio

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public open class HttpClientCall(
* @throws NoTransformationFoundException If no transformation is found for the type [info].
* @throws DoubleReceiveException If already called [body].
*/
@OptIn(InternalAPI::class)
public suspend fun bodyNullable(info: TypeInfo): Any? {
try {
if (response.instanceOf(info.type)) return response
Expand Down Expand Up @@ -107,7 +106,6 @@ public open class HttpClientCall(
* @throws DoubleReceiveException If already called [body].
* @throws NullPointerException If content is `null`.
*/
@OptIn(InternalAPI::class)
public suspend fun body(info: TypeInfo): Any = bodyNullable(info)!!

override fun toString(): String = "HttpClientCall[${request.url}, ${response.status}]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ private val LOGGER = KtorSimpleLogger("io.ktor.client.plugins.defaultTransformer
* Usually installed by default so there is no need to use it
* unless you have disabled it via [HttpClientConfig.useDefaultTransformers].
*/
@OptIn(InternalAPI::class)
public fun HttpClient.defaultTransformers() {
requestPipeline.intercept(HttpRequestPipeline.Render) { body ->
if (context.headers[HttpHeaders.Accept] == null) {
Expand Down
Loading

0 comments on commit 17839c5

Please sign in to comment.