Skip to content

Commit

Permalink
Upgrade ktlint to 1.0
Browse files Browse the repository at this point in the history
Whatever.
  • Loading branch information
JakeWharton committed Nov 30, 2023
1 parent 87d3af4 commit da7bbf6
Show file tree
Hide file tree
Showing 34 changed files with 191 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

private const val redwoodGroupId = "app.cash.redwood"
private const val REDWOOD_GROUP_ID = "app.cash.redwood"

// HEY! If you change the major version update release.yaml doc folder.
private const val redwoodVersion = "0.8.0-SNAPSHOT"
private const val REDWOOD_VERSION = "0.8.0-SNAPSHOT"

@Suppress("unused") // Invoked reflectively by Gradle.
class RedwoodBuildPlugin : Plugin<Project> {
private lateinit var libs: LibrariesForLibs

override fun apply(target: Project) {
target.group = redwoodGroupId
target.version = redwoodVersion
target.group = REDWOOD_GROUP_ID
target.version = REDWOOD_VERSION

libs = target.extensions.getByName("libs") as LibrariesForLibs

Expand Down Expand Up @@ -101,7 +101,10 @@ class RedwoodBuildPlugin : Plugin<Project> {
it.targetExclude("src/test/fixture/**/build/**")
}
it.ktlint(libs.ktlint.get().version).editorConfigOverride(
mapOf("ktlint_standard_filename" to "disabled"),
mapOf(
"ktlint_standard_filename" to "disabled",
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
),
)
it.licenseHeaderFile(licenseHeaderFile)
}
Expand Down Expand Up @@ -200,7 +203,8 @@ class RedwoodBuildPlugin : Plugin<Project> {
private fun Project.configureCommonKotlin() {
tasks.withType(KotlinCompile::class.java).configureEach {
it.kotlinOptions.freeCompilerArgs += listOf(
"-progressive", // https://kotlinlang.org/docs/whatsnew13.html#progressive-mode
// https://kotlinlang.org/docs/whatsnew13.html#progressive-mode
"-progressive",
"-Xexpect-actual-classes",
)
}
Expand Down Expand Up @@ -307,7 +311,7 @@ private class RedwoodBuildExtensionImpl(private val project: Project) : RedwoodB
signAllPublications()
}

coordinates(redwoodGroupId, project.name, redwoodVersion)
coordinates(REDWOOD_GROUP_ID, project.name, REDWOOD_VERSION)

pom { pom ->
pom.name.set(project.name)
Expand Down Expand Up @@ -424,7 +428,7 @@ private class RedwoodBuildExtensionImpl(private val project: Project) : RedwoodB
it.isCanBeResolved = false
it.isCanBeConsumed = true
it.attributes {
it.attribute(ziplineAttribute, ziplineAttributeValue)
it.attribute(ziplineAttribute, ZIPLINE_ATTRIBUTE_VALUE)
}
}
project.artifacts.add(ziplineConfiguration.name, zipTask)
Expand All @@ -447,7 +451,7 @@ private class RedwoodBuildExtensionImpl(private val project: Project) : RedwoodB
it.isCanBeResolved = true
it.isCanBeConsumed = false
it.attributes {
it.attribute(ziplineAttribute, ziplineAttributeValue)
it.attribute(ziplineAttribute, ZIPLINE_ATTRIBUTE_VALUE)
}
}
project.dependencies.add(ziplineConfiguration.name, dependencyNotation)
Expand All @@ -468,4 +472,4 @@ private class RedwoodBuildExtensionImpl(private val project: Project) : RedwoodB
}

private val ziplineAttribute = Attribute.of("zipline", String::class.java)
private const val ziplineAttributeValue = "yep"
private const val ZIPLINE_ATTRIBUTE_VALUE = "yep"
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jimfs = "com.google.jimfs:jimfs:1.3.0"
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
coil-core = { module = "io.coil-kt:coil", version.ref = "coil" }
turbine = "app.cash.turbine:turbine:1.0.0"
ktlint = "com.pinterest:ktlint:0.50.0"
ktlint = "com.pinterest.ktlint:ktlint-cli:1.0.1"
googleJavaFormat = "com.google.googlejavaformat:google-java-format:1.18.1"
poko-gradlePlugin = "dev.drewhamilton.poko:poko-gradle-plugin:0.15.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,15 @@ public inline fun <P : Widget.Provider<*>, W : Widget<*>> RedwoodComposeNode(
// Perform an explicit !! on the return value to avoid the Kotlin compiler inserting a huge
// string into the output as an error message for an otherwise implicit null check.
@Suppress(
"UNCHECKED_CAST", // Safe so long as you use generated composition function.
// Safe so long as you use generated composition function.
"UNCHECKED_CAST",
"UNNECESSARY_NOT_NULL_ASSERTION",
)
val applier = currentComposer.applier!! as RedwoodApplier<Any>

currentComposer.createNode {
@Suppress("UNCHECKED_CAST") // Safe so long as you use generated composition function.
// Safe so long as you use generated composition function.
@Suppress("UNCHECKED_CAST")
WidgetNode(applier, factory(applier.provider as P) as Widget<Any>)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.wasm
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption

private const val extensionName = "redwood"
private const val redwoodComposeArtifactId = "redwood-compose"
private const val EXTENSION_NAME = "redwood"
private const val REDWOOD_COMPOSE_ARTIFACT_ID = "redwood-compose"

public class RedwoodComposePlugin : KotlinCompilerPluginSupportPlugin {
private lateinit var extension: RedwoodComposeExtension

override fun apply(target: Project) {
super.apply(target)

extension = target.extensions.create(extensionName, RedwoodComposeExtension::class.java)
extension = target.extensions.create(EXTENSION_NAME, RedwoodComposeExtension::class.java)

target.plugins.withId("org.jetbrains.compose") {
throw IllegalStateException(
Expand All @@ -52,7 +52,7 @@ public class RedwoodComposePlugin : KotlinCompilerPluginSupportPlugin {
| sourceSets {
| commonMain {
| dependencies {
| implementation("${target.redwoodDependency(redwoodComposeArtifactId)}")
| implementation("${target.redwoodDependency(REDWOOD_COMPOSE_ARTIFACT_ID)}")
| }
| }
| }
Expand All @@ -71,7 +71,7 @@ public class RedwoodComposePlugin : KotlinCompilerPluginSupportPlugin {
|within an Android Compose-based project you only need to add the runtime dependency:
|
| dependencies {
| implementation("${target.redwoodDependency(redwoodComposeArtifactId)}")
| implementation("${target.redwoodDependency(REDWOOD_COMPOSE_ARTIFACT_ID)}")
| }
""".trimMargin()
}
Expand All @@ -94,7 +94,7 @@ public class RedwoodComposePlugin : KotlinCompilerPluginSupportPlugin {
3 -> SubpluginArtifact(parts[0], parts[1], parts[2])
else -> error(
"""
|Illegal format of '$extensionName.${RedwoodComposeExtension::kotlinCompilerPlugin.name}' property.
|Illegal format of '$EXTENSION_NAME.${RedwoodComposeExtension::kotlinCompilerPlugin.name}' property.
|Expected format: either '<VERSION>' or '<GROUP_ID>:<ARTIFACT_ID>:<VERSION>'
|Actual value: '$plugin'
""".trimMargin(),
Expand All @@ -104,7 +104,7 @@ public class RedwoodComposePlugin : KotlinCompilerPluginSupportPlugin {

override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> {
kotlinCompilation.dependencies {
api(project.redwoodDependency(redwoodComposeArtifactId))
api(project.redwoodDependency(REDWOOD_COMPOSE_ARTIFACT_ID))
}

when (kotlinCompilation.platformType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.androidJvm
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.common
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget

private const val baseTaskName = "redwoodLint"
private const val BASE_TASK_NAME = "redwoodLint"

@Suppress("unused") // Invoked reflectively by Gradle.
public class RedwoodLintPlugin : Plugin<Project> {
Expand All @@ -51,7 +51,7 @@ public class RedwoodLintPlugin : Plugin<Project> {
}

val task = if (project.plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) {
val rootTask = project.tasks.register(baseTaskName) {
val rootTask = project.tasks.register(BASE_TASK_NAME) {
it.group = VERIFICATION_GROUP
it.description = taskDescription("all Kotlin targets")
}
Expand All @@ -68,7 +68,7 @@ public class RedwoodLintPlugin : Plugin<Project> {
checkNotNull(androidPlugin) {
"Kotlin Android plugin requires either Android application or library plugin"
}
val rootTask = project.tasks.register(baseTaskName) {
val rootTask = project.tasks.register(BASE_TASK_NAME) {
it.group = VERIFICATION_GROUP
it.description = taskDescription("all Kotlin targets")
}
Expand Down Expand Up @@ -110,7 +110,7 @@ private fun configureKotlinAndroidVariants(
}
variants.configureEach { variant ->
val taskName = buildString {
append(baseTaskName)
append(BASE_TASK_NAME)
if (prefix) {
append("Android")
}
Expand Down Expand Up @@ -146,7 +146,7 @@ private fun configureKotlinMultiplatformTargets(
val task = createKotlinTargetRedwoodLintTask(
project,
target,
taskName = baseTaskName + target.name.replaceFirstChar { it.titlecase(ROOT) },
taskName = BASE_TASK_NAME + target.name.replaceFirstChar { it.titlecase(ROOT) },
)
rootTask.configure {
it.dependsOn(task)
Expand All @@ -158,7 +158,7 @@ private fun configureKotlinJvmProject(
project: Project,
): TaskProvider<out Task> {
val kotlin = project.extensions.getByType(KotlinJvmProjectExtension::class.java)
return createKotlinTargetRedwoodLintTask(project, kotlin.target, baseTaskName)
return createKotlinTargetRedwoodLintTask(project, kotlin.target, BASE_TASK_NAME)
}

private fun createKotlinTargetRedwoodLintTask(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private abstract class RedwoodSchemaApiWorker @Inject constructor(
"--file",
parameters.apiFile.get().asFile.absolutePath,
"--fix-with",
RedwoodApiGenerateTaskName,
REDWOOD_API_GENERATE_TASK_NAME,
"--class-path",
parameters.classpath.files.joinToString(File.pathSeparator),
parameters.schemaType.get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class RedwoodSchemaPlugin : Plugin<Project> {
if (extension.apiTracking.get()) {
val apiFile = project.layout.projectDirectory.file("redwood-api.xml")

project.tasks.register(RedwoodApiGenerateTaskName, RedwoodSchemaApiGenerateTask::class.java) {
project.tasks.register(REDWOOD_API_GENERATE_TASK_NAME, RedwoodSchemaApiGenerateTask::class.java) {
it.group = BUILD_GROUP
it.description = "Write an updated API tracking file for the current schema"

Expand Down Expand Up @@ -110,4 +110,4 @@ public class RedwoodSchemaPlugin : Plugin<Project> {
}
}

internal const val RedwoodApiGenerateTaskName = "redwoodApiGenerate"
internal const val REDWOOD_API_GENERATE_TASK_NAME = "redwoodApiGenerate"
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ internal class ComposeUiFlexContainer(
val constrainedWidth = if (constraints.hasFixedWidth) {
constraints.maxWidth.toFloat()
} else {
Size.Undefined
Size.UNDEFINED
}
val constrainedHeight = if (constraints.hasFixedHeight) {
constraints.maxHeight.toFloat()
} else {
Size.Undefined
Size.UNDEFINED
}
rootNode.measure(constrainedWidth, constrainedHeight)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class YogaUIView(
}

override fun intrinsicContentSize(): CValue<CGSize> {
return calculateLayoutWithSize(CGSizeMake(Size.Undefined.toDouble(), Size.Undefined.toDouble()))
return calculateLayoutWithSize(CGSizeMake(Size.UNDEFINED.toDouble(), Size.UNDEFINED.toDouble()))
}

override fun sizeThatFits(size: CValue<CGSize>): CValue<CGSize> {
Expand All @@ -62,9 +62,9 @@ internal class YogaUIView(
// combined into one call.
val scrollSize = bounds.useContents {
if (rootNode.flexDirection == FlexDirection.Column) {
CGSizeMake(width, Size.Undefined.toDouble())
CGSizeMake(width, Size.UNDEFINED.toDouble())
} else {
CGSizeMake(Size.Undefined.toDouble(), height)
CGSizeMake(Size.UNDEFINED.toDouble(), height)
}
}
val contentSize = calculateLayoutWithSize(scrollSize)
Expand Down Expand Up @@ -113,7 +113,7 @@ internal class YogaUIView(

private fun sizeForConstraintsDimension(constraint: Constraint, dimension: Double): Double {
if (constraint == Constraint.Wrap || dimension == UIViewNoIntrinsicMetric) {
return Size.Undefined.toDouble()
return Size.UNDEFINED.toDouble()
} else {
return dimension
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ internal class YogaLayout(
}

private fun calculateLayout(widthSpec: Int, heightSpec: Int) {
rootNode.requestedWidth = Size.Undefined
rootNode.requestedMaxWidth = Size.Undefined
rootNode.requestedHeight = Size.Undefined
rootNode.requestedMaxHeight = Size.Undefined
rootNode.requestedWidth = Size.UNDEFINED
rootNode.requestedMaxWidth = Size.UNDEFINED
rootNode.requestedHeight = Size.UNDEFINED
rootNode.requestedMaxHeight = Size.UNDEFINED

val widthSize = MeasureSpec.getSize(widthSpec).toFloat()
when (MeasureSpec.getMode(widthSpec)) {
Expand All @@ -90,7 +90,7 @@ internal class YogaLayout(
applyModifier(node, index)
}

rootNode.measure(Size.Undefined, Size.Undefined)
rootNode.measure(Size.UNDEFINED, Size.UNDEFINED)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import app.cash.redwood.layout.api.CrossAxisAlignment
import app.cash.redwood.ui.Margin
import kotlin.jvm.JvmName

private const val OffscreenItemsBufferCount = 30
private const val OFFSCREEN_ITEMS_BUFFER_COUNT = 30

@Composable
internal fun LazyList(
Expand All @@ -45,8 +45,8 @@ internal fun LazyList(
) {
val itemProvider = rememberLazyListItemProvider(content)
val itemCount = itemProvider.itemCount
val itemsBefore = (state.firstIndex - OffscreenItemsBufferCount / 2).coerceAtLeast(0)
val itemsAfter = (itemCount - (state.lastIndex + OffscreenItemsBufferCount / 2).coerceAtMost(itemCount)).coerceAtLeast(0)
val itemsBefore = (state.firstIndex - OFFSCREEN_ITEMS_BUFFER_COUNT / 2).coerceAtLeast(0)
val itemsAfter = (itemCount - (state.lastIndex + OFFSCREEN_ITEMS_BUFFER_COUNT / 2).coerceAtMost(itemCount)).coerceAtLeast(0)
// TODO(jwilson): drop this down to 20 once this is fixed:
// https://github.com/cashapp/redwood/issues/1551
var placeholderPoolSize by remember { mutableStateOf(30) }
Expand Down Expand Up @@ -98,8 +98,8 @@ internal fun RefreshableLazyList(
) {
val itemProvider = rememberLazyListItemProvider(content)
val itemCount = itemProvider.itemCount
val itemsBefore = (state.firstIndex - OffscreenItemsBufferCount / 2).coerceAtLeast(0)
val itemsAfter = (itemCount - (state.lastIndex + OffscreenItemsBufferCount / 2).coerceAtMost(itemCount)).coerceAtLeast(0)
val itemsBefore = (state.firstIndex - OFFSCREEN_ITEMS_BUFFER_COUNT / 2).coerceAtLeast(0)
val itemsAfter = (itemCount - (state.lastIndex + OFFSCREEN_ITEMS_BUFFER_COUNT / 2).coerceAtMost(itemCount)).coerceAtLeast(0)
var placeholderPoolSize by remember { mutableStateOf(20) }
RefreshableLazyList(
isVertical,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ internal open class UIViewLazyList(
index: Int,
): LazyListContainerCell {
val result = tableView.dequeueReusableCellWithIdentifier(
identifier = reuseIdentifier,
identifier = REUSE_IDENTIFIER,
forIndexPath = NSIndexPath.indexPathForItem(index.convert(), 0.convert()),
) as LazyListContainerCell
require(result.binding == null)
Expand Down Expand Up @@ -181,9 +181,9 @@ internal open class UIViewLazyList(
separatorStyle = UITableViewCellSeparatorStyleNone

registerClass(
cellClass = LazyListContainerCell(UITableViewCellStyle.UITableViewCellStyleDefault, reuseIdentifier)
cellClass = LazyListContainerCell(UITableViewCellStyle.UITableViewCellStyleDefault, REUSE_IDENTIFIER)
.initWithFrame(CGRectZero.readValue()).classForCoder() as ObjCClass?,
forCellReuseIdentifier = reuseIdentifier,
forCellReuseIdentifier = REUSE_IDENTIFIER,
)
}
}
Expand Down Expand Up @@ -232,7 +232,7 @@ internal open class UIViewLazyList(
}
}

private const val reuseIdentifier = "LazyListContainerCell"
private const val REUSE_IDENTIFIER = "LazyListContainerCell"

internal class LazyListContainerCell(
style: UITableViewCellStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import kotlinx.coroutines.flow.StateFlow
* @param scope A [CoroutineScope] whose [coroutineContext][kotlin.coroutines.CoroutineContext]
* must have a [MonotonicFrameClock] key which is being ticked.
*/
@Suppress("FunctionName")
public fun ProtocolRedwoodComposition(
scope: CoroutineScope,
bridge: ProtocolBridge,
Expand Down
Loading

0 comments on commit da7bbf6

Please sign in to comment.