rewrite
rewrite copied to clipboard
Yaml - coalesce less
As discussed w/ @jkschneider on slack, consider a test case like this:
@Test
fun `does not reformat properties outside the affected key`() = rewriteRun({ spec ->
spec.recipe(ChangePropertyKey("a.b.c", "x.y.z", true, null))
},
yaml(
"""
a:
b:
c: abc
something:
else: qwe
""", """
x:
y:
z: abc
something:
else: qwe
"""
)
)
This case fails, as the actual value is this:
# file leads with an empty line
something.else: qwe
x.y.z: abc
Few observations, ordered subjectively from most-to-least severe:
- The key
something.else
gets coalesced, though it was unrelated to the change -
x.y.z
gets coalesced, though the key it replaced was styled as non-coalesced -
x.y.z
gets relocated in the file - The resultant file has an extraneous newline at the beginning
These tend to conflict w/ this design intent: "OpenRewrite recipes make minimally invasive changes to your source code that honor the original formatting" (from the main page of the docs site).
This issue targets that first observation, and we'd like to try simply removing nested usages of CoalesceProperties
from other recipes. This should get us closer to a target state, with low risk of functional changes.
This could include:
-
ChangePropertyKey
-
DeleteProperty
-
MergeBootstrapYamlWithApplicationYaml
-
MigrateDatabaseCredentials
Future enhancements could include defining Styles for Yaml, to better-protect indent-vs-dot preferences.