Update formatters to latest

Ensure renovate can bump them by specifying full coordinates in toml.
This commit is contained in:
Jake Wharton
2024-01-29 12:02:30 -05:00
committed by Zac Sweers
parent 84ca5cfd7e
commit 2cc9ebb88e
15 changed files with 155 additions and 90 deletions

View File

@@ -9,9 +9,11 @@ import java.net.URI
buildscript {
dependencies {
val kotlinVersion = System.getenv("MOSHI_KOTLIN_VERSION")
val kotlinVersion =
System.getenv("MOSHI_KOTLIN_VERSION")
?: libs.versions.kotlin.get()
val kspVersion = System.getenv("MOSHI_KSP_VERSION")
val kspVersion =
System.getenv("MOSHI_KSP_VERSION")
?: libs.versions.ksp.get()
classpath(kotlin("gradle-plugin", version = kotlinVersion))
classpath("com.google.devtools.ksp:symbol-processing-gradle-plugin:$kspVersion")
@@ -44,7 +46,7 @@ spotless {
endWithNewline()
}
val configureCommonJavaFormat: JavaExtension.() -> Unit = {
googleJavaFormat(libs.versions.gjf.get())
googleJavaFormat(libs.googleJavaFormat.get().version)
}
java {
configureCommonJavaFormat()
@@ -52,7 +54,7 @@ spotless {
targetExclude("**/build/**")
}
kotlin {
ktlint(libs.versions.ktlint.get()).editorConfigOverride(
ktlint(libs.ktlint.get().version).editorConfigOverride(
mapOf("ktlint_standard_filename" to "disabled"),
)
target("**/*.kt")
@@ -61,7 +63,7 @@ spotless {
targetExclude("**/Dependencies.kt", "**/build/**")
}
kotlinGradle {
ktlint(libs.versions.ktlint.get())
ktlint(libs.ktlint.get().version)
target("**/*.gradle.kts")
trimTrailingWhitespace()
endWithNewline()

View File

@@ -1,12 +1,10 @@
[versions]
autoService = "1.1.1"
gjf = "1.15.0"
jvmTarget = "1.8"
kotlin = "1.9.21"
kotlinCompileTesting = "0.4.0"
kotlinpoet = "1.14.2"
ksp = "1.9.22-1.0.17"
ktlint = "0.48.2"
[plugins]
dokka = { id = "org.jetbrains.dokka", version = "1.9.10" }
@@ -33,10 +31,10 @@ kotlinxMetadata = "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.7.0"
ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
okio = "com.squareup.okio:okio:3.7.0"
# Test libs
assertj = "org.assertj:assertj-core:3.25.2"
junit = "junit:junit:4.13.2"
kotlinCompileTesting = { module = "dev.zacsweers.kctfork:core", version.ref = "kotlinCompileTesting" }
kotlinCompileTesting-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref ="kotlinCompileTesting" }
truth = "com.google.truth:truth:1.3.0"
googleJavaFormat = "com.google.googlejavaformat:google-java-format:1.19.2"
ktlint = "com.pinterest.ktlint:ktlint-cli:1.1.1"

View File

@@ -18,7 +18,8 @@ dependencies {
latest(project(":moshi-adapters"))
}
val japicmp = tasks.register<JapicmpTask>("japicmp") {
val japicmp =
tasks.register<JapicmpTask>("japicmp") {
dependsOn("jar")
oldClasspath.from(baseline)
newClasspath.from(latest)
@@ -27,7 +28,7 @@ val japicmp = tasks.register<JapicmpTask>("japicmp") {
txtOutputFile.set(layout.buildDirectory.file("reports/japi.txt"))
ignoreMissingClasses.set(true)
includeSynthetic.set(true)
}
}
tasks.named("check").configure {
dependsOn(japicmp)

View File

@@ -81,19 +81,40 @@ internal fun String.parseIsoDate(): Date {
var offset = 0
// extract year
val year = parseInt(this, offset, 4.let { offset += it; offset })
val year = parseInt(
this,
offset,
4.let {
offset += it
offset
},
)
if (checkOffset(this, offset, '-')) {
offset += 1
}
// extract month
val month = parseInt(this, offset, 2.let { offset += it; offset })
val month = parseInt(
this,
offset,
2.let {
offset += it
offset
},
)
if (checkOffset(this, offset, '-')) {
offset += 1
}
// extract day
val day = parseInt(this, offset, 2.let { offset += it; offset })
val day = parseInt(
this,
offset,
2.let {
offset += it
offset
},
)
// default time value
var hour = 0
var minutes = 0
@@ -108,11 +129,28 @@ internal fun String.parseIsoDate(): Date {
}
if (hasT) {
// extract hours, minutes, seconds and milliseconds
hour = parseInt(this, 1.let { offset += it; offset }, 2.let { offset += it; offset })
hour = parseInt(
this,
1.let {
offset += it
offset
},
2.let {
offset += it
offset
},
)
if (checkOffset(this, offset, ':')) {
offset += 1
}
minutes = parseInt(this, offset, 2.let { offset += it; offset })
minutes = parseInt(
this,
offset,
2.let {
offset += it
offset
},
)
if (checkOffset(this, offset, ':')) {
offset += 1
}
@@ -120,7 +158,14 @@ internal fun String.parseIsoDate(): Date {
if (this.length > offset) {
val c = this[offset]
if (c != 'Z' && c != '+' && c != '-') {
seconds = parseInt(this, offset, 2.let { offset += it; offset })
seconds = parseInt(
this,
offset,
2.let {
offset += it
offset
},
)
if (seconds in 60..62) seconds = 59 // truncate up to 3 leap seconds
// milliseconds can be optional in the format
if (checkOffset(this, offset, '.')) {

View File

@@ -83,7 +83,8 @@ dependencies {
testImplementation(libs.kotlinCompileTesting)
}
val shadowJar = tasks.shadowJar.apply {
val shadowJar =
tasks.shadowJar.apply {
configure {
archiveClassifier.set("")
configurations = listOf(shade)
@@ -95,7 +96,7 @@ val shadowJar = tasks.shadowJar.apply {
relocate("kotlinx.metadata", "com.squareup.moshi.kotlinx.metadata")
transformers.add(ServiceFileTransformer())
}
}
}
artifacts {
runtimeOnly(shadowJar)

View File

@@ -10,10 +10,13 @@ plugins {
}
enum class TestMode {
REFLECT, KAPT, KSP
REFLECT,
KAPT,
KSP,
}
val testMode = findProperty("kotlinTestMode")?.toString()
val testMode =
findProperty("kotlinTestMode")?.toString()
?.let(TestMode::valueOf)
?: REFLECT

View File

@@ -10,10 +10,13 @@ plugins {
}
enum class TestMode {
REFLECT, KAPT, KSP
REFLECT,
KAPT,
KSP,
}
val testMode = findProperty("kotlinTestMode")?.toString()
val testMode =
findProperty("kotlinTestMode")?.toString()
?.let(TestMode::valueOf)
?: KSP

View File

@@ -1189,6 +1189,7 @@ class GeneratedAdaptersTest {
}
@JsonClass(generateAdapter = true)
@Suppress("ktlint:standard:property-naming")
class MutableUppercasePropertyName {
var AAA: Int = -1
var BBB: Int = -1

View File

@@ -21,6 +21,7 @@ import com.squareup.moshi.JsonWriter
import com.squareup.moshi.kotlin.codegen.GeneratedAdaptersTest.CustomGeneratedClass
// This also tests custom generated types with no moshi constructor
@Suppress("ktlint:standard:class-naming")
class GeneratedAdaptersTest_CustomGeneratedClassJsonAdapter : JsonAdapter<CustomGeneratedClass>() {
override fun fromJson(reader: JsonReader): CustomGeneratedClass? {
TODO()

View File

@@ -569,7 +569,8 @@ class KotlinJsonAdapterTest {
data class UsingEnum(val e: KotlinEnum)
enum class KotlinEnum {
A, B
A,
B,
}
@Test fun interfacesNotSupported() {

View File

@@ -190,8 +190,7 @@ internal class KotlinJsonAdapter<T>(
}
public class KotlinJsonAdapterFactory : JsonAdapter.Factory {
override fun create(type: Type, annotations: Set<Annotation>, moshi: Moshi):
JsonAdapter<*>? {
override fun create(type: Type, annotations: Set<Annotation>, moshi: Moshi): JsonAdapter<*>? {
if (annotations.isNotEmpty()) return null
val rawType = type.rawType

View File

@@ -21,9 +21,10 @@ val java16: SourceSet by sourceSets.creating {
// We use JDK 17 for latest but target 16 for maximum compatibility
val service = project.extensions.getByType<JavaToolchainService>()
val customLauncher = service.launcherFor {
val customLauncher =
service.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
tasks.named<JavaCompile>("compileJava16Java") {
options.release.set(16)

View File

@@ -18,7 +18,8 @@ dependencies {
latest(project(":moshi"))
}
val japicmp = tasks.register<JapicmpTask>("japicmp") {
val japicmp =
tasks.register<JapicmpTask>("japicmp") {
dependsOn("jar")
oldClasspath.from(baseline)
newClasspath.from(latest)
@@ -28,18 +29,21 @@ val japicmp = tasks.register<JapicmpTask>("japicmp") {
ignoreMissingClasses.set(true)
includeSynthetic.set(true)
classExcludes.addAll(
"com.squareup.moshi.AdapterMethodsFactory", // Internal.
"com.squareup.moshi.ClassJsonAdapter", // Internal.
"com.squareup.moshi.RecordJsonAdapter\$ComponentBinding", // Package-private
"com.squareup.moshi.StandardJsonAdapters", // Package-private
"com.squareup.moshi.internal.NonNullJsonAdapter", // Internal.
"com.squareup.moshi.internal.NullSafeJsonAdapter", // Internal.
"com.squareup.moshi.internal.Util\$GenericArrayTypeImpl", // Internal.
"com.squareup.moshi.internal.Util\$ParameterizedTypeImpl", // Internal.
"com.squareup.moshi.internal.Util\$WildcardTypeImpl", // Internal.
// Internal.
"com.squareup.moshi.AdapterMethodsFactory",
"com.squareup.moshi.ClassJsonAdapter",
"com.squareup.moshi.internal.NonNullJsonAdapter",
"com.squareup.moshi.internal.NullSafeJsonAdapter",
"com.squareup.moshi.internal.Util\$GenericArrayTypeImpl",
"com.squareup.moshi.internal.Util\$ParameterizedTypeImpl",
"com.squareup.moshi.internal.Util\$WildcardTypeImpl",
// Package-private
"com.squareup.moshi.RecordJsonAdapter\$ComponentBinding",
"com.squareup.moshi.StandardJsonAdapters",
)
methodExcludes.addAll(
"com.squareup.moshi.JsonAdapter#indent(java.lang.String)", // Was unintentionally open before
// Was unintentionally open before
"com.squareup.moshi.JsonAdapter#indent(java.lang.String)",
"com.squareup.moshi.internal.Util#hasNullable(java.lang.annotation.Annotation[])",
"com.squareup.moshi.internal.Util#jsonAnnotations(java.lang.annotation.Annotation[])",
"com.squareup.moshi.internal.Util#jsonAnnotations(java.lang.reflect.AnnotatedElement)",
@@ -49,11 +53,14 @@ val japicmp = tasks.register<JapicmpTask>("japicmp") {
"com.squareup.moshi.internal.Util#typeAnnotatedWithAnnotations(java.lang.reflect.Type, java.util.Set)",
)
fieldExcludes.addAll(
"com.squareup.moshi.CollectionJsonAdapter#FACTORY", // False-positive, class is not public anyway
"com.squareup.moshi.MapJsonAdapter#FACTORY", // Class is not public
"com.squareup.moshi.ArrayJsonAdapter#FACTORY", // Class is not public
// False-positive, class is not public anyway
"com.squareup.moshi.CollectionJsonAdapter#FACTORY",
// Class is not public
"com.squareup.moshi.MapJsonAdapter#FACTORY",
// Class is not public
"com.squareup.moshi.ArrayJsonAdapter#FACTORY",
)
}
}
tasks.named("check").configure {
dependsOn(japicmp)

View File

@@ -448,7 +448,8 @@ internal class JsonUtf8Reader : JsonReader {
checkLenient() // fall-through
false
}
'{', '}', '[', ']', ':', ',', ' ', '\t', '\u000C'/*\f*/, '\r', '\n' -> false
// 0x000C = \f
'{', '}', '[', ']', ':', ',', ' ', '\t', '\u000C', '\r', '\n' -> false
else -> true
}
}

View File

@@ -151,6 +151,7 @@ public sealed class JsonWriter : Closeable, Flushable {
* pretty printing.
*/
@JvmField
@Suppress("ktlint:standard:property-naming") // Exposed to sealed subtypes.
protected var _indent: String? = null
public open var indent: String
/**