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..7de5d18eb0 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 @@ -22,6 +22,7 @@ import org.cqfn.diktat.ruleset.utils.isSingleLineIfElse import org.cqfn.diktat.ruleset.utils.leaveOnlyOneNewLine import com.pinterest.ktlint.core.ast.ElementType.ANDAND +import com.pinterest.ktlint.core.ast.ElementType.ARRAY_ACCESS_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.ARROW import com.pinterest.ktlint.core.ast.ElementType.BINARY_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.BLOCK @@ -461,7 +462,7 @@ class NewlinesRule(configRules: List) : DiktatRule( if (psi.children.isNotEmpty() && !psi.isFirstChildElementType(DOT_QUALIFIED_EXPRESSION) && !psi.isFirstChildElementType(SAFE_ACCESS_EXPRESSION)) { - val firstChild = psi.firstChild + val firstChild = if (psi.isFirstChildElementType(ARRAY_ACCESS_EXPRESSION)) psi.firstChild.firstChild else psi.firstChild if (firstChild.isFirstChildElementType(DOT_QUALIFIED_EXPRESSION) || firstChild.isFirstChildElementType(SAFE_ACCESS_EXPRESSION)) { getOrderedCallExpressions(firstChild.firstChild, result) 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..bece38b5b9 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,18 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) { ) } + @Test + @Tag(WarningNames.WRONG_NEWLINES) + fun `should warn for array access expression`() { + lintMethod( + """ + |fun bar(): String { + | val a = it.responseBody!!.name + |} + """.trimMargin() + ) + } + @Test @Tag(WarningNames.WRONG_NEWLINES) fun `long argument list should be split into several lines - positive example`() {