Skip to content

Commit

Permalink
Fixed no-consecutive-blank-lines formatting at the end of file (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
shyiko committed Nov 28, 2017
1 parent ea3c6fb commit 61375fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class NoConsecutiveBlankLinesRule : Rule("no-consecutive-blank-lines") {
if (split.size > 3 || split.size == 3 && PsiTreeUtil.nextLeaf(node) == null /* eof */) {
emit(node.startOffset + split[0].length + split[1].length + 2, "Needless blank line(s)", true)
if (autoCorrect) {
(node as LeafPsiElement).rawReplaceWithText("${split.first()}\n\n${split.last()}")
(node as LeafPsiElement)
.rawReplaceWithText("${split.first()}\n${if (split.size > 3) "\n" else ""}${split.last()}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,23 @@ class NoConsecutiveBlankLinesRuleTest {
"""
)
}

@Test
fun testFormatAtTheEndOfFile() {
assertThat(NoConsecutiveBlankLinesRule().format(
"""
fun main() {
}
""",
script = true
)).isEqualTo(
"""
fun main() {
}
"""
)
}
}

0 comments on commit 61375fd

Please # to comment.