Skip to content

Commit

Permalink
Upgrade ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbrooks committed Oct 5, 2024
1 parent 5f278bf commit 388a944
Show file tree
Hide file tree
Showing 47 changed files with 582 additions and 408 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ changelog.path.set("changelog.md")
subprojects {
apply<KtlintPlugin>()
configure<KtlintExtension> {
version.set("1.2.1")
version.set("1.3.1")
}

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
Expand Down
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
### Changed

- `vgo-plugin` (`com.jzbrooks.vgo.plugin`) no longer requires a particular version of Android Gradle Plugin.
Note: `:vgo` is now an abstract impmeentation of the tool which does not assume either a cli or plugin context. CLI related logic has been relocated into `:vgo-core`.
Note: `:vgo` is now an abstract implementation of the tool which does not assume either a cli or plugin context. CLI related logic has been relocated into `:vgo-core`.

### Deprecated

Expand Down
13 changes: 10 additions & 3 deletions vgo-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ tasks {
attributes["Bundle-Version"] = project.properties["VERSION_NAME"]
}

val sourceClasses = sourceSets.main.get().output.classesDirs
val sourceClasses =
sourceSets.main
.get()
.output.classesDirs
inputs.files(sourceClasses)
destinationDirectory.set(layout.buildDirectory.dir("libs/debug"))

doFirst {
from(files(sourceClasses))
from(configurations.runtimeClasspath.get().asFileTree.files.map(::zipTree))
from(
configurations.runtimeClasspath
.get()
.asFileTree.files
.map(::zipTree),
)

exclude(
"**/*.kotlin_metadata",
Expand All @@ -41,7 +49,6 @@ tasks {
}
}


val optimize by registering(JavaExec::class) {
description = "Runs r8 on the jar application."
group = "build"
Expand Down
9 changes: 5 additions & 4 deletions vgo-cli/src/main/kotlin/com/jzbrooks/vgo/cli/ArgReader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import kotlin.collections.map
import kotlin.text.isNotBlank
import kotlin.text.split

class ArgReader(private val args: MutableList<String>) {
class ArgReader(
private val args: MutableList<String>,
) {
private val hasArguments
get() = args.isNotEmpty()

Expand Down Expand Up @@ -73,12 +75,11 @@ class ArgReader(private val args: MutableList<String>) {
private fun isOptionArgument(
name: String,
argument: String,
): Boolean {
return if (name.length == 1) {
): Boolean =
if (name.length == 1) {
"-$name" == argument
} else {
"--$name" == argument
}
}
}
}
41 changes: 41 additions & 0 deletions vgo-cli/src/main/kotlin/com/jzbrooks/vgo/cli/CliMain.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.jzbrooks.vgo.cli

import com.jzbrooks.vgo.Application
import kotlin.system.exitProcess

fun main(args: Array<String>) {
val argReader = ArgReader(args.toMutableList())

val printHelp = argReader.readFlag("help|h")
val printVersion = argReader.readFlag("version|v")
val printStats = argReader.readFlag("stats|s")
val indent = argReader.readOption("indent")?.toIntOrNull()

val outputs =
run {
val outputPaths = mutableListOf<String>()
var output = argReader.readOption("output|o")
while (output != null) {
outputPaths.add(output)
output = argReader.readOption("output|o")
}
outputPaths.toList()
}

var format = argReader.readOption("format")

var inputs = argReader.readArguments()

val options =
Application.Options(
printHelp = printHelp,
printVersion = printVersion,
printStats = printStats,
indent = indent,
output = outputs,
format = format,
input = inputs,
)

exitProcess(Application(options).run())
}
39 changes: 0 additions & 39 deletions vgo-cli/src/main/kotlin/com/jzbrooks/vgo/cli/main.kt

This file was deleted.

9 changes: 5 additions & 4 deletions vgo-core/src/main/kotlin/com/jzbrooks/vgo/core/Color.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.jzbrooks.vgo.core

@JvmInline
value class Color(private val argb: UInt) {
value class Color(
private val argb: UInt,
) {
val alpha: UByte
get() = (argb shr 24).toUByte()

Expand All @@ -22,8 +24,8 @@ value class Color(private val argb: UInt) {

operator fun component4() = blue

fun toHexString(format: HexFormat): String {
return if (alpha != 0xFF.toUByte()) {
fun toHexString(format: HexFormat): String =
if (alpha != 0xFF.toUByte()) {
val pattern = "#%02x%02x%02x%02x"
when (format) {
HexFormat.ARGB ->
Expand All @@ -50,7 +52,6 @@ value class Color(private val argb: UInt) {
hexColor
}
}
}

enum class HexFormat {
RGBA,
Expand Down
4 changes: 3 additions & 1 deletion vgo-core/src/main/kotlin/com/jzbrooks/vgo/core/Writer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface Writer<in T : Graphic> {
)

sealed class Option {
class Indent(val columns: Int) : Option()
class Indent(
val columns: Int,
) : Option()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ package com.jzbrooks.vgo.core.graphic.command
import com.jzbrooks.vgo.core.util.math.Point

@JvmInline
value class CommandString(val data: String) {
fun toCommandList(): List<Command> {
return data.split(commandRegex)
value class CommandString(
val data: String,
) {
fun toCommandList(): List<Command> =
data
.split(commandRegex)
.asSequence()
.filter { it.isNotBlank() }
.map { command ->
val variant = if (command[0].isLowerCase()) CommandVariant.RELATIVE else CommandVariant.ABSOLUTE
when {
command.startsWith('M', true) -> {
val parameters =
number.findAll(command)
number
.findAll(command)
.map(MatchResult::value)
.map(String::toFloat)
.chunked(2)
Expand All @@ -24,7 +28,8 @@ value class CommandString(val data: String) {
}
command.startsWith('L', true) -> {
val parameters =
number.findAll(command)
number
.findAll(command)
.map(MatchResult::value)
.map(String::toFloat)
.chunked(2)
Expand All @@ -35,23 +40,26 @@ value class CommandString(val data: String) {
}
command.startsWith('V', true) -> {
val parameters =
number.findAll(command)
number
.findAll(command)
.map { it.value.toFloat() }
.toList()

VerticalLineTo(variant, parameters)
}
command.startsWith('H', true) -> {
val parameters =
number.findAll(command)
number
.findAll(command)
.map { it.value.toFloat() }
.toList()

HorizontalLineTo(variant, parameters)
}
command.startsWith('Q', true) -> {
val parameters =
number.findAll(command)
number
.findAll(command)
.map(MatchResult::value)
.map(String::toFloat)
.chunked(4)
Expand All @@ -62,7 +70,8 @@ value class CommandString(val data: String) {
}
command.startsWith('T', true) -> {
val parameters =
number.findAll(command)
number
.findAll(command)
.map(MatchResult::value)
.map(String::toFloat)
.chunked(2)
Expand All @@ -73,7 +82,8 @@ value class CommandString(val data: String) {
}
command.startsWith('C', true) -> {
val parameters =
number.findAll(command)
number
.findAll(command)
.map(MatchResult::value)
.map(String::toFloat)
.chunked(6)
Expand All @@ -84,7 +94,8 @@ value class CommandString(val data: String) {
}
command.startsWith('S', true) -> {
val parameters =
number.findAll(command)
number
.findAll(command)
.map(MatchResult::value)
.map(String::toFloat)
.chunked(4)
Expand All @@ -95,7 +106,8 @@ value class CommandString(val data: String) {
}
command.startsWith('A', true) -> {
val parameters =
number.findAll(command)
number
.findAll(command)
.map(MatchResult::value)
.map(String::toFloat)
.chunked(7)
Expand All @@ -108,11 +120,8 @@ value class CommandString(val data: String) {
else -> throw IllegalStateException("Expected one of $commandRegex but was $command")
}
}.toList()
}

private fun mapPoint(components: List<Float>): Point {
return Point(components[0], components[1])
}
private fun mapPoint(components: List<Float>): Point = Point(components[0], components[1])

private fun mapQuadraticBezierCurveParameter(components: List<Float>): QuadraticBezierCurve.Parameter {
val control = Point(components[0], components[1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ data class CubicBezierCurve(
override var variant: CommandVariant,
override var parameters: List<Parameter>,
) : CubicCurve<CubicBezierCurve.Parameter> {
data class Parameter(var startControl: Point, var endControl: Point, override var end: Point) : CommandParameter
data class Parameter(
var startControl: Point,
var endControl: Point,
override var end: Point,
) : CommandParameter
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ data class QuadraticBezierCurve(
override var variant: CommandVariant,
override var parameters: List<Parameter>,
) : ParameterizedCommand<QuadraticBezierCurve.Parameter> {
data class Parameter(var control: Point, override var end: Point) : CommandParameter
data class Parameter(
var control: Point,
override var end: Point,
) : CommandParameter
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ data class SmoothCubicBezierCurve(
override var variant: CommandVariant,
override var parameters: List<Parameter>,
) : CubicCurve<SmoothCubicBezierCurve.Parameter> {
data class Parameter(var endControl: Point, override var end: Point) : CommandParameter
data class Parameter(
var endControl: Point,
override var end: Point,
) : CommandParameter
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import java.util.Stack
/**
* Apply transformations to paths command coordinates in a group
*/
class BakeTransformations : ElementVisitor, BottomUpOptimization {
class BakeTransformations :
ElementVisitor,
BottomUpOptimization {
override fun visit(graphic: Graphic) {}

override fun visit(clipPath: ClipPath) {}
Expand Down Expand Up @@ -58,12 +60,11 @@ class BakeTransformations : ElementVisitor, BottomUpOptimization {
group.transform = Matrix3.IDENTITY
}

private fun areElementsRelocatable(group: Group): Boolean {
return group.id == null &&
private fun areElementsRelocatable(group: Group): Boolean =
group.id == null &&
group.transform.contentsEqual(Matrix3.IDENTITY) &&
group.foreign.isEmpty() &&
group.elements.all { it is Path }
}

private fun applyTransform(
path: Path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class BreakoutImplicitCommands : TopDownOptimization {
path.commands = commands
}

private fun divideParameters(first: ParameterizedCommand<*>): List<Command> {
return when (first) {
private fun divideParameters(first: ParameterizedCommand<*>): List<Command> =
when (first) {
is MoveTo ->
first.parameters.mapIndexed { i, it ->
if (i == 0) first.copy(parameters = listOf(it)) else LineTo(first.variant, listOf(it))
Expand All @@ -61,5 +61,4 @@ class BreakoutImplicitCommands : TopDownOptimization {
is SmoothCubicBezierCurve -> first.parameters.map { first.copy(parameters = listOf(it)) }
is EllipticalArcCurve -> first.parameters.map { first.copy(parameters = listOf(it)) }
}
}
}
Loading

0 comments on commit 388a944

Please sign in to comment.