Create a gist now

Instantly share code, notes, and snippets.

package com.wealthfront.test.filesetcheck;
import java.io.File;
import java.util.List;
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.FileContents;
import com.puppycrawl.tools.checkstyle.api.FileText;
public class MultipleEmptyLinesFileSetCheck extends AbstractFileSetCheck {
@Override
protected void processFiltered(File file, List<String> lines) throws CheckstyleException {
if (file.getPath().endsWith(".java")) {
final int countLessOne = lines.size() - 1;
final FileContents contents = new FileContents(FileText.fromLines(file, lines));
for (int lineNumber = 0; lineNumber < countLessOne; lineNumber++) {
if (contents.lineIsBlank(lineNumber) && contents.lineIsBlank(lineNumber+1)) {
log(lineNumber+2, "Multiple empty lines.");
while (lineNumber < countLessOne && contents.lineIsBlank(lineNumber)) {
lineNumber++;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment