Skip to content

Commit

Permalink
Fixed #59 - Semicolon at end of package declaration not reported, dif…
Browse files Browse the repository at this point in the history
…ferent error instead
  • Loading branch information
shyiko committed Jun 19, 2017
1 parent 650b762 commit 29effae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -12,14 +12,17 @@ class NoSemicolonsRuleTest {
fun testLint() {
assertThat(NoSemicolonsRule().lint(
"""
package a.b.c;
fun main() {
fun name() { a(); return b }
println(";")
println();
}
""".trimIndent()
)).isEqualTo(listOf(
LintError(4, 14, "no-semi", "Unnecessary semicolon")
LintError(1, 14, "no-semi", "Unnecessary semicolon"),
LintError(6, 14, "no-semi", "Unnecessary semicolon")
))
}

Expand Down

0 comments on commit 29effae

Please sign in to comment.