Repository: cqfn/diKTat (kotlin)

Issue:
false positive finding for WRONG_WHITESPACE on gradle plugins block
The warning states:

> [WRONG_WHITESPACE] incorrect usage of whitespaces for code separation: version should have 1 space(s) before and 1 space(s) after, but has 0 space(s) after

for code in settings.gradle.kts:
```
plugins {
    id("com.gradle.enterprise") version("3.10.1") // this line
}
```
Maybe the rule can be adjusted/improved here.

Pull request description:
### What's done:
* Fixed logic
* Added test

This pull request closes #1313

Patch:
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt
index d4fbb097ef..c7df37c81b 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt
@@ -225,7 +225,7 @@ class WhiteSpaceRule(configRules: List<RulesConfig>) : DiktatRule(
                 .parent({ it.elementType == VALUE_ARGUMENT })
                 .let { it?.prevSibling { prevNode -> prevNode.elementType == COMMA } == null }
 
-            // If it is lambda, then we don't force it to be on newline or same line
+            // Handling this case: `foo({ it.bar() }, 2, 3)`
             if (numWhiteSpace != 0 && isFirstArgument) {
                 WRONG_WHITESPACE.warnAndFix(configRules, emitWarn, isFixMode, "there should be no whitespace before '{' of lambda" +
                     " inside argument list", node.startOffset, node) {
@@ -233,8 +233,11 @@ class WhiteSpaceRule(configRules: List<RulesConfig>) : DiktatRule(
                 }
             }
         } else if (prevNode.elementType !in keywordsWithSpaceAfter && numWhiteSpace != 1) {
-            WRONG_WHITESPACE.warnAndFix(configRules, emitWarn, isFixMode, "there should be a whitespace before '{'", node.startOffset, node) {
-                prevNode.leaveSingleWhiteSpace()
+            val hasOnlyWhiteSpaceBefore = whitespaceOrPrevNode.elementType == WHITE_SPACE && whitespaceOrPrevNode.textContains('\n')
+            if (!hasOnlyWhiteSpaceBefore) {
+                WRONG_WHITESPACE.warnAndFix(configRules, emitWarn, isFixMode, "there should be a whitespace before '{'", node.startOffset, node) {
+                    prevNode.leaveSingleWhiteSpace()
+                }
             }
         }
     }


Test patch:
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt
index 600f050db9..97fafa4b0d 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt
@@ -670,4 +670,18 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) {
             """.trimMargin()
         )
     }
+
+    @Test
+    @Tag(WarningNames.WRONG_WHITESPACE)
+    fun `should not trigger in braces on the beginning of the line`() {
+        lintMethod(
+            """
+                |val onClick: () -> Unit = remember {
+                |    {
+                |        /* do stuff */
+                |    }
+                |}
+            """.trimMargin()
+        )
+    }
 }