Skip to content

Commit

Permalink
Fix: formatter no longer adds whitespace to blank lines (#800)
Browse files Browse the repository at this point in the history
Don't add whitespace to blank lines inside comments. Fixes #799
  • Loading branch information
dansanduleac authored and bulldozer-bot[bot] committed Sep 11, 2019
1 parent ee8012d commit 316aef3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-800.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: 'Don''t add whitespace to blank lines inside comments. Fixes #799'
links:
- https://github.com/palantir/gradle-baseline/pull/800
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ public void apply(Project project) {
java.removeUnusedImports();
// use empty string to specify one group for all non-static imports
java.importOrder("");
java.trimTrailingWhitespace();

if (eclipseFormattingEnabled(project)) {
java.eclipse().configFile(project.file(eclipseXml.toString()));
}

java.trimTrailingWhitespace();
});

// necessary because SpotlessPlugin creates tasks in an afterEvaluate block
Expand All @@ -65,7 +66,7 @@ public void apply(Project project) {
Task spotlessJava = project.getTasks().getByName("spotlessJava");
Task spotlessApply = project.getTasks().getByName("spotlessApply");
if (eclipseFormattingEnabled(project) && !Files.exists(eclipseXml)) {
spotlessJava.dependsOn(project.getTasks().findByPath(":baselineUpdateConfig"));
spotlessJava.dependsOn(":baselineUpdateConfig");
}
formatTask.dependsOn(spotlessApply);
project.getTasks().withType(JavaCompile.class).configureEach(spotlessJava::mustRunAfter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.palantir.baseline

import com.google.common.io.Resources
import java.nio.charset.Charset
import org.apache.commons.io.FileUtils
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome
Expand Down Expand Up @@ -152,4 +154,23 @@ class BaselineFormatIntegrationTest extends AbstractPluginTest {
BuildResult result = with('spotlessJavaCheck').build()
result.task(":spotlessJava").outcome == TaskOutcome.SUCCESS
}

def 'eclipse format trims blank lines in block or javadoc comment'() {
when:
buildFile << standardBuildFile
file('gradle.properties') << """
com.palantir.baseline-format.eclipse=true
""".stripIndent()
file('src/main/java/test/Test.java').text = resourceAsString("blank-lines-in-comments.java")

then:
BuildResult result = with('format').build()
result.task(":spotlessJavaApply").outcome == TaskOutcome.SUCCESS
file('src/main/java/test/Test.java').text == resourceAsString("blank-lines-in-comments-fixed.java")
}

private String resourceAsString(String fileName) {
Resources.toString(Resources.getResource(this.class, fileName), Charset.defaultCharset())
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test;

public class Test {
/**
Docstring that looks like a list:
1. hey
2. there
with blank line.
*/
Void test() {
/*
Normal comment
with blank line.
*/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test;

public class Test {
/**
Docstring that looks like a list:
1. hey
2. there
with blank line.
*/
Void test() {
/*
Normal comment
with blank line.
*/
}
}

0 comments on commit 316aef3

Please sign in to comment.