Skip to content

Commit

Permalink
Make RemoveSemicolonsStep round-trippable
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Feb 1, 2024
1 parent f5e3dd3 commit adb6ec7
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 DiffPlug
* Copyright 2023-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,23 +21,25 @@

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.RoundedStep;

/**
* Removes all semicolons from the end of lines.
*
* @author Jose Luis Badano
*/
public final class RemoveSemicolonsStep {
public final class RemoveSemicolonsStep implements RoundedStep {
private static final long serialVersionUID = 1L;
private static final String NAME = "Remove unnecessary semicolons";

private RemoveSemicolonsStep() {
// do not instantiate
}

public static FormatterStep create() {
return FormatterStep.createLazy(NAME,
State::new,
RemoveSemicolonsStep.State::toFormatter);
return FormatterStep.create(NAME,
new State(),
State::toFormatter);
}

private static final class State implements Serializable {
Expand All @@ -64,7 +66,7 @@ FormatterFunc toFormatter() {
* @return the line without the last semicolon
*/
private String removeSemicolon(String line) {
// find last semicolon in a string a remove it
// Find the last semicolon in a string and remove it.
int lastSemicolon = line.lastIndexOf(";");
if (lastSemicolon != -1 && lastSemicolon == line.length() - 1) {
return line.substring(0, lastSemicolon);
Expand Down

0 comments on commit adb6ec7

Please sign in to comment.