Skip to content

Commit

Permalink
Update plugin kotlinter to v3.16.0 (#213)
Browse files Browse the repository at this point in the history
* Update plugin kotlinter to v3.16.0

* Update kotlinter suppression syntax

---------

Co-authored-by: Travis Wyatt <travis@juul.com>
  • Loading branch information
juul-mobile-bot and twyatt committed Aug 21, 2023
1 parent 03b8cd3 commit 93dd1b4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 33 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ binary-compatibility-validator = { id = "binary-compatibility-validator", versio
dokka = { id = "org.jetbrains.dokka", version = "1.8.20" }
kotlin-js = { id = "org.jetbrains.kotlin.js", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinter = { id = "org.jmailen.kotlinter", version = "3.15.0" }
kotlinter = { id = "org.jmailen.kotlinter", version = "3.16.0" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
maven-publish = { id = "com.vanniktech.maven.publish", version = "0.25.3" }
12 changes: 4 additions & 8 deletions koap/src/commonMain/kotlin/Decoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,14 @@ fun ByteArray.decodeTcpHeader(): Header.Tcp = withReader {
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Extended Length (if any, as chosen by Len) ...
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/* ktlint-disable no-multi-spaces */
@Suppress("ktlint:standard:no-multi-spaces")
val length = when (len) {
in 0..12 -> len.toLong() // No Extended Length
13 -> (readUByte() + 13).toLong() // 8-bit unsigned integer
14 -> (readUShort() + 269).toLong() // 16-bit unsigned integer
15 -> readUInt() + 65805 // 32-bit unsigned integer
else -> error("Invalid length $len")
}
/* ktlint-enable no-multi-spaces */

// |7 6 5 4 3 2 1 0|
// +-+-+-+-+-+-+-+-+
Expand Down Expand Up @@ -370,27 +369,25 @@ internal fun ByteArrayReader.readOption(preceding: Format?): Option? {
// / Option Delta / 0-2 bytes
// \ (extended) \
// +-------------------------------+
/* ktlint-disable no-multi-spaces */
@Suppress("ktlint:standard:no-multi-spaces")
val delta = when (optionDelta) {
in 0..12 -> optionDelta // No Extended Delta
13 -> readUByte() + 13 // 8-bit unsigned integer
14 -> readUShort() + 269 // 16-bit unsigned integer
else -> error("Invalid option delta $optionDelta")
}
/* ktlint-enable no-multi-spaces */

// +-------------------------------+
// / Option Length / 0-2 bytes
// \ (extended) \
// +-------------------------------+
/* ktlint-disable no-multi-spaces */
@Suppress("ktlint:standard:no-multi-spaces")
val length = when (optionLength) {
in 0..12 -> optionLength // No Extended Length
13 -> readUByte() + 13 // 8-bit unsigned integer
14 -> readUShort() + 269 // 16-bit unsigned integer
else -> error("Invalid option length $optionLength")
}
/* ktlint-enable no-multi-spaces */

return when (val number = (preceding?.number ?: 0) + delta) {
1 -> IfMatch(readByteArray(length))
Expand Down Expand Up @@ -423,7 +420,7 @@ private fun Int.toType(): Message.Udp.Type = when (this) {
else -> error("Unknown message type: $this")
}

/* ktlint-disable no-multi-spaces */
@Suppress("ktlint:standard:no-multi-spaces")
private fun Int.toCode(): Message.Code = when (this) {
1 -> GET // 0.01
2 -> POST // 0.02
Expand Down Expand Up @@ -459,7 +456,6 @@ private fun Int.toCode(): Message.Code = when (this) {
Message.Code.Raw(`class`, detail)
}
}
/* ktlint-enable no-multi-spaces */

/**
* Reads specified number of [bytes] from [ByteArrayReader] receiver to acquire a number.
Expand Down
13 changes: 3 additions & 10 deletions koap/src/commonMain/kotlin/Encoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,13 @@ internal fun BufferedSink.writeHeader(
"Token length of $tokenLength is outside allowable range of $UINT4_RANGE"
}

/* ktlint-disable no-multi-spaces */
@Suppress("ktlint:standard:no-multi-spaces")
val len = when {
contentLength < 13 -> contentLength // No Extended Length
contentLength < 269 -> 13 // Reserved, indicates 8-bit unsigned integer Extended Length
contentLength < 65805 -> 14 // Reserved, indicates 16-bit unsigned integer Extended Length
else -> 15 // Reserved, indicates 32-bit unsigned integer Extended Length
}.toInt()
/* ktlint-enable no-multi-spaces */
val tkl = tokenLength.toInt()

// |7 6 5 4 3 2 1 0|
Expand All @@ -188,7 +187,7 @@ internal fun BufferedSink.writeHeader(
writeByte((len shl 4) or tkl)

// Extended Length (if any, as chosen by Len) ...
/* ktlint-disable no-multi-spaces */
@Suppress("ktlint:standard:no-multi-spaces")
when (len) {
// |7 6 5 4 3 2 1 0|
// +-+-+-+-+-+-+-+-+
Expand All @@ -208,7 +207,6 @@ internal fun BufferedSink.writeHeader(
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
15 -> writeInt(contentLength - 65805) // 32-bit unsigned integer
}
/* ktlint-enable no-multi-spaces */

// |7 6 5 4 3 2 1 0|
// +-+-+-+-+-+-+-+-+
Expand Down Expand Up @@ -250,16 +248,15 @@ private fun BufferedSink.writeOptions(options: List<Option>) {
* +-------------------------------+
* ```
*/
@Suppress("ktlint:standard:no-multi-spaces")
internal fun BufferedSink.writeOption(option: Format, preceding: Format?) {
val delta = option.number - (preceding?.number ?: 0)
/* ktlint-disable no-multi-spaces */
val optionDelta = when {
delta in 0..12 -> delta // No Option Delta (extended)
delta < 269 -> 13 // Reserved, indicates 8-bit unsigned integer Option Delta (extended)
delta < 65805 -> 14 // Reserved, indicates 16-bit unsigned integer Option Delta (extended)
else -> error("Invalid option delta $delta")
}
/* ktlint-enable no-multi-spaces */

val optionValue = Buffer().apply {
when (option) {
Expand All @@ -284,8 +281,6 @@ internal fun BufferedSink.writeOption(option: Format, preceding: Format?) {
}
}

/* ktlint-disable no-multi-spaces */

val length = optionValue.size.toInt()
val optionLength = when {
length in 0..12 -> length // No Extended Length
Expand Down Expand Up @@ -324,8 +319,6 @@ internal fun BufferedSink.writeOption(option: Format, preceding: Format?) {
// \ \
// +-------------------------------+
writeAll(optionValue)

/* ktlint-enable no-multi-spaces */
}

/**
Expand Down
20 changes: 6 additions & 14 deletions koap/src/commonMain/kotlin/Message.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// ktlint-disable indent
// todo: Disable above rule only on effected line when https://github.com/pinterest/ktlint/issues/631 is fixed.

package com.juul.koap

import com.juul.koap.Message.Option.Observe.Registration.Deregister
Expand Down Expand Up @@ -189,7 +186,7 @@ sealed class Message {
override fun toString(): String = "ContentFormat(${format.contentType})"

/** RFC 7252 12.3. CoAP Content-Formats Registry */
/* ktlint-disable no-multi-spaces */
@Suppress("ktlint:standard:no-multi-spaces")
companion object {
val PlainText = ContentFormat(0) // text/plain; charset=utf-8
val LinkFormat = ContentFormat(40) // application/link-format
Expand All @@ -201,7 +198,6 @@ sealed class Message {
/** RFC 7049 7.4. CoAP Content-Format */
val CBOR = ContentFormat(60) // application/cbor
}
/* ktlint-enable no-multi-spaces */
}

/** RFC 7252 5.10.4. Accept */
Expand Down Expand Up @@ -344,16 +340,15 @@ sealed class Message {
abstract val detail: Int

/** RFC 7252: 12.1.1. Method Codes */
@Suppress("ktlint:standard:no-multi-spaces")
sealed class Method(
override val `class`: Int,
override val detail: Int,
) : Code() {
/* ktlint-disable no-multi-spaces */
object GET : Method(`class` = 0, detail = 1) // 0.01
object POST : Method(`class` = 0, detail = 2) // 0.02
object PUT : Method(`class` = 0, detail = 3) // 0.03
object DELETE : Method(`class` = 0, detail = 4) // 0.04
/* ktlint-enable no-multi-spaces */

override fun toString(): String = when (this) {
GET -> "GET"
Expand All @@ -364,11 +359,11 @@ sealed class Message {
}

/** RFC 7252: 12.1.2. Response Codes */
@Suppress("ktlint:standard:no-multi-spaces")
sealed class Response(
override val `class`: Int,
override val detail: Int,
) : Code() {
/* ktlint-disable no-multi-spaces */
object Created : Response(`class` = 2, detail = 1) // 2.01
object Deleted : Response(`class` = 2, detail = 2) // 2.02
object Valid : Response(`class` = 2, detail = 3) // 2.03
Expand All @@ -390,7 +385,6 @@ sealed class Message {
object ServiceUnavailable : Response(`class` = 5, detail = 3) // 5.03
object GatewayTimeout : Response(`class` = 5, detail = 4) // 5.04
object ProxyingNotSupported : Response(`class` = 5, detail = 5) // 5.05
/* ktlint-enable no-multi-spaces */

override fun toString(): String = when (this) {
Created -> "Created"
Expand Down Expand Up @@ -452,19 +446,18 @@ sealed class Message {
}
}

// ktlint-disable indent
@Suppress("ktlint:standard:indent")
override fun equals(other: Any?): Boolean =
this === other ||
(
other is Udp && // ktlint-disable indent
other is Udp &&
type == other.type &&
code == other.code &&
id == other.id &&
token == other.token &&
options == other.options &&
payload.contentEquals(other.payload)
)
// ktlint-enable indent

override fun hashCode(): Int {
var result = type.hashCode()
Expand Down Expand Up @@ -493,7 +486,7 @@ sealed class Message {
override val payload: ByteArray,
) : Message() {

// ktlint-disable indent
@Suppress("ktlint:standard:indent")
override fun equals(other: Any?): Boolean =
this === other ||
(
Expand All @@ -503,7 +496,6 @@ sealed class Message {
options == other.options &&
payload.contentEquals(other.payload)
)
// ktlint-enable indent

override fun hashCode(): Int {
var result = code.hashCode()
Expand Down

0 comments on commit 93dd1b4

Please sign in to comment.