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

View File

@@ -1,12 +1,10 @@
[versions] [versions]
autoService = "1.1.1" autoService = "1.1.1"
gjf = "1.15.0"
jvmTarget = "1.8" jvmTarget = "1.8"
kotlin = "1.9.21" kotlin = "1.9.21"
kotlinCompileTesting = "0.4.0" kotlinCompileTesting = "0.4.0"
kotlinpoet = "1.14.2" kotlinpoet = "1.14.2"
ksp = "1.9.22-1.0.17" ksp = "1.9.22-1.0.17"
ktlint = "0.48.2"
[plugins] [plugins]
dokka = { id = "org.jetbrains.dokka", version = "1.9.10" } 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 = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
okio = "com.squareup.okio:okio:3.7.0" okio = "com.squareup.okio:okio:3.7.0"
# Test libs
assertj = "org.assertj:assertj-core:3.25.2" assertj = "org.assertj:assertj-core:3.25.2"
junit = "junit:junit:4.13.2" junit = "junit:junit:4.13.2"
kotlinCompileTesting = { module = "dev.zacsweers.kctfork:core", version.ref = "kotlinCompileTesting" } kotlinCompileTesting = { module = "dev.zacsweers.kctfork:core", version.ref = "kotlinCompileTesting" }
kotlinCompileTesting-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref ="kotlinCompileTesting" } kotlinCompileTesting-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref ="kotlinCompileTesting" }
truth = "com.google.truth:truth:1.3.0" 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,16 +18,17 @@ dependencies {
latest(project(":moshi-adapters")) latest(project(":moshi-adapters"))
} }
val japicmp = tasks.register<JapicmpTask>("japicmp") { val japicmp =
dependsOn("jar") tasks.register<JapicmpTask>("japicmp") {
oldClasspath.from(baseline) dependsOn("jar")
newClasspath.from(latest) oldClasspath.from(baseline)
onlyBinaryIncompatibleModified.set(true) newClasspath.from(latest)
failOnModification.set(true) onlyBinaryIncompatibleModified.set(true)
txtOutputFile.set(layout.buildDirectory.file("reports/japi.txt")) failOnModification.set(true)
ignoreMissingClasses.set(true) txtOutputFile.set(layout.buildDirectory.file("reports/japi.txt"))
includeSynthetic.set(true) ignoreMissingClasses.set(true)
} includeSynthetic.set(true)
}
tasks.named("check").configure { tasks.named("check").configure {
dependsOn(japicmp) dependsOn(japicmp)

View File

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

View File

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

View File

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

View File

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

View File

@@ -1189,6 +1189,7 @@ class GeneratedAdaptersTest {
} }
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
@Suppress("ktlint:standard:property-naming")
class MutableUppercasePropertyName { class MutableUppercasePropertyName {
var AAA: Int = -1 var AAA: Int = -1
var BBB: 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 import com.squareup.moshi.kotlin.codegen.GeneratedAdaptersTest.CustomGeneratedClass
// This also tests custom generated types with no moshi constructor // This also tests custom generated types with no moshi constructor
@Suppress("ktlint:standard:class-naming")
class GeneratedAdaptersTest_CustomGeneratedClassJsonAdapter : JsonAdapter<CustomGeneratedClass>() { class GeneratedAdaptersTest_CustomGeneratedClassJsonAdapter : JsonAdapter<CustomGeneratedClass>() {
override fun fromJson(reader: JsonReader): CustomGeneratedClass? { override fun fromJson(reader: JsonReader): CustomGeneratedClass? {
TODO() TODO()

View File

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

View File

@@ -190,8 +190,7 @@ internal class KotlinJsonAdapter<T>(
} }
public class KotlinJsonAdapterFactory : JsonAdapter.Factory { public class KotlinJsonAdapterFactory : JsonAdapter.Factory {
override fun create(type: Type, annotations: Set<Annotation>, moshi: Moshi): override fun create(type: Type, annotations: Set<Annotation>, moshi: Moshi): JsonAdapter<*>? {
JsonAdapter<*>? {
if (annotations.isNotEmpty()) return null if (annotations.isNotEmpty()) return null
val rawType = type.rawType 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 // We use JDK 17 for latest but target 16 for maximum compatibility
val service = project.extensions.getByType<JavaToolchainService>() val service = project.extensions.getByType<JavaToolchainService>()
val customLauncher = service.launcherFor { val customLauncher =
languageVersion.set(JavaLanguageVersion.of(17)) service.launcherFor {
} languageVersion.set(JavaLanguageVersion.of(17))
}
tasks.named<JavaCompile>("compileJava16Java") { tasks.named<JavaCompile>("compileJava16Java") {
options.release.set(16) options.release.set(16)

View File

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

View File

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

View File

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