Skip to content

Commit

Permalink
Merge pull request #1100 from Tapchicoma/tapchicoma/fix-npe
Browse files Browse the repository at this point in the history
Fix NPE in NoConsecutiveBlankLinesRule.
  • Loading branch information
Tapchicoma authored Mar 8, 2021
2 parents eecd43d + 44418ef commit 338a9a4
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 338a9a4

Please sign in to comment.