Skip to content

Commit

Permalink
Fix NPE in NoConsecutiveBlankLinesRule.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapchicoma committed Mar 8, 2021
1 parent eecd43d commit 44418ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement

class NoConsecutiveBlankLinesRule : Rule("no-consecutive-blank-lines") {
public class NoConsecutiveBlankLinesRule : Rule("no-consecutive-blank-lines") {

override fun visit(
node: ASTNode,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
) {
if (node is PsiWhiteSpace) {
if (node is PsiWhiteSpace &&
node.prevSibling != null
) {
val text = node.getText()
val lfcount = text.count { it == '\n' }
if (lfcount < 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,20 @@ class NoConsecutiveBlankLinesRuleTest {
)
).isEmpty()
}

@Test
fun `should not raise NPE on linting Kotlin script file`() {
assertThat(
NoConsecutiveBlankLinesRule().lint(
"""
import java.net.URI
plugins {
`java-library`
}
""".trimIndent(),
script = true
)
).isEmpty()
}
}

0 comments on commit 44418ef

Please sign in to comment.