Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Renamed SemiColons to Semicolons
  • Loading branch information
jlbadano committed Nov 11, 2023
commit 5781dea7679fb5be6a652fe5d8aa4a9920dc47e8
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
*
* @author Jose Luis Badano
*/
public final class RemoveSemiColonsStep {
public final class RemoveSemicolonsStep {

private RemoveSemiColonsStep() {
private RemoveSemicolonsStep() {
// prevent instantiation
}

Expand All @@ -38,7 +38,7 @@ private RemoveSemiColonsStep() {
public static FormatterStep create() {
return FormatterStep.createLazy(NAME,
State::new,
RemoveSemiColonsStep.State::toFormatter);
RemoveSemicolonsStep.State::toFormatter);
}

private static final class State implements Serializable {
Expand All @@ -50,7 +50,7 @@ FormatterFunc toFormatter() {
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(removeSemiColon(line));
result.append(removeSemicolon(line));
result.append(System.lineSeparator());
}
return result.toString();
Expand All @@ -64,11 +64,11 @@ FormatterFunc toFormatter() {
* @param line the line to remove the semicolon from
* @return the line without the last semicolon
*/
private String removeSemiColon(String line) {
private String removeSemicolon(String line) {
// find last semicolon in a string a remove it
int lastSemiColon = line.lastIndexOf(";");
if (lastSemiColon != -1 && lastSemiColon == line.length() - 1) {
return line.substring(0, lastSemiColon);
int lastSemicolon = line.lastIndexOf(";");
if (lastSemicolon != -1 && lastSemicolon == line.length() - 1) {
return line.substring(0, lastSemicolon);
} else {
return line;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.diffplug.spotless.extra.EquoBasedStepBuilder;
import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep;
import com.diffplug.spotless.generic.LicenseHeaderStep;
import com.diffplug.spotless.groovy.RemoveSemiColonsStep;
import com.diffplug.spotless.groovy.RemoveSemicolonsStep;
import com.diffplug.spotless.java.ImportOrderStep;

public class GroovyExtension extends FormatExtension implements HasBuiltinDelimiterForLicense, JvmLang {
Expand Down Expand Up @@ -70,8 +70,8 @@ public void importOrder(String... importOrder) {
addStep(ImportOrderStep.forGroovy().createFrom(importOrder));
}

public void removeSemiColons() {
addStep(RemoveSemiColonsStep.create());
public void removeSemicolons() {
addStep(RemoveSemicolonsStep.create());
}

public void importOrderFile(Object importOrderFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import javax.inject.Inject;

import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep;
import com.diffplug.spotless.groovy.RemoveSemiColonsStep;
import com.diffplug.spotless.groovy.RemoveSemicolonsStep;
import com.diffplug.spotless.java.ImportOrderStep;

public class GroovyGradleExtension extends FormatExtension {
Expand All @@ -41,8 +41,8 @@ public void importOrderFile(Object importOrderFile) {
addStep(ImportOrderStep.forGroovy().createFrom(getProject().file(importOrderFile)));
}

public void removeSemiColons(String... arguments) {
addStep(RemoveSemiColonsStep.create());
public void removeSemicolons(String... arguments) {
addStep(RemoveSemicolonsStep.create());
}

public GroovyExtension.GrEclipseConfig greclipse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void excludeJavaWithCustomTarget() throws IOException {
}

@Test
void removeSemiColons() throws IOException {
void removeSemicolons() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'com.diffplug.spotless'",
Expand All @@ -98,18 +98,18 @@ void removeSemiColons() throws IOException {
"",
"spotless {",
" groovy {",
" removeSemiColons()",
" removeSemicolons()",
" }",
"}");

String withSemiColons = getTestResource("groovy/removesemicolons/GroovyCodeWithSemiColons.test");
String withoutSemiColons = getTestResource("groovy/removesemicolons/GroovyCodeWithSemiColonsFormatted.test");
String withSemicolons = getTestResource("groovy/removesemicolons/GroovyCodeWithSemicolons.test");
String withoutSemicolons = getTestResource("groovy/removesemicolons/GroovyCodeWithSemicolonsFormatted.test");

setFile("src/main/groovy/test.groovy").toContent(withSemiColons);
setFile("src/main/groovy/test.groovy").toContent(withSemicolons);

gradleRunner().withArguments("spotlessApply").build();

assertFile("src/main/groovy/test.groovy").hasContent(withoutSemiColons);
assertFile("src/main/groovy/test.groovy").hasContent(withoutSemicolons);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void addImportOrder(ImportOrder importOrder) {
addStepFactory(importOrder);
}

public void addRemoveSemiColons(RemoveSemiColons removeSemiColons) {
addStepFactory(removeSemiColons);
public void addRemoveSemicolons(RemoveSemicolons removeSemicolons) {
addStepFactory(removeSemicolons);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
package com.diffplug.spotless.maven.groovy;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.groovy.RemoveSemiColonsStep;
import com.diffplug.spotless.groovy.RemoveSemicolonsStep;
import com.diffplug.spotless.maven.FormatterStepConfig;
import com.diffplug.spotless.maven.FormatterStepFactory;

public class RemoveSemiColons implements FormatterStepFactory {
public class RemoveSemicolons implements FormatterStepFactory {

@Override
public FormatterStep newFormatterStep(FormatterStepConfig config) {
return RemoveSemiColonsStep.create();
return RemoveSemicolonsStep.create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@

import com.diffplug.spotless.maven.MavenIntegrationHarness;

class RemoveSemiColonsTest extends MavenIntegrationHarness {
class RemoveSemicolonsTest extends MavenIntegrationHarness {

@Test
void testRemoveSemiColonsString() throws Exception {
writePomWithGroovySteps("<removeSemiColons/>");
void testRemoveSemicolonsString() throws Exception {
writePomWithGroovySteps("<removeSemicolons/>");
runTest("Hello World;", "Hello World");
}

@Test
void testNotRemoveSemiColonsString() throws Exception {
writePomWithGroovySteps("<removeSemiColons/>");
void testNotRemoveSemicolonsString() throws Exception {
writePomWithGroovySteps("<removeSemicolons/>");
runTest("Hello;World", "Hello;World");
}

@Test
void testRemoveSemiColons() throws Exception {
writePomWithGroovySteps("<removeSemiColons/>");
void testRemoveSemicolons() throws Exception {
writePomWithGroovySteps("<removeSemicolons/>");

String path = "src/main/groovy/test.groovy";
setFile(path).toResource("groovy/removesemicolons/GroovyCodeWithSemiColons.test");
setFile(path).toResource("groovy/removesemicolons/GroovyCodeWithSemicolons.test");
mavenRunner().withArguments("spotless:apply").runNoError();
assertFile(path).sameAsResource("groovy/removesemicolons/GroovyCodeWithSemiColonsFormatted.test");
assertFile(path).sameAsResource("groovy/removesemicolons/GroovyCodeWithSemicolonsFormatted.test");

}

Expand Down