Skip to content

Commit

Permalink
refactor: Spaces
Browse files Browse the repository at this point in the history
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.java.format.Spaces?organizationId=T3BlblJld3JpdGU%3D

Co-authored-by: Moderne <team@moderne.io>
  • Loading branch information
jkschneider and TeamModerne committed Sep 26, 2023
1 parent dde86e4 commit 991a8d0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/main/kotlin/org/openrewrite/RecipeDescriptorExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.openrewrite
import org.openrewrite.config.OptionDescriptor
import org.openrewrite.config.RecipeDescriptor

fun RecipeDescriptor.asYaml(): String {
fun RecipeDescriptor.asYaml( ): String {
val s = StringBuilder()
s.appendLine("""
---
Expand All @@ -12,46 +12,46 @@ fun RecipeDescriptor.asYaml(): String {
displayName: $displayName
description: $description
""".trimIndent())
if(tags.isNotEmpty()) {
if (tags.isNotEmpty()) {
s.appendLine("tags:")
for(tag in tags) {
for (tag in tags) {
s.appendLine(" - $tag")
}
}
if(options.isNotEmpty()) {
for(option in options) {
if (options.isNotEmpty()) {
for (option in options) {
s.appendLine(option.asYaml())
}
}
if(recipeList.isNotEmpty()) {
if (recipeList.isNotEmpty()) {
s.appendLine("recipeList:")
for(subRecipe in recipeList) {
for (subRecipe in recipeList) {
s.append(" - ${subRecipe.name}")
if(subRecipe.options.isEmpty()) {
if (subRecipe.options.isEmpty()) {
s.appendLine()
} else {
s.appendLine(":")
}
for(subOption in subRecipe.options) {
for (subOption in subRecipe.options) {
s.append(subOption.asYaml(3))
}
}
}
return s.toString()
}

fun OptionDescriptor.asYaml(indentation: Int = 0): String {
if(value == null) {
fun OptionDescriptor.asYaml( indentation: Int = 0): String {
if (value == null) {
return ""
}
val prefixBuilder = StringBuilder()
(0 until indentation).forEach { _ ->
(0 untilindentation).forEach{ _ ->
prefixBuilder.append(" ")
}

val prefix = prefixBuilder.toString()
val formattedValue = if(value is Array<*>) {
val asArray = value as Array<*>
val formattedValue = if (value is Array<*>) {
val asArray = value asArray<*>
"[${asArray.joinToString(", ")}]"
} else {
value
Expand Down

0 comments on commit 991a8d0

Please sign in to comment.