Skip to content

Commit

Permalink
Fix detecting blank line after object header
Browse files Browse the repository at this point in the history
  • Loading branch information
panpeter committed Jul 14, 2022
1 parent f457cd4 commit c8ed2b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ class NoBlankNewLineAfterClassHeader(config: Config) : Rule(config) {
val whiteSpaceAfterLBrace = lBrace.nextSibling as? PsiWhiteSpace ?: return

if (whiteSpaceAfterLBrace.text.count { it == '\n' } > 1) {
val klass = classBody.parent as KtClass
val codeSmell = CodeSmell(
issue = issue,
entity = Entity.from(whiteSpaceAfterLBrace),
message = "Class ${klass.name} has blank line after the header",
message = "Unnecessary blank line after the header",
)
report(codeSmell)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ internal class NoBlankNewLineAfterClassHeaderTest(private val env: KotlinCoreEnv
findings shouldHaveSize 1
}

@Test
fun `reports blank line after object header`() {
val code = """
object A {
val b = true
}
"""
val rule = NoBlankNewLineAfterClassHeader(Config.empty)
val findings = rule.compileAndLintWithContext(env, code)
findings shouldHaveSize 1
}

@Test
fun `doesn't report blank line after class header`() {
val code = """
Expand Down

0 comments on commit c8ed2b6

Please sign in to comment.