Skip to content

Commit

Permalink
Fix if-else-wrapping and if-else-bracing
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd committed Nov 21, 2024
1 parent 2812b75 commit b4879c8
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 38 deletions.
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 @@ -107,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
@@ -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.
*/

package io.ktor.client.plugins
Expand Down Expand Up @@ -264,7 +264,9 @@ public val HttpRequestRetry: ClientPlugin<HttpRequestRetryConfig> = createClient
val subRequestJob = subRequest.executionContext as CompletableJob
if (cause == null) {
subRequestJob.complete()
} else subRequestJob.completeExceptionally(cause)
} else {
subRequestJob.completeExceptionally(cause)
}
}
return subRequest
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public suspend fun HttpClient.webSocketSession(
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
@@ -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.darwin.internal
Expand Down Expand Up @@ -100,17 +100,21 @@ internal class DarwinWebsocketSession(
) { error ->
if (error == null) {
continuation.resume(Unit)
} else continuation.resumeWithException(DarwinHttpRequestException(error))
} else {
continuation.resumeWithException(DarwinHttpRequestException(error))
}
}
}
}

FrameType.BINARY -> {
suspendCancellableCoroutine<Unit> { continuation ->
suspendCancellableCoroutine { continuation ->
task.sendMessage(NSURLSessionWebSocketMessage(frame.data.toNSData())) { error ->
if (error == null) {
continuation.resume(Unit)
} else continuation.resumeWithException(DarwinHttpRequestException(error))
} else {
continuation.resumeWithException(DarwinHttpRequestException(error))
}
}
}
}
Expand Down
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.
*/

package io.ktor.tests.server.cio
Expand Down Expand Up @@ -38,7 +38,10 @@ class IntegrationTest {
s.invokeOnCompletion { t ->
if (t != null) {
server.completeExceptionally(t)
} else server.complete(@OptIn(ExperimentalCoroutinesApi::class) s.getCompleted())
} else {
@OptIn(ExperimentalCoroutinesApi::class)
server.complete(s.getCompleted())
}
}

j.invokeOnCompletion {
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.server.routing
Expand Down Expand Up @@ -187,7 +187,9 @@ public class RoutingResolveContext(

val partQuality = if (part.quality == RouteSelectorEvaluation.qualityTransparent) {
RouteSelectorEvaluation.qualityConstant
} else part.quality
} else {
part.quality
}

quality = minOf(quality, partQuality)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 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.server.netty
Expand Down Expand Up @@ -33,7 +33,9 @@ public suspend fun <T> Future<T>.suspendAwait(): T {
private val wrappingErrorHandler = { t: Throwable, c: Continuation<*> ->
if (t is IOException) {
c.resumeWithException(ChannelWriteException("Write operation future failed", t))
} else c.resumeWithException(t)
} else {
c.resumeWithException(t)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 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.server.netty
Expand All @@ -20,6 +20,8 @@ internal class NettyDirectEncoder : MessageToByteEncoder<HttpContent>() {
Unpooled.EMPTY_BUFFER
} else if (preferDirect) {
ctx.alloc().ioBuffer(size)
} else ctx.alloc().heapBuffer(size)
} else {
ctx.alloc().heapBuffer(size)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 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.server.auth
Expand Down Expand Up @@ -31,7 +31,9 @@ internal class CombinedPrincipal {
.firstOrNull { (name, principal) ->
if (provider != null) {
name == provider && klass.isInstance(principal)
} else klass.isInstance(principal)
} else {
klass.isInstance(principal)
}
}?.second as? T
}

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.server.auth
Expand Down Expand Up @@ -38,7 +38,9 @@ public class SessionAuthenticationProvider<T : Any> private constructor(
val cause =
if (session == null) {
AuthenticationFailedCause.NoCredentials
} else AuthenticationFailedCause.InvalidCredentials
} else {
AuthenticationFailedCause.InvalidCredentials
}

@Suppress("NAME_SHADOWING")
context.challenge(SessionAuthChallengeKey, cause) { challenge, call ->
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.server.plugins.calllogging
Expand Down Expand Up @@ -135,5 +135,7 @@ public class CallLoggingConfig {
private fun colored(value: Any, color: Ansi.Color): String =
if (isColorsEnabled) {
Ansi.ansi().fg(color).a(value).reset().toString()
} else value.toString() // ignore color
} else {
value.toString() // ignore color
}
}
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.server.plugins.requestvalidation
Expand All @@ -23,12 +23,16 @@ class RequestValidationTest {
validate<CharSequence> {
if (!it.startsWith("+")) {
ValidationResult.Invalid(listOf("$it should start with \"+\""))
} else ValidationResult.Valid
} else {
ValidationResult.Valid
}
}
validate<String> {
if (!it.endsWith("!")) {
ValidationResult.Invalid(listOf("$it should end with \"!\""))
} else ValidationResult.Valid
} else {
ValidationResult.Valid
}
}
}
install(StatusPages) {
Expand Down Expand Up @@ -96,7 +100,9 @@ class RequestValidationTest {
val intValue = it.decodeToString(0, 0 + it.size).toInt()
if (intValue < 0) {
ValidationResult.Invalid("Value is negative")
} else ValidationResult.Valid
} else {
ValidationResult.Valid
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 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.server.servlet.jakarta
Expand Down Expand Up @@ -64,7 +64,9 @@ public class AsyncServletApplicationRequest(
if (!upgraded) {
val contentLength = servletRequest.contentLength
servletReader(servletRequest.inputStream, contentLength).channel
} else ByteReadChannel.Empty
} else {
ByteReadChannel.Empty
}
}

override val engineReceiveChannel: ByteReadChannel get() = inputStreamChannel
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.server.servlet

Expand Down Expand Up @@ -64,7 +64,9 @@ public class AsyncServletApplicationRequest(
if (!upgraded) {
val contentLength = servletRequest.contentLength
servletReader(servletRequest.inputStream, contentLength).channel
} else ByteReadChannel.Empty
} else {
ByteReadChannel.Empty
}
}

override val engineReceiveChannel: ByteReadChannel get() = inputStreamChannel
Expand Down
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.
*/

package io.ktor.server.testing.client
Expand Down Expand Up @@ -33,7 +33,9 @@ internal class TestEngineWebsocketSession(
outgoing.invokeOnClose {
if (it != null) {
socketJob.completeExceptionally(it)
} else socketJob.complete()
} else {
socketJob.complete()
}
}
socketJob.join()
}
Expand Down

0 comments on commit b4879c8

Please sign in to comment.