Repository: analysis-dev/diktat (kotlin)

Issue:
`BLANK_LINE_BETWEEN_PROPERTIES` false positive when an `@Annotation` of a private property is followed with a single-line comment
Minimal repro:

```kotlin
class C {
    private val val0 = Regex("""\d+""")

    @Suppress("WRONG_NEWLINES")  // Trailing comment
    private val val1 = 42

    @Deprecated("Deprecation message")  // Trailing comment
    private val val2 = ""
}
```

## Environment information
* diktat version: 1.2.3

Pull request:
### What's done:
* fixed isFollowedByNewlineCheck

Closes #1496

Patch:
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
index bfe06c4c3e..2c89140e90 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt
@@ -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
 
 /**
@@ -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 {


Test patch:
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ClassLikeStructuresOrderRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ClassLikeStructuresOrderRuleWarnTest.kt
index 2d795bad41..415012b835 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ClassLikeStructuresOrderRuleWarnTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ClassLikeStructuresOrderRuleWarnTest.kt
@@ -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`() {