Skip to content

Commit

Permalink
Update ktlint version (#3657)
Browse files Browse the repository at this point in the history
* KTOR-5957 Update kotlinter version to 3.15.0
  • Loading branch information
e5l authored Jun 20, 2023
1 parent 4bd7334 commit cf1937b
Show file tree
Hide file tree
Showing 98 changed files with 526 additions and 300 deletions.
23 changes: 16 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
[*]
charset=utf-8
end_of_line=lf
insert_final_newline=true
indent_style=space
indent_size=4
max_line_length=120
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
max_line_length = 120

[*.json]
indent_size=2
indent_size = 2

[*.{kt,kts}]
ktlint_standard_no-wildcard-imports = 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
12 changes: 7 additions & 5 deletions buildSrc/src/main/kotlin/Codestyle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
* Copyright 2014-2021 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.api.tasks.*
import org.gradle.kotlin.dsl.*
import org.jmailen.gradle.kotlinter.tasks.*

fun Project.configureCodestyle() {
apply(plugin = "org.jmailen.kotlinter")

kotlinter.apply {
ignoreFailures = true
reporters = arrayOf("checkstyle", "plain")
experimentalRules = false
disabledRules = arrayOf(
"no-wildcard-imports",
"indent"
)
}

val editorconfigFile = rootProject.file(".editorconfig")
tasks.withType<LintTask> {
inputs.file(editorconfigFile).withPathSensitivity(PathSensitivity.RELATIVE)
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ coroutines-version = "1.7.1"
atomicfu-version = "0.18.5"
serialization-version = "1.5.1"
validator-version = "0.8.0"
ktlint-version = "3.10.0"
ktlint-version = "3.15.0"

netty-version = "4.1.92.Final"
netty-tcnative-version = "2.0.61.Final"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ internal fun ApacheRequestProducer(

return BasicRequestProducer(
setupRequest(requestData, config),
if (!hasContent && isGetOrHead) null
else ApacheRequestEntityProducer(requestData, callContext, contentLength, type, isChunked)
if (!hasContent && isGetOrHead) {
null
} else {
ApacheRequestEntityProducer(requestData, callContext, contentLength, type, isChunked)
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public suspend fun HttpClient.webSocketRawSession(
val sessionCompleted = CompletableDeferred<Unit>()
result.complete(session)
session.outgoing.invokeOnClose {
if (it != null) sessionCompleted.completeExceptionally(it)
else sessionCompleted.complete(Unit)
if (it != null) {
sessionCompleted.completeExceptionally(it)
} else sessionCompleted.complete(Unit)
}
sessionCompleted.await()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ public class HttpRequestRetry internal constructor(configuration: Configuration)
val subRequest = HttpRequestBuilder().takeFrom(request)
request.executionContext.invokeOnCompletion { cause ->
val subRequestJob = subRequest.executionContext as CompletableJob
if (cause == null) subRequestJob.complete()
else subRequestJob.completeExceptionally(cause)
if (cause == null) {
subRequestJob.complete()
} else subRequestJob.completeExceptionally(cause)
}
return subRequest
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ internal object ResponseHook :
}

internal object TransformRequestBodyHook :
ClientHook<suspend TransformRequestBodyContext.(
request: HttpRequestBuilder,
content: Any,
bodyType: TypeInfo?
) -> OutgoingContent?> {
ClientHook<
suspend TransformRequestBodyContext.(
request: HttpRequestBuilder,
content: Any,
bodyType: TypeInfo?
) -> OutgoingContent?
> {

override fun install(
client: HttpClient,
Expand All @@ -84,11 +86,13 @@ internal object TransformRequestBodyHook :
}

internal object TransformResponseBodyHook :
ClientHook<suspend TransformResponseBodyContext.(
response: HttpResponse,
content: ByteReadChannel,
requestedType: TypeInfo
) -> Any?> {
ClientHook<
suspend TransformResponseBodyContext.(
response: HttpResponse,
content: ByteReadChannel,
requestedType: TypeInfo
) -> Any?
> {

override fun install(
client: HttpClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ internal fun Cookie.matches(requestUrl: Url): Boolean {
if (path != "/" &&
requestPath != path &&
!requestPath.startsWith(path)
) return false
) {
return false
}

return !(secure && !requestUrl.protocol.isSecure())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ public class WebSockets internal constructor(

val negotiated = if (extensionsSupported) {
plugin.completeNegotiation(context)
} else emptyList()
} else {
emptyList()
}

clientSession.apply {
start(negotiated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public suspend fun HttpClient.webSocketSession(
val sessionCompleted = CompletableDeferred<Unit>()
sessionDeferred.complete(session)
session.outgoing.invokeOnClose {
if (it != null) sessionCompleted.completeExceptionally(it)
else sessionCompleted.complete(Unit)
if (it != null) {
sessionCompleted.completeExceptionally(it)
} else sessionCompleted.complete(Unit)
}
sessionCompleted.await()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class HttpRequestBuilder : HttpMessageBuilder {
*/
public var bodyType: TypeInfo?
get() = attributes.getOrNull(BodyTypeAttributeKey)

@InternalAPI set(value) {
if (value != null) {
attributes.put(BodyTypeAttributeKey, value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class CacheExpiresTest {
get() = error("Shouldn't be used")
override val responseTime: GMTDate
get() = error("Shouldn't be used")

@OptIn(InternalAPI::class)
override val content: ByteReadChannel
get() = error("Shouldn't be used")
Expand Down
16 changes: 8 additions & 8 deletions ktor-client/ktor-client-core/common/test/ClientPluginsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ class ClientPluginsTest {
fun testCustomHook() = testSuspend {
var hookCalled = false
val plugin = createClientPlugin("F") {
on(CustomHook) {
hookCalled = true
}
on(CustomHook) {
hookCalled = true
}
}

val client = HttpClient(MockEngine) {
Expand All @@ -166,11 +166,11 @@ class ClientPluginsTest {
@Test
fun testSendHook() = testSuspend {
val plugin = createClientPlugin("F") {
on(Send) {
val call = proceed(it)
assertEquals("temp response", call.response.bodyAsText())
proceed(it)
}
on(Send) {
val call = proceed(it)
assertEquals("temp response", call.response.bodyAsText())
proceed(it)
}
}

val client = HttpClient(MockEngine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ internal class CurlMultiApiHandler : Closeable {

private val cancelledHandles = mutableSetOf<Pair<EasyHandle, Throwable>>()

@Suppress("DEPRECATION")
private val multiHandle: MultiHandle = curl_multi_init()
?: @Suppress("DEPRECATION") throw CurlRuntimeException("Could not initialize curl multi handle")
?: throw CurlRuntimeException("Could not initialize curl multi handle")

private val easyHandlesToUnpauseLock = SynchronizedObject()
private val easyHandlesToUnpause = mutableListOf<EasyHandle>()
Expand All @@ -47,7 +48,9 @@ internal class CurlMultiApiHandler : Closeable {

fun scheduleRequest(request: CurlRequestData, deferred: CompletableDeferred<CurlSuccess>): EasyHandle {
val easyHandle = curl_easy_init()
?: throw @Suppress("DEPRECATION") CurlIllegalStateException("Could not initialize an easy handle")
?: throw
@Suppress("DEPRECATION")
CurlIllegalStateException("Could not initialize an easy handle")

val bodyStartedReceiving = CompletableDeferred<Unit>()
val responseData = CurlResponseBuilder(request)
Expand Down Expand Up @@ -207,9 +210,9 @@ internal class CurlMultiApiHandler : Closeable {
val messagePtr = curl_multi_info_read(multiHandle, messagesLeft.ptr)
val message = messagePtr?.pointed ?: continue

@Suppress("DEPRECATION")
val easyHandle = message.easy_handle
?: @Suppress("DEPRECATION")
throw CurlIllegalStateException("Got a null easy handle from the message")
?: throw CurlIllegalStateException("Got a null easy handle from the message")

try {
val result = processCompletedEasyHandle(message.msg, easyHandle, message.data.result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ internal class DarwinWebsocketSession(
FrameType.TEXT -> {
suspendCancellableCoroutine<Unit> { continuation ->
task.sendMessage(NSURLSessionWebSocketMessage(String(frame.data))) { error ->
if (error == null) continuation.resume(Unit)
else continuation.resumeWithException(DarwinHttpRequestException(error))
if (error == null) {
continuation.resume(Unit)
} else continuation.resumeWithException(DarwinHttpRequestException(error))
}
}
}

FrameType.BINARY -> {
suspendCancellableCoroutine<Unit> { continuation ->
task.sendMessage(NSURLSessionWebSocketMessage(frame.data.toNSData())) { error ->
if (error == null) continuation.resume(Unit)
else continuation.resumeWithException(DarwinHttpRequestException(error))
if (error == null) {
continuation.resume(Unit)
} else continuation.resumeWithException(DarwinHttpRequestException(error))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ private fun HttpRequestData.convertToOkHttpRequest(callContext: CoroutineContext

val bodyBytes = if (HttpMethod.permitsRequestBody(method.value)) {
body.convertToOkHttpBody(callContext)
} else null
} else {
null
}

method(method.value, bodyBytes)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,11 @@ class AuthTest : ClientLoader() {
engine {
addHandler { request ->
fun respond(): HttpResponseData {
return if (request.headers[HttpHeaders.Authorization] != "Bearer initial") respond("OK")
else respond("Error", HttpStatusCode.Unauthorized, headersOf("WWW-Authenticate", "Bearer"))
return if (request.headers[HttpHeaders.Authorization] != "Bearer initial") {
respond("OK")
} else {
respond("Error", HttpStatusCode.Unauthorized, headersOf("WWW-Authenticate", "Bearer"))
}
}

when (request.url.encodedPath) {
Expand Down Expand Up @@ -483,7 +486,6 @@ class AuthTest : ClientLoader() {
}
}


@Suppress("JoinDeclarationAndAssignment")
@Test
fun testRefreshWithSameClient() = clientTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class AuthTokenHolderTest {

var clearTokenCalled = false
val holder = AuthTokenHolder {

// suspend until clearToken is called
while (!clearTokenCalled) {
delay(10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ data class TestEntry(val a: String, val b: Int)
inline fun <reified T> indexListUnwrapper() =
object : JsonTransformingSerializer<List<T>>(ListSerializer<T>(serializer<T>())) {
override fun transformDeserialize(element: JsonElement): JsonElement {
return if (element is JsonArray) element else element.jsonObject.values.firstOrNull { it is JsonArray }
return if (element is JsonArray) {
element
} else element.jsonObject.values.firstOrNull { it is JsonArray }
?: error("Collection not found in json")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ class ContentTest : ClientLoader(5 * 60) {
}
}

@Test
// NSUrlSession buffers first 512 bytes
@Test
fun testDownloadStream() = clientTests(listOf("Darwin", "DarwinLegacy")) {
test { client ->
client.prepareGet("$TEST_SERVER/content/stream?delay=100").execute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ class MockedTests {
val responseHeaders = headersOf("Content-Type" to listOf(ContentType.Application.Json.toString()))

addHandler { request ->
if (request.url.host == "localhost") when (request.url.encodedPath) {
"/long.json" -> return@addHandler respond(longJSONString, headers = responseHeaders)
"/longer.json" -> return@addHandler respond(longerJSONString, headers = responseHeaders)
if (request.url.host == "localhost") {
when (request.url.encodedPath) {
"/long.json" -> return@addHandler respond(longJSONString, headers = responseHeaders)
"/longer.json" -> return@addHandler respond(longerJSONString, headers = responseHeaders)
}
}
error("${request.url} should not be requested")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ package io.ktor.client.engine.winhttp.internal
internal enum class WinHttpChunkedMode {
// Do not encode body
Disabled,

// Encode body
Enabled,

// Use native encoder
Automatic
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ internal suspend inline fun <T> Closeable.closeableCoroutine(
try {
block(continuation)
} catch (cause: Throwable) {
if (continuation.isActive) continuation.resumeWithException(cause)
else close()
if (continuation.isActive) {
continuation.resumeWithException(cause)
} else {
close()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ private fun formatMessage(errorCode: UInt, moduleHandle: HMODULE? = null): Strin
return try {
if (readChars > 0u) {
bufferPtr.value?.toKStringFromUtf16(readChars.convert())
} else null
} else {
null
}
} finally {
@Suppress("INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR")
LocalFree(bufferPtr.reinterpret())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ internal class WinHttpRequest(
val notifications = WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS.convert<UInt>()
val callback = if (enable) {
staticCFunction(::winHttpCallback)
} else null
} else {
null
}

val oldStatusCallback = WinHttpSetStatusCallback(hRequest, callback, notifications, 0)
if (oldStatusCallback?.rawValue?.toLong() == WINHTTP_INVALID_STATUS_CALLBACK) {
Expand Down
Loading

0 comments on commit cf1937b

Please sign in to comment.