openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.13k stars 317 forks source link

org.openrewrite.java.format.Spaces wrongly remove spaces in build.gradle #3030

Closed ErwanLeroux closed 11 months ago

ErwanLeroux commented 1 year ago

Hello, here is a diff after running rewrite with the config

rewrite{    
    activeRecipe("org.openrewrite.java.format.Spaces")
}

As you can see, it removed spaces all over the place, breaking gradle. It also affected several other .gradle files. Did I missed something ?

Index: build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/build.gradle b/build.gradle
--- a/build.gradle  (revision 15ef9939704ac98beddca0de9b11012e56e3311c)
+++ b/build.gradle  (date 1679772863591)
@@ -38,8 +38,8 @@
 configurations.configureEach {
     // Force le rafraichissement des dépendances -SNAPSHOT
     resolutionStrategy.cacheChangingModulesFor 0, "seconds"
-    incoming.beforeResolve {
-        it.dependencies.each { dep ->
+    incoming.beforeResolve{
+        it.dependencies.each{ dep  ->
             if (dep.getVersion()?.endsWith("-SNAPSHOT")) {
                 if (dep.metaClass.respondsTo(dep, "setChanging", boolean)) {
                     dep.setChanging(true)
@@ -47,19 +47,19 @@
             }
         }
     }
-    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
+    resolutionStrategy.eachDependency{ DependencyResolveDetails details  ->
         // On laisse l'application décider de la version de spring boot même si aciv-commons fournit une autre version
         if (details.requested.group == "org.springframework.boot") {
-            details.useVersion libs.versions.springBoot.get()
+            details.useVersionlibs.versions.springBoot.get()
         }
     }
 }
-configurations {
-    [testFixturesCompileOnly, testCompileOnly].each { it.extendsFrom compileOnly }
-    [testFixturesAnnotationProcessor, testAnnotationProcessor].each { it.extendsFrom annotationProcessor }
-    [testFixturesImplementation].each { it.extendsFrom implementation }
+configurations{
+    [testFixturesCompileOnly, testCompileOnly].each{ it.extendsFromcompileOnly }
+    [testFixturesAnnotationProcessor, testAnnotationProcessor].each{ it.extendsFromannotationProcessor }
+    [testFixturesImplementation].each{ it.extendsFromimplementation }
 }
-dependencies {
+dependencies{
     compileOnly(libs.jsr305) // https://stackoverflow.com/a/58002092/550633

     annotationProcessor(libs.lombok)
@@ -70,9 +70,9 @@

-    rewrite platform(libs.rewriteBom)
+    rewriteplatform(libs.rewriteBom)
 }
-tasks.withType(JavaCompile).configureEach {
+tasks.withType(JavaCompile).configureEach{
     configure(options) {
         // Affiche les warning sur les objets dépréciés et les opérations 'unchecked or unsafe '
         options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
@@ -83,14 +83,14 @@
  * N'utilisez pas le filtrage avec les fichiers binaires, images, certificats, etc...
  * Pour ces filtres vous devez utiliser @placeholder@ au lieu de ${placeholder} exemple conf-example.properties
  **/
-processResources {
+processResources{
     //noinspection UnnecessaryQualifiedReference
-    filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [
+    filterorg.apache.tools.ant.filters.ReplaceTokens, tokens: [
             "application.version": project.property("version"),
             "application.name"   : project.name
-    ]
+            ]
 }
-gitProperties {
+gitProperties{
     keys = ['git.branch', 'git.commit.time', 'git.commit.message.full', 'git.commit.id']
     dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
     dateFormatTimeZone = "Europe/Paris"
@@ -102,30 +102,30 @@
 //
 // -------------------------------------------------------------------------------------------------

-distributions {
-    trm {
+distributions{
+    trm{
         getDistributionBaseName().set('trm')
-        contents {
+        contents{
             dirMode = 0750
             from('src/dist/') {
-                exclude '**/*.sh'
-                into '/'
+                exclude'**/*.sh'
+                into'/'
             }
             from('src/dist') {
-                include '**/*.sh'
-                filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [
+                include'**/*.sh'
+                filterorg.apache.tools.ant.filters.ReplaceTokens, tokens: [
                         "application.version": project.property("version"),
                         "application.name"   : project.name
-                ]
+                        ]
                 filteringCharset = 'UTF-8'
-                into '/'
+                into'/'
             }
             from(bootJar) {
-                into '/appli/trm/comp/java/trm/'
-                include '*.jar'
+                into'/appli/trm/comp/java/trm/'
+                include'*.jar'
             }
         }
     }
@@ -143,37 +143,37 @@
 /**
  * Écriture des rapports de test en html et non xml
  */
-test {
+test{
     useJUnitPlatform()
-    systemProperty 'user.country', 'FR'
-    systemProperty 'user.language', 'fr'
+    systemProperty'user.country', 'FR'
+    systemProperty'user.language', 'fr'
     minHeapSize = "128m"
     maxHeapSize = "1g"
-    jvmArgs "-XX:MaxMetaspaceSize=256m"
-    reports {
+    jvmArgs"-XX:MaxMetaspaceSize=256m"
+    reports{
         junitXml.required = true
     }
-    finalizedBy jacocoTestReport
+    finalizedByjacocoTestReport
 }

 /**
  * Génération du rapport jacoco test coverage
  *
  */
-jacocoTestReport {
-    reports {
+jacocoTestReport{
+    reports{
         xml.required = true
         csv.required = false
-        xml.destination file("${buildDir}/jacoco/reports/xml/jacocoTestReport.xml")
-        html.destination file("${buildDir}/jacoco/reports/html")
+        xml.destinationfile("${buildDir}/jacoco/reports/xml/jacocoTestReport.xml")
+        html.destinationfile("${buildDir}/jacoco/reports/html")
     }
 }
 tasks.sonarqube.dependsOn(jacocoTestReport)

 //https://docs.openrewrite.org/reference/gradle-plugin-configuration

     exclusion(

@@ -185,7 +185,7 @@
 }
 // rewriteDryRun can be used as a "gate" in a continuous integration environment by failing the build
 // if rewriteDryRun detects changes to be made and failOnDryRunResults = true
-tasks.named("check").configure {
+tasks.named("check").configure{
     dependsOn(tasks.named("rewriteDryRun"))
 }
 tasks.named("wrapper") {
knutwannheden commented 11 months ago

Fixed by https://github.com/openrewrite/rewrite/commit/a60b83a92c789ee838a0caed02ca74774141930b