Skip to content

Commit

Permalink
NPE in NewlinesRule:
Browse files Browse the repository at this point in the history
### What's done:
* fixed bug in NewlinesRule
Closes #1047
  • Loading branch information
Cheshiriks committed Sep 10, 2021
1 parent 91d5535 commit 2dfeaab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -461,7 +462,7 @@ class NewlinesRule(configRules: List<RulesConfig>) : 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`() {
Expand Down

0 comments on commit 2dfeaab

Please sign in to comment.