se.vandmo.textchecker.maven.fixers.RemoveTrailingWhitespaceOnNonBlankLines Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of text-checker-maven-plugin Show documentation
Show all versions of text-checker-maven-plugin Show documentation
Maven plugin that checks that text files adheres to certain rules.
package se.vandmo.textchecker.maven.fixers;
import static se.vandmo.textchecker.maven.rules.NoTrailingWhitespaceOnNonBlankLines.ENDS_WITH_WHITESPACE;
import static se.vandmo.textchecker.maven.rules.NoTrailingWhitespaceOnNonBlankLines.isOk;
import java.util.regex.Matcher;
import se.vandmo.textchecker.maven.Content;
import se.vandmo.textchecker.maven.ContentType;
import se.vandmo.textchecker.maven.Fixer;
public final class RemoveTrailingWhitespaceOnNonBlankLines implements Fixer {
@Override
public void fix(Content content) {
content.modifyLines((line) -> {
return possiblyFixLine(line, content.type());
});
}
private String possiblyFixLine(String line, ContentType contentType) {
if (isOk(line, contentType)) {
return line;
}
Matcher matcher = ENDS_WITH_WHITESPACE.matcher(line);
if (!matcher.matches()) {
return line;
}
return matcher.group("beforetrailing");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy