From 7ea4ecabfe5b20f85c77b2fb684499807e524fd6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 21 Jun 2024 23:35:34 -0400 Subject: [PATCH] Update dependency com.pinterest.ktlint:ktlint-cli to v1.3.0 (#1853) * Update dependency com.pinterest.ktlint:ktlint-cli to v1.3.0 * Disable expression rule * Reformat * Whatever --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Jake Wharton --- build.gradle.kts | 6 +++++- gradle/libs.versions.toml | 2 +- .../moshi/kotlin/codegen/api/AdapterGenerator.kt | 10 +++++++--- .../squareup/moshi/kotlin/codegen/ksp/shadedUtil.kt | 5 +++-- moshi-kotlin-tests/build.gradle.kts | 3 ++- moshi-kotlin-tests/codegen-only/build.gradle.kts | 3 ++- .../kotlin/codegen/ComplexGenericsInheritanceTest.kt | 7 +++++-- .../com/squareup/moshi/kotlin/codegen/MoshiKspTest.kt | 4 +++- .../com/squareup/moshi/KotlinJsonAdapterFactory.kt | 3 +-- moshi/build.gradle.kts | 3 ++- .../src/main/java/com/squareup/moshi/JsonUtf8Writer.kt | 9 ++++++--- .../main/java/com/squareup/moshi/JsonValueReader.kt | 3 ++- moshi/src/main/java/com/squareup/moshi/JsonWriter.kt | 4 +++- .../main/java/com/squareup/moshi/LinkedHashTreeMap.kt | 3 ++- moshi/src/main/java/com/squareup/moshi/Types.kt | 3 ++- 15 files changed, 46 insertions(+), 22 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6cfb5da68..fa423ee7e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -57,7 +57,11 @@ spotless { } kotlin { ktlint(libs.ktlint.get().version).editorConfigOverride( - mapOf("ktlint_standard_filename" to "disabled"), + mapOf( + "ktlint_standard_filename" to "disabled", + // Making something an expression body should be a choice around readability. + "ktlint_standard_function-expression-body" to "disabled", + ), ) target("**/*.kt") trimTrailingWhitespace() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a033b88e6..47bb190dd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -37,4 +37,4 @@ kotlinCompileTesting = { module = "dev.zacsweers.kctfork:core", version.ref = "k kotlinCompileTesting-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref ="kotlinCompileTesting" } truth = "com.google.truth:truth:1.4.2" googleJavaFormat = "com.google.googlejavaformat:google-java-format:1.22.0" -ktlint = "com.pinterest.ktlint:ktlint-cli:1.2.1" +ktlint = "com.pinterest.ktlint:ktlint-cli:1.3.0" diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt index 2fbadba52..3459d68a7 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt @@ -774,20 +774,24 @@ private sealed class FromJsonComponent { data class ParameterOnly( override val parameter: TargetParameter, - ) : FromJsonComponent(), ParameterComponent { + ) : FromJsonComponent(), + ParameterComponent { override val type: TypeName = parameter.type } data class PropertyOnly( override val property: PropertyGenerator, - ) : FromJsonComponent(), PropertyComponent { + ) : FromJsonComponent(), + PropertyComponent { override val type: TypeName = property.target.type } data class ParameterProperty( override val parameter: TargetParameter, override val property: PropertyGenerator, - ) : FromJsonComponent(), ParameterComponent, PropertyComponent { + ) : FromJsonComponent(), + ParameterComponent, + PropertyComponent { override val type: TypeName = parameter.type } } diff --git a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/shadedUtil.kt b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/shadedUtil.kt index de58602ac..de75902fc 100644 --- a/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/shadedUtil.kt +++ b/moshi-kotlin-codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/shadedUtil.kt @@ -43,8 +43,9 @@ internal fun Resolver.getClassDeclarationByName(name: String): KSClassDeclaratio internal fun KSAnnotated.getAnnotationsByType(annotationKClass: KClass): Sequence { return this.annotations.filter { - it.shortName.getShortName() == annotationKClass.simpleName && it.annotationType.resolve().declaration - .qualifiedName?.asString() == annotationKClass.qualifiedName + it.shortName.getShortName() == annotationKClass.simpleName && + it.annotationType.resolve().declaration + .qualifiedName?.asString() == annotationKClass.qualifiedName }.map { it.toAnnotation(annotationKClass.java) } } diff --git a/moshi-kotlin-tests/build.gradle.kts b/moshi-kotlin-tests/build.gradle.kts index 29aae33ab..bdf6b1ca1 100644 --- a/moshi-kotlin-tests/build.gradle.kts +++ b/moshi-kotlin-tests/build.gradle.kts @@ -13,7 +13,8 @@ enum class TestMode { } val testMode = - findProperty("kotlinTestMode")?.toString() + findProperty("kotlinTestMode") + ?.toString() ?.let(TestMode::valueOf) ?: REFLECT diff --git a/moshi-kotlin-tests/codegen-only/build.gradle.kts b/moshi-kotlin-tests/codegen-only/build.gradle.kts index f08385e7f..31eb6c9b3 100644 --- a/moshi-kotlin-tests/codegen-only/build.gradle.kts +++ b/moshi-kotlin-tests/codegen-only/build.gradle.kts @@ -13,7 +13,8 @@ enum class TestMode { } val testMode = - findProperty("kotlinTestMode")?.toString() + findProperty("kotlinTestMode") + ?.toString() ?.let(TestMode::valueOf) ?: KSP diff --git a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt index 022ff5703..e665b3a6b 100644 --- a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt +++ b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/ComplexGenericsInheritanceTest.kt @@ -134,7 +134,9 @@ abstract class Layer1 { var layer1: A? = null } -abstract class Layer2 : Layer1(), LayerInterface { +abstract class Layer2 : + Layer1(), + LayerInterface { var layer2: B? = null } @@ -147,4 +149,5 @@ abstract class Layer3 : Layer2() { data class Layer4( val layer4E: E, val layer4F: F? = null, -) : Layer3, String>(), LayerInterface +) : Layer3, String>(), + LayerInterface diff --git a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MoshiKspTest.kt b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MoshiKspTest.kt index 4ef7b5198..f23fc4eb8 100644 --- a/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MoshiKspTest.kt +++ b/moshi-kotlin-tests/codegen-only/src/test/kotlin/com/squareup/moshi/kotlin/codegen/MoshiKspTest.kt @@ -44,5 +44,7 @@ class MoshiKspTest { // NOTE the Any() superclass is important to test that we're detecting the farthest parent class // correct.y @JsonClass(generateAdapter = true) - data class SimpleImpl(override val a: String, val b: String) : Any(), SimpleInterface + data class SimpleImpl(override val a: String, val b: String) : + Any(), + SimpleInterface } diff --git a/moshi-kotlin/src/main/java/com/squareup/moshi/KotlinJsonAdapterFactory.kt b/moshi-kotlin/src/main/java/com/squareup/moshi/KotlinJsonAdapterFactory.kt index 2b6440737..fe5e29cd4 100644 --- a/moshi-kotlin/src/main/java/com/squareup/moshi/KotlinJsonAdapterFactory.kt +++ b/moshi-kotlin/src/main/java/com/squareup/moshi/KotlinJsonAdapterFactory.kt @@ -21,5 +21,4 @@ import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory message = "this moved to avoid a package name conflict in the Java Platform Module System.", replaceWith = ReplaceWith("com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory"), ) -public class KotlinJsonAdapterFactory : - JsonAdapter.Factory by KotlinJsonAdapterFactory() +public class KotlinJsonAdapterFactory : JsonAdapter.Factory by KotlinJsonAdapterFactory() diff --git a/moshi/build.gradle.kts b/moshi/build.gradle.kts index 011e3b559..98e769fba 100644 --- a/moshi/build.gradle.kts +++ b/moshi/build.gradle.kts @@ -63,7 +63,8 @@ tasks.withType().configureEach { jvmArgs("--add-opens=java.base/java.io=ALL-UNNAMED") } -tasks.withType() +tasks + .withType() .configureEach { compilerOptions { freeCompilerArgs.addAll( diff --git a/moshi/src/main/java/com/squareup/moshi/JsonUtf8Writer.kt b/moshi/src/main/java/com/squareup/moshi/JsonUtf8Writer.kt index 4099b103d..f844458ed 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonUtf8Writer.kt +++ b/moshi/src/main/java/com/squareup/moshi/JsonUtf8Writer.kt @@ -115,8 +115,10 @@ internal class JsonUtf8Writer( check(stackSize != 0) { "JsonWriter is closed." } val context = peekScope() val isWritingObject = !( - context != JsonScope.EMPTY_OBJECT && context != JsonScope.NONEMPTY_OBJECT || - deferredName != null || promoteValueToName + context != JsonScope.EMPTY_OBJECT && + context != JsonScope.NONEMPTY_OBJECT || + deferredName != null || + promoteValueToName ) check(isWritingObject) { "Nesting problem." } deferredName = name @@ -281,7 +283,8 @@ internal class JsonUtf8Writer( if (context == JsonScope.NONEMPTY_OBJECT) { // first in object sink.writeByte(','.code) } else { - check(context == JsonScope.EMPTY_OBJECT) { // not in an object! + check(context == JsonScope.EMPTY_OBJECT) { + // not in an object! "Nesting problem." } } diff --git a/moshi/src/main/java/com/squareup/moshi/JsonValueReader.kt b/moshi/src/main/java/com/squareup/moshi/JsonValueReader.kt index ff9e9e0c3..cba7736b3 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonValueReader.kt +++ b/moshi/src/main/java/com/squareup/moshi/JsonValueReader.kt @@ -398,7 +398,8 @@ internal class JsonValueReader : JsonReader { val endToken: Token, val array: Array, var next: Int, - ) : Iterator, Cloneable { + ) : Iterator, + Cloneable { override fun hasNext() = next < array.size override fun next() = array[next++] diff --git a/moshi/src/main/java/com/squareup/moshi/JsonWriter.kt b/moshi/src/main/java/com/squareup/moshi/JsonWriter.kt index 4d3bd51d5..e4fad9475 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonWriter.kt +++ b/moshi/src/main/java/com/squareup/moshi/JsonWriter.kt @@ -128,7 +128,9 @@ import kotlin.Throws * Each `JsonWriter` may be used to write a single JSON stream. Instances of this class are * not thread safe. Calls that would result in a malformed JSON string will fail with an [IllegalStateException]. */ -public sealed class JsonWriter : Closeable, Flushable { +public sealed class JsonWriter : + Closeable, + Flushable { /** * The nesting stack. Using a manual array rather than an ArrayList saves 20%. This stack will * grow itself up to 256 levels of nesting including the top-level document. Deeper nesting is diff --git a/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.kt b/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.kt index 9a6831649..cd9e1084e 100644 --- a/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.kt +++ b/moshi/src/main/java/com/squareup/moshi/LinkedHashTreeMap.kt @@ -19,7 +19,8 @@ private val NATURAL_ORDER = Comparator { o1, o2 -> (o1 as Comparable). */ internal class LinkedHashTreeMap( comparator: Comparator? = null, -) : AbstractMutableMap(), Serializable { +) : AbstractMutableMap(), + Serializable { @Suppress("UNCHECKED_CAST") private val comparator: Comparator = (comparator ?: NATURAL_ORDER) as Comparator private var table: Array?> = arrayOfNulls(16) // TODO: sizing/resizing policies diff --git a/moshi/src/main/java/com/squareup/moshi/Types.kt b/moshi/src/main/java/com/squareup/moshi/Types.kt index 43eab2d33..2e1087d28 100644 --- a/moshi/src/main/java/com/squareup/moshi/Types.kt +++ b/moshi/src/main/java/com/squareup/moshi/Types.kt @@ -238,7 +238,8 @@ public object Types { val bTypeArguments = if (b is ParameterizedTypeImpl) b.typeArguments else b.actualTypeArguments return ( equals(a.ownerType, b.ownerType) && - (a.rawType == b.rawType) && aTypeArguments.contentEquals(bTypeArguments) + (a.rawType == b.rawType) && + aTypeArguments.contentEquals(bTypeArguments) ) }