Skip to content

Instantly share code, notes, and snippets.

@leeym
Created October 26, 2016 09:18
Show Gist options
  • Save leeym/4047692b80e30cd33dc58071034438c5 to your computer and use it in GitHub Desktop.
Save leeym/4047692b80e30cd33dc58071034438c5 to your computer and use it in GitHub Desktop.
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