Skip to content

Commit

Permalink
BLANK_LINE_BETWEEN_PROPERTIES false positive (#1608)
Browse files Browse the repository at this point in the history
* BLANK_LINE_BETWEEN_PROPERTIES false positive

### What's done:
* fixed isFollowedByNewlineCheck

Closes #1496
  • Loading branch information
Cheshiriks authored Feb 3, 2023
1 parent 7954882 commit 22c1cdb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ fun ASTNode.isEol() = parent({ it.treeNext != null }, false)?.isFollowedByNewlin
*/
fun ASTNode.isFollowedByNewline() =
parent({ it.treeNext != null }, strict = false)?.let {
it.treeNext.elementType == WHITE_SPACE && it.treeNext.text.contains("\n")
val probablyWhitespace = it.treeNext
it.isFollowedByNewlineCheck() ||
(probablyWhitespace.elementType == WHITE_SPACE && probablyWhitespace.treeNext.run {
elementType == EOL_COMMENT && isFollowedByNewlineCheck()
})
} ?: false

/**
Expand Down Expand Up @@ -902,6 +906,9 @@ fun ASTNode.isBooleanExpression(): Boolean =
fun PsiElement.isLongStringTemplateEntry(): Boolean =
node.elementType == LONG_STRING_TEMPLATE_ENTRY

private fun ASTNode.isFollowedByNewlineCheck() =
this.treeNext.elementType == WHITE_SPACE && this.treeNext.text.contains("\n")

private fun <T> Sequence<T>.takeWhileInclusive(pred: (T) -> Boolean): Sequence<T> {
var shouldContinue = true
return takeWhile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ class ClassLikeStructuresOrderRuleWarnTest : LintTestBase(::ClassLikeStructuresO
)
}

@Test
@Tag(WarningNames.BLANK_LINE_BETWEEN_PROPERTIES)
fun `a single-line comment after annotation`() {
lintMethod(
"""class Example {
| private val val0 = Regex(""${'"'}\d+""${'"'})
|
| @Deprecated("Deprecation message") // Trailing comment
| private val val2 = ""
|}
""".trimMargin()
)
}

@Test
@Tag(WarningNames.BLANK_LINE_BETWEEN_PROPERTIES)
fun `should allow blank lines around properties with custom getters and setters - positive example`() {
Expand Down

0 comments on commit 22c1cdb

Please sign in to comment.