Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE in NewlinesRule: #1050

Merged
merged 8 commits into from
Sep 22, 2021
Merged
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 @@ -466,9 +467,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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,20 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) {
)
}

@Test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create fixer tests (where WRONG_NEWLINES is fixing the code in such case) to prove that you are right

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cheshiriks where are tests for fixers?

@Tag(WarningNames.WRONG_NEWLINES)
fun `should warn for array access expression`() {
lintMethod(
"""
|fun bar(): String {
| val a = list.responseBody!![0].
| name
|}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add positive scenarios (that will trigger warnings)

""".trimMargin(),
LintError(2, 35, ruleId, "$shouldBreakBefore .", true)
)
}

@Test
@Tag(WarningNames.WRONG_NEWLINES)
fun `long argument list should be split into several lines - positive example`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ fun goo() {
.map()
.filter()
.hre()

t.responseBody!![0]
.name
}

fun foo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ fun goo() {
x
.map()
.filter().hre()

t.responseBody!![0].
name
}

fun foo() {
Expand Down