Repository: cqfn/diKTat (kotlin)

Issue:
NPE in NewlinesRule
Consider the following code:
```kotlin
fun foo() {
    val a = it.responseBody!![0].name
}
```
NPE:

```bash
[ERROR] 2021-09-06 18:22:12 Internal error has occurred in rule [newlines].
Please make an issue on this bug at https://github.com/cqfn/diKTat/. 
As a workaround you can disable these inspections in yml config: <[COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES]>.
java.lang.NullPointerException: astNode.treePrev must not be null 
at org.cqfn.diktat.ruleset.rules.chapter3.files.NewlinesRule.isNotValidCalls(NewlinesRule.kt:557)               
at org.cqfn.diktat.ruleset.rules.chapter3.files.NewlinesRule.isCallsChain(NewlinesRule.kt:532)
at org.cqfn.diktat.ruleset.rules.chapter3.files.NewlinesRule.handleOperatorWithLineBreakBefore(NewlinesRule.kt:186)         
at org.cqfn.diktat.ruleset.rules.chapter3.files.NewlinesRule.logic(NewlinesRule.kt:126)
at org.cqfn.diktat.ruleset.rules.DiktatRule.visit(DiktatRule.kt:50)
at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:271)
at com.pinterest.ktlint.core.KtLint$format$1.invoke(KtLint.kt:23)                  
```

Pull request:
### What's done:
* fixed bug in NewlinesRule
Closes #1047

Patch:
diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt
index 9344ffd263..fd62a17688 100644
--- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt
+++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt
@@ -466,9 +466,6 @@ class NewlinesRule(configRules: List<RulesConfig>) : DiktatRule(
                     firstChild.isFirstChildElementType(SAFE_ACCESS_EXPRESSION)) {
                 getOrderedCallExpressions(firstChild.firstChild, result)
             }
-            if (firstChild.isFirstChildElementType(POSTFIX_EXPRESSION)) {
-                result.add(firstChild.node)
-            }
             result.add(firstChild.node
                 .siblings(true)
                 .dropWhile { it.elementType in dropChainValues }


Test patch:
diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt
index 95a505b829..25880d8bef 100644
--- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt
+++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt
@@ -527,6 +527,20 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) {
         )
     }
 
+    @Test
+    @Tag(WarningNames.WRONG_NEWLINES)
+    fun `should warn for array access expression`() {
+        lintMethod(
+            """
+                    |fun bar(): String {
+                    |    val a = list.responseBody!![0].
+                    |    name
+                    |}
+            """.trimMargin(),
+            LintError(2, 35, ruleId, "$shouldBreakBefore .", true)
+        )
+    }
+
     @Test
     @Tag(WarningNames.WRONG_NEWLINES)
     fun `long argument list should be split into several lines - positive example`() {
diff --git a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt
index 6d0f90b556..a9cba895f8 100644
--- a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt
+++ b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt
@@ -28,6 +28,9 @@ fun goo() {
             .map()
             .filter()
 .hre()
+
+    t.responseBody!![0]
+.name
 }
 
 fun foo() {
diff --git a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt
index 16e8490f85..a21af042f6 100644
--- a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt
+++ b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt
@@ -22,6 +22,9 @@ fun goo() {
     x
             .map()
             .filter().hre()
+
+    t.responseBody!![0].
+    name
 }
 
 fun foo() {