Repository: analysis-dev/diktat (kotlin)

Issue:
`KotlinParseException` in [STRING_CONCATENATION]
## Describe the bug
```kotlin
fun foo() {
    "File is" + if (fileInfo.isExecutable) "regular" else "executable"
}
```

```
org.cqfn.diktat.ruleset.utils.KotlinParseException: Text is not valid: [""Click to mark file " + if (fileInfo.isExecutable) "regular" else "executable""
```

## Observed behavior
Diktat doesn't support concatenation of string and `if` expression

## Environment information
* diktat version: 1.0.0-rc.3

Pull request description:
### What's done:
* fixed if expression in rule
closes #1076 
closes #1141

Patch:
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt
index 4cfb720d9e..0fb79e3ef3 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt
@@ -15,10 +15,9 @@ import org.jetbrains.kotlin.psi.KtBinaryExpression
 import org.jetbrains.kotlin.psi.KtCallExpression
 import org.jetbrains.kotlin.psi.KtConstantExpression
 import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
-import org.jetbrains.kotlin.psi.KtOperationExpression
+import org.jetbrains.kotlin.psi.KtExpression
 import org.jetbrains.kotlin.psi.KtParenthesizedExpression
 import org.jetbrains.kotlin.psi.KtReferenceExpression
-import org.jetbrains.kotlin.psi.KtSafeQualifiedExpression
 import org.jetbrains.kotlin.psi.KtStringTemplateExpression
 
 /**
@@ -154,13 +153,14 @@ class StringConcatenationRule(configRules: List<RulesConfig>) : DiktatRule(
             // =========== "a " + "b" -> "a b"
             val rvalueTextNew = rvalueText?.trim('"')
             return "$lvalueText$rvalueTextNew"
-        } else if (binaryExpressionPsi.isRvalueCallExpression() || binaryExpressionPsi.isRvalueDotQualifiedExpression() ||
-                binaryExpressionPsi.isRvalueOperation() || binaryExpressionPsi.isRvalueSafeQualifiedExpression()) {
+        } else if (binaryExpressionPsi.isRvalueCallExpression()) {
             // ===========  "a " + foo() -> "a ${foo()}}"
             return "$lvalueText\${$rvalueText}"
         } else if (binaryExpressionPsi.isRvalueReferenceExpression()) {
             // ===========  "a " + b -> "a $b"
             return "$lvalueText$$rvalueText"
+        } else if (!binaryExpressionPsi.isRvalueParenthesized() && binaryExpressionPsi.isRvalueExpression()) {
+            return "$lvalueText\${$rvalueText}"
         } else if (binaryExpressionPsi.isRvalueParenthesized()) {
             val binExpression = binaryExpressionPsi.right?.children?.first()
             if (binExpression is KtBinaryExpression) {
@@ -198,15 +198,9 @@ class StringConcatenationRule(configRules: List<RulesConfig>) : DiktatRule(
     private fun KtBinaryExpression.isRvalueReferenceExpression() =
             this.right is KtReferenceExpression
 
-    private fun KtBinaryExpression.isRvalueDotQualifiedExpression() =
-            this.right is KtDotQualifiedExpression
-
     private fun KtBinaryExpression.isRvalueParenthesized() =
             this.right is KtParenthesizedExpression
 
-    private fun KtBinaryExpression.isRvalueOperation() =
-            this.right is KtOperationExpression
-
     private fun KtBinaryExpression.isLvalueDotQualifiedExpression() =
             this.left is KtDotQualifiedExpression
 
@@ -219,6 +213,6 @@ class StringConcatenationRule(configRules: List<RulesConfig>) : DiktatRule(
     private fun KtBinaryExpression.isLvalueConstantExpression() =
             this.left is KtConstantExpression
 
-    private fun KtBinaryExpression.isRvalueSafeQualifiedExpression() =
-            this.right is KtSafeQualifiedExpression
+    private fun KtBinaryExpression.isRvalueExpression() =
+            this.right is KtExpression
 }


Test patch:
diff --git a/diktat-rules/src/test/resources/test/paragraph3/string_concatenation/StringConcatenationExpected.kt b/diktat-rules/src/test/resources/test/paragraph3/string_concatenation/StringConcatenationExpected.kt
index 80d319ae76..bd80f5e585 100644
--- a/diktat-rules/src/test/resources/test/paragraph3/string_concatenation/StringConcatenationExpected.kt
+++ b/diktat-rules/src/test/resources/test/paragraph3/string_concatenation/StringConcatenationExpected.kt
@@ -32,4 +32,5 @@ val myTest21 = "${x} string"
 val myTest22 = "string${foo()}"
 val myTest23 = x.toString() + foo()
 val myTest24 = foo() + "string"
-val myTest25 = "String ${valueStr?.value}"
\ No newline at end of file
+val myTest25 = "String ${valueStr?.value}"
+val myTest26 = "my string ${if (true) "1" else "2"}"
\ No newline at end of file
diff --git a/diktat-rules/src/test/resources/test/paragraph3/string_concatenation/StringConcatenationTest.kt b/diktat-rules/src/test/resources/test/paragraph3/string_concatenation/StringConcatenationTest.kt
index 8c49d00fdb..3cb4bd17fe 100644
--- a/diktat-rules/src/test/resources/test/paragraph3/string_concatenation/StringConcatenationTest.kt
+++ b/diktat-rules/src/test/resources/test/paragraph3/string_concatenation/StringConcatenationTest.kt
@@ -33,3 +33,4 @@ val myTest22 = "string" + foo()
 val myTest23 = x.toString() + foo()
 val myTest24 = foo() + "string"
 val myTest25 = "String " + valueStr?.value
+val myTest26 = "my string " + if (true) "1" else "2"