Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLANK_LINE_BETWEEN_PROPERTIES false positive #1608

Merged
merged 2 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ 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")
it.isFollowedByNewlineCheck() ||
(it.treeNext.elementType == WHITE_SPACE && it.treeNext.treeNext.elementType == EOL_COMMENT && it.treeNext.treeNext.isFollowedByNewlineCheck())
0x6675636b796f75676974687562 marked this conversation as resolved.
Show resolved Hide resolved
} ?: false

/**
Expand Down Expand Up @@ -902,6 +903,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