diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt index f08d500f13..804b37ce2c 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt @@ -14,10 +14,10 @@ class NoSemicolonsRule : Rule("no-semi") { emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit) { if (node is LeafPsiElement && node.textMatches(";") && !node.isPartOfString() && !node.isPartOf(KtEnumEntry::class)) { - val nextLeaf = PsiTreeUtil.nextLeaf(node) + val nextLeaf = PsiTreeUtil.nextLeaf(node, true) if (nextLeaf == null /* eof */ || (nextLeaf is PsiWhiteSpace && (nextLeaf.text.contains("\n") || - PsiTreeUtil.nextLeaf(nextLeaf) == null /* \s+ and then eof */)) + PsiTreeUtil.nextLeaf(nextLeaf, true) == null /* \s+ and then eof */)) ) { emit(node.startOffset, "Unnecessary semicolon", true) if (autoCorrect) { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCommaRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCommaRule.kt index f2a867c445..fa0f2f361c 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCommaRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCommaRule.kt @@ -11,7 +11,7 @@ class SpacingAroundCommaRule : Rule("comma-spacing") { override fun visit(node: ASTNode, autoCorrect: Boolean, emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit) { - if (node is LeafPsiElement && (node.textMatches(",") || node.textMatches(";")) && !node.isPartOfString() && + if (node is LeafPsiElement && node.textMatches(",") && !node.isPartOfString() && PsiTreeUtil.nextLeaf(node) !is PsiWhiteSpace) { emit(node.startOffset + 1, "Missing spacing after \"${node.text}\"", true) if (autoCorrect) { diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt index 4d4ab29ea6..923320e926 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRuleTest.kt @@ -1,8 +1,8 @@ package com.github.shyiko.ktlint.ruleset.standard import com.github.shyiko.ktlint.core.LintError -import com.github.shyiko.ktlint.test.lint import com.github.shyiko.ktlint.test.format +import com.github.shyiko.ktlint.test.lint import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.Test @@ -12,6 +12,8 @@ class NoSemicolonsRuleTest { fun testLint() { assertThat(NoSemicolonsRule().lint( """ + package a.b.c; + fun main() { fun name() { a(); return b } println(";") @@ -19,7 +21,8 @@ class NoSemicolonsRuleTest { } """.trimIndent() )).isEqualTo(listOf( - LintError(4, 14, "no-semi", "Unnecessary semicolon") + LintError(1, 14, "no-semi", "Unnecessary semicolon"), + LintError(6, 14, "no-semi", "Unnecessary semicolon") )) }