Skip to content

Commit

Permalink
Update dependency com.pinterest.ktlint:ktlint-cli to v1.2.0 (#1826)
Browse files Browse the repository at this point in the history
* Update dependency com.pinterest.ktlint:ktlint-cli to v1.2.0

* Fix ktlint

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jake Wharton <jw@squareup.com>
  • Loading branch information
renovate[bot] and JakeWharton authored Feb 28, 2024
1 parent c81bd35 commit 43e28ee
Show file tree
Hide file tree
Showing 25 changed files with 107 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,38 @@ internal fun Node.applyModifier(parentModifier: Modifier, density: Density) {
is GrowModifier -> {
flexGrow = childModifier.value.toFloat()
}

is ShrinkModifier -> {
flexShrink = childModifier.value.toFloat()
}

is MarginModifier -> with(density) {
marginStart = childModifier.margin.start.toPx().toFloat()
marginEnd = childModifier.margin.end.toPx().toFloat()
marginTop = childModifier.margin.top.toPx().toFloat()
marginBottom = childModifier.margin.bottom.toPx().toFloat()
}

is HorizontalAlignmentModifier -> {
alignSelf = childModifier.alignment.toAlignSelf()
}

is VerticalAlignmentModifier -> {
alignSelf = childModifier.alignment.toAlignSelf()
}

is WidthModifier -> with(density) {
val width = childModifier.width.toPx().toFloat()
requestedMinWidth = width
requestedMaxWidth = width
}

is HeightModifier -> with(density) {
val height = childModifier.height.toPx().toFloat()
requestedMinHeight = height
requestedMaxHeight = height
}

is SizeModifier -> with(density) {
val width = childModifier.width.toPx().toFloat()
requestedMinWidth = width
Expand All @@ -124,6 +131,7 @@ internal fun Node.applyModifier(parentModifier: Modifier, density: Density) {
requestedMinHeight = height
requestedMaxHeight = height
}

is FlexModifier -> {
val flex = childModifier.value.coerceAtLeast(0.0).toFloat()
flexGrow = flex
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ coil-compose = { module = "io.coil-kt.coil3:coil-compose-core", version.ref = "c
coil-core = { module = "io.coil-kt.coil3:coil", version.ref = "coil" }
coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil" }
turbine = "app.cash.turbine:turbine:1.0.0"
ktlint = "com.pinterest.ktlint:ktlint-cli:1.1.1"
ktlint = "com.pinterest.ktlint:ktlint-cli:1.2.0"
ktlintComposeRules = "io.nlopez.compose.rules:ktlint:0.3.11"
googleJavaFormat = "com.google.googlejavaformat:google-java-format:1.20.0"
poko-gradlePlugin = "dev.drewhamilton.poko:poko-gradle-plugin:0.15.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public class RedwoodComposePlugin : KotlinCompilerPluginSupportPlugin {
val parts = plugin.split(":")
return when (parts.size) {
1 -> SubpluginArtifact("org.jetbrains.compose.compiler", "compiler", parts[0])

3 -> SubpluginArtifact(parts[0], parts[1], parts[2])

else -> error(
"""
|Illegal format of '$EXTENSION_NAME.${RedwoodComposeExtension::kotlinCompilerPlugin.name}' property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@ internal fun measureSpecsToConstraints(
minWidth = width.toInt()
maxWidth = width.toInt()
}

MeasureMode.AtMost -> {
minWidth = 0
maxWidth = width.toInt()
}

MeasureMode.Undefined -> {
minWidth = 0
maxWidth = Constraints.Infinity
}

else -> throw AssertionError()
}
val minHeight: Int
Expand All @@ -94,14 +97,17 @@ internal fun measureSpecsToConstraints(
minHeight = height.toInt()
maxHeight = height.toInt()
}

MeasureMode.AtMost -> {
minHeight = 0
maxHeight = height.toInt()
}

MeasureMode.Undefined -> {
minHeight = 0
maxHeight = Constraints.Infinity
}

else -> throw AssertionError()
}
return Constraints(minWidth, maxWidth, minHeight, maxHeight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@ internal class UIViewBox : Box<UIView> {
is HorizontalAlignment -> {
itemHorizontalAlignment = childModifier.alignment
}

is VerticalAlignment -> {
itemVerticalAlignment = childModifier.alignment
}

is Width -> {
requestedWidth = childModifier.width.toPlatformDp()
}

is Height -> {
requestedHeight = childModifier.height.toPlatformDp()
}
Expand All @@ -132,17 +135,23 @@ internal class UIViewBox : Box<UIView> {
x = 0.0
childWidth = frame.useContents { this.size.width }
}

CrossAxisAlignment.Start -> x = 0.0

CrossAxisAlignment.Center -> x = (frame.useContents { this.size.width } - childWidth) / 2.0

CrossAxisAlignment.End -> x = frame.useContents { this.size.width } - childWidth
}
when (itemVerticalAlignment) {
CrossAxisAlignment.Stretch -> {
y = 0.0
childHeight = frame.useContents { this.size.height }
}

CrossAxisAlignment.Start -> y = 0.0

CrossAxisAlignment.Center -> y = (frame.useContents { this.size.height } - childHeight) / 2.0

CrossAxisAlignment.End -> y = frame.useContents { this.size.height } - childHeight
}

Expand All @@ -167,6 +176,7 @@ internal class UIViewBox : Box<UIView> {
maxRequestedWidth = childModifier.width.value
}
}

is Height -> {
if (childModifier.height.value > maxRequestedHeight) {
maxRequestedHeight = childModifier.height.value
Expand All @@ -184,6 +194,7 @@ internal class UIViewBox : Box<UIView> {
maxItemWidth = size.useContents { this.width }
maxItemHeight = size.useContents { this.height }
}

Constraint.Wrap -> { // Fill Wrap
maxItemWidth = size.useContents { this.width }
maxItemHeight = typedSubviews
Expand All @@ -192,6 +203,7 @@ internal class UIViewBox : Box<UIView> {
}
}
}

Constraint.Wrap -> {
when (heightConstraint) {
Constraint.Fill -> { // Wrap Fill
Expand All @@ -200,6 +212,7 @@ internal class UIViewBox : Box<UIView> {
.max()
maxItemHeight = size.useContents { this.height }
}

Constraint.Wrap -> { // Wrap Wrap
val unconstrainedSizes = typedSubviews
.map { it.sizeThatFits(size) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public abstract class LazyListUpdateProcessor<V : Any, W : Any> {
itemsBefore.removeRange(0, delta)
deleteRows(0, delta)
}

newItemsBefore > itemsBefore.size -> {
// Grow the before window.
val delta = newItemsBefore - itemsBefore.size
Expand All @@ -236,6 +237,7 @@ public abstract class LazyListUpdateProcessor<V : Any, W : Any> {
itemsAfter.removeRange(itemsAfter.size - delta, itemsAfter.size)
deleteRows(index, delta)
}

newItemsAfter > itemsAfter.size -> {
// Grow the after window.
val delta = newItemsAfter - itemsAfter.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ internal class SparseList<T> : AbstractList<T?>() {
}
null
}

else -> {
externalIndexes.removeAt(searchIndex)
for (i in searchIndex until externalIndexes.size) {
Expand Down Expand Up @@ -102,6 +103,7 @@ internal class SparseList<T> : AbstractList<T?>() {
externalIndexes.add(insertIndex, index)
insertIndex + 1
}

else -> insertIndex
}

Expand Down Expand Up @@ -155,12 +157,14 @@ internal class SparseList<T> : AbstractList<T?>() {
nextExternalIndex++
return
}

// Return a non-null element and bump the internal index.
nextInternalIndex < elements.size -> {
setNext(elements[nextInternalIndex])
nextInternalIndex++
nextExternalIndex++
}

else -> done()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,19 @@ class ProtocolTest {
0 -> {
{ state = 1 }
}

1 -> {
{ state = 2 }
}

2 -> {
null
}

3 -> {
null
}

else -> fail()
},
)
Expand Down Expand Up @@ -239,9 +243,11 @@ class ProtocolTest {
0 -> {
{ state = 1 }
}

1 -> {
{ state = 2 }
}

else -> fail()
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class ProtocolBridge<W : Any>(
"Insert attempted to replace existing widget with ID ${change.id.value}"
}
}

is ChildrenChange -> {
val node = node(id)
val children = node.children(change.tag) ?: continue
Expand All @@ -76,9 +77,11 @@ public class ProtocolBridge<W : Any>(
val child = node(change.childId)
children.insert(change.index, child)
}

is Move -> {
children.move(change.fromIndex, change.toIndex, change.count)
}

is Remove -> {
children.remove(change.index, change.count)
@Suppress("ConvertArgumentToSet") // Compose side guarantees set semantics.
Expand All @@ -91,6 +94,7 @@ public class ProtocolBridge<W : Any>(
changedWidgets += widget
}
}

is ModifierChange -> {
val modifier = change.elements.fold<_, Modifier>(Modifier) { modifier, element ->
modifier.then(factory.createModifier(element))
Expand All @@ -103,6 +107,7 @@ public class ProtocolBridge<W : Any>(
changedWidgets += widget
}
}

is PropertyChange -> {
val node = node(change.id)
node.apply(change, eventSink)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ public class Margin(
start != end || top != bottom -> {
"Margin(start=$start, end=$end, top=$top, bottom=$bottom)"
}

start != top -> {
"Margin(horizontal=$start, vertical=$top)"
}

else -> "Margin(all=$start)"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ internal class GenerateCommand : CliktCommand(name = "generate") {
val schemaSet = ProtocolSchemaSet.load(schemaType, classLoader)
schemaSet.generate(type, out)
}

is ProtocolCodegenType -> {
val schemaSet = ProtocolSchemaSet.load(schemaType, classLoader)
schemaSet.generate(type, out)
}

else -> throw AssertionError()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ internal fun SchemaSet.generateFileSpecs(type: CodegenType): List<FileSpec> {
add(generateComposable(schema, widget))
}
}

Modifiers -> {
for (modifier in schema.modifiers) {
add(generateModifierInterface(schema, modifier))
}
}

Testing -> {
add(generateTester(this@generateFileSpecs))
add(generateMutableWidgetFactory(schema))
Expand All @@ -61,6 +63,7 @@ internal fun SchemaSet.generateFileSpecs(type: CodegenType): List<FileSpec> {
add(generateWidgetValue(schema, widget))
}
}

Widget -> {
add(generateWidgetFactories(this@generateFileSpecs))
add(generateWidgetFactory(schema))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ internal fun generateComposable(
}
.build()
}

is Event -> {
ParameterSpec.builder(trait.name, trait.lambdaType)
.apply {
Expand All @@ -121,6 +122,7 @@ internal fun generateComposable(
}
.build()
}

is Children -> {
val scope = trait.scope?.let { ClassName(schema.composePackage(), it.flatName) }
ParameterSpec.builder(trait.name, composableLambda(scope))
Expand All @@ -132,6 +134,7 @@ internal fun generateComposable(
}
.build()
}

is ProtocolTrait -> throw AssertionError()
},
)
Expand All @@ -149,6 +152,7 @@ internal fun generateComposable(
-> {
updateLambda.add("set(%1N) { recordChanged(); widget.%1N(it) }\n", trait.name)
}

is Children -> {
childrenLambda.apply {
add("Children(%T::%N) {\n", widgetType, trait.name)
Expand All @@ -161,6 +165,7 @@ internal fun generateComposable(
add("}\n")
}
}

is ProtocolTrait -> throw AssertionError()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal fun ProtocolSchemaSet.generateFileSpecs(type: ProtocolCodegenType): Lis
}
}
}

Widget -> {
add(generateProtocolFactory(this@generateFileSpecs))
for (dependency in all) {
Expand Down
Loading

0 comments on commit 43e28ee

Please sign in to comment.