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

Don't separate fully-qualified as a regular dot qualified expression #1411

Merged
merged 8 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,15 @@ class NewlinesRule(configRules: List<RulesConfig>) : DiktatRule(
isDotQuaOrSafeAccessOrPostfixExpression(it) && it.elementType != POSTFIX_EXPRESSION
}.reversed()
if (listDot.size > 3) {
val without = listDot.filterNot {
val without = listDot.filterIndexed { index, it ->
val whiteSpaceBeforeDotOrSafeAccess = it.findChildByType(DOT)?.treePrev ?: it.findChildByType(SAFE_ACCESS)?.treePrev
whiteSpaceBeforeDotOrSafeAccess?.elementType == WHITE_SPACE && whiteSpaceBeforeDotOrSafeAccess.text.lines().size > 1
val firstElem = it.firstChildNode
(firstElem.textContains('(') || firstElem.textContains('{')) && (index > 0) && ((whiteSpaceBeforeDotOrSafeAccess?.elementType != WHITE_SPACE) ||
(whiteSpaceBeforeDotOrSafeAccess.elementType != WHITE_SPACE && !whiteSpaceBeforeDotOrSafeAccess.textContains('\n')))
Arrgentum marked this conversation as resolved.
Show resolved Hide resolved
}
if (without.size > 1 || (without.size == 1 && without[0] != listDot[0])) {
WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode, "should be split before second and other dot/safe access", node.startOffset, node) {
if (without.isNotEmpty()) {
WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode, "should be split before second and other dot/safe access after first call expression",
node.startOffset, node) {
fixDotQualifiedExpression(listDot)
}
}
Expand Down Expand Up @@ -193,7 +196,8 @@ class NewlinesRule(configRules: List<RulesConfig>) : DiktatRule(
list.forEachIndexed { index, astNode ->
val dotNode = astNode.getFirstChildWithType(DOT) ?: astNode.getFirstChildWithType(SAFE_ACCESS)
val nodeBeforeDot = dotNode?.treePrev
if (index > 0) {
val firstElem = astNode.firstChildNode
if (index > 0 && (firstElem.textContains('(') || firstElem.textContains('{'))) {
Arrgentum marked this conversation as resolved.
Show resolved Hide resolved
astNode.appendNewlineMergingWhiteSpace(nodeBeforeDot, dotNode)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) {
mapOf("maxCallsInOneLine" to "1"))
)
private val ruleId = "$DIKTAT_RULE_SET_ID:${NewlinesRule.NAME_ID}"
private val dotQuaOrSafeAccessOrPostfixExpression = "${WRONG_NEWLINES.warnText()} should be split before second and other dot/safe access"
private val dotQuaOrSafeAccessOrPostfixExpression = "${WRONG_NEWLINES.warnText()} should be split before second and other dot/safe access after first call expression"
Arrgentum marked this conversation as resolved.
Show resolved Hide resolved
private val shouldBreakAfter = "${WRONG_NEWLINES.warnText()} should break a line after and not before"
private val shouldBreakBefore = "${WRONG_NEWLINES.warnText()} should break a line before and not after"
private val functionalStyleWarn = "${WRONG_NEWLINES.warnText()} should follow functional style at"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package test.paragraph3.newlines

val elem1 = firstArgumentDot?.secondArgumentDot
val elem1 = firstArgumentDot()?.secondArgumentDot
?.thirdArgumentDot
?.fourthArgumentDot
?.fifthArgumentDot
?.sixthArgumentDot


val elem2 = firstArgumentDot?.secondArgumentDot
val elem2 = firstArgumentDot?.secondArgumentDot()
?.thirdArgumentDot
?.fourthArgumentDot
?.fifthArgumentDot
?.sixthArgumentDot


val elem3 = firstArgumentDot?.secondArgumentDot
?.thirdArgumentDot
val elem3 = firstArgumentDot?.secondArgumentDot?.thirdArgumentDot()
?.fourthArgumentDot
?.fifthArgumentDot
?.sixthArgumentDot
Expand All @@ -24,70 +23,79 @@ val elem3 = firstArgumentDot?.secondArgumentDot
val elem4 = firstArgumentDot?.secondArgumentDot?.thirdArgumentDot + firstArgumentDot?.secondArgumentDot?.thirdArgumentDot?.fourthArgumentDot


val elem5 = firstArgumentDot!!.secondArgumentDot!!
val elem5 = firstArgumentDot()!!.secondArgumentDot()!!
.thirdArgumentDot!!
.fourthArgumentDot!!
.fifthArgumentDot!!
.sixthArgumentDot
.sixthArgumentDot()


val elem6 = firstArgumentDot!!.secondArgumentDot!!
.thirdArgumentDot!!
val elem6 = firstArgumentDot!!.secondArgumentDot!!.thirdArgumentDot()!!
.fourthArgumentDot!!
.fifthArgumentDot!!
.fifthArgumentDot()!!
.sixthArgumentDot


val elem7 = firstArgumentDot!!.secondArgumentDot!!
val elem7 = firstArgumentDot!!.secondArgumentDot()!!
.thirdArgumentDot!!
.fourthArgumentDot!!
.fourthArgumentDot()!!
.fifthArgumentDot!!
.sixthArgumentDot


val elem8 = firstArgumentDot!!.secondArgumentDot!!.thirdArgumentDot + firstArgumentDot!!.secondArgumentDot!!.thirdArgumentDot!!.fourthArgumentDot
val elem8 = firstArgumentDot()!!.secondArgumentDot!!.thirdArgumentDot + firstArgumentDot!!.secondArgumentDot!!.thirdArgumentDot!!.fourthArgumentDot


val elem9 = firstArgumentDot.secondArgumentDot
.thirdArgumentDot
val elem9 = firstArgumentDot().secondArgumentDot
.thirdArgumentDot()
.fourthArgumentDot
.fifthArgumentDot
.sixthArgumentDot


val elem10 = firstArgumentDot.secondArgumentDot
val elem10 = firstArgumentDot.secondArgumentDot()
.thirdArgumentDot
.fourthArgumentDot
.fifthArgumentDot
.fifthArgumentDot()
.sixthArgumentDot


val elem11 = firstArgumentDot.secondArgumentDot
.thirdArgumentDot
val elem11 = firstArgumentDot.secondArgumentDot.thirdArgumentDot()
.fourthArgumentDot
.fifthArgumentDot
.sixthArgumentDot


val elem12 = firstArgumentDot.secondArgumentDot.thirdArgumentDot + firstArgumentDot.secondArgumentDot.thirdArgumentDot.fourthArgumentDot
val elem12 = firstArgumentDot.secondArgumentDot.thirdArgumentDot + firstArgumentDot.secondArgumentDot().thirdArgumentDot.fourthArgumentDot


val elem13 = firstArgumentDot!!.secondArgumentDot
?.thirdArgumentDot
val elem13 = firstArgumentDot!!.secondArgumentDot?.thirdArgumentDot()
.fourthArgumentDot!!
.fifthArgumentDot
.fifthArgumentDot()
?.sixthArgumentDot


val elem14 = firstArgumentDot.secondArgumentDot
?.thirdArgumentDot!!
val elem14 = firstArgumentDot.secondArgumentDot?.thirdArgumentDot()!!
.fourthArgumentDot
?.fifthArgumentDot
.sixthArgumentDot


val elem15 = firstArgumentDot?.secondArgumentDot!!
.thirdArgumentDot
.fourthArgumentDot
val elem15 = firstArgumentDot?.secondArgumentDot!!.thirdArgumentDot.fourthArgumentDot()
.fifthArgumentDot!!
.sixthArgumentDot


val elem16 = firstArgumentDot.secondArgumentDot.thirdArgumentDot.fourthArgumentDot.fifthArgumentDot.sixthArgumentDot


val elem17 = firstArgumentDot!!.secondArgumentDot.thirdArgumentDot!!.fourthArgumentDot.fifthArgumentDot!!.sixthArgumentDot


val elem18 = firstArgumentDot.secondArgumentDot?.thirdArgumentDot.fourthArgumentDot?.fifthArgumentDot.sixthArgumentDot


private val holder: java.util.concurrent.atomic.AtomicReference<T> = java.util.concurrent.atomic.AtomicReference(valueToStore)


private val holder: kotlin.native.concurrent.AtomicReference<T> = kotlin.native.concurrent.AtomicReference(valueToStore)
Original file line number Diff line number Diff line change
@@ -1,51 +1,66 @@
package test.paragraph3.newlines

val elem1 = firstArgumentDot?.secondArgumentDot?.thirdArgumentDot?.fourthArgumentDot?.fifthArgumentDot?.sixthArgumentDot
val elem1 = firstArgumentDot()?.secondArgumentDot?.thirdArgumentDot?.fourthArgumentDot?.fifthArgumentDot?.sixthArgumentDot


val elem2 = firstArgumentDot?.secondArgumentDot?.thirdArgumentDot
val elem2 = firstArgumentDot?.secondArgumentDot()?.thirdArgumentDot
?.fourthArgumentDot?.fifthArgumentDot?.sixthArgumentDot


val elem3 = firstArgumentDot?.secondArgumentDot?.thirdArgumentDot?.fourthArgumentDot
val elem3 = firstArgumentDot?.secondArgumentDot?.thirdArgumentDot()?.fourthArgumentDot
?.fifthArgumentDot?.sixthArgumentDot


val elem4 = firstArgumentDot?.secondArgumentDot?.thirdArgumentDot + firstArgumentDot?.secondArgumentDot?.thirdArgumentDot?.fourthArgumentDot


val elem5 = firstArgumentDot!!.secondArgumentDot!!.thirdArgumentDot!!.fourthArgumentDot!!.fifthArgumentDot!!.sixthArgumentDot
val elem5 = firstArgumentDot()!!.secondArgumentDot()!!.thirdArgumentDot!!.fourthArgumentDot!!.fifthArgumentDot!!.sixthArgumentDot()


val elem6 = firstArgumentDot!!.secondArgumentDot!!.thirdArgumentDot!!
.fourthArgumentDot!!.fifthArgumentDot!!.sixthArgumentDot
val elem6 = firstArgumentDot!!.secondArgumentDot!!.thirdArgumentDot()!!
.fourthArgumentDot!!.fifthArgumentDot()!!.sixthArgumentDot


val elem7 = firstArgumentDot!!.secondArgumentDot!!.thirdArgumentDot!!.fourthArgumentDot!!
val elem7 = firstArgumentDot!!.secondArgumentDot()!!.thirdArgumentDot!!.fourthArgumentDot()!!
.fifthArgumentDot!!.sixthArgumentDot


val elem8 = firstArgumentDot!!.secondArgumentDot!!.thirdArgumentDot + firstArgumentDot!!.secondArgumentDot!!.thirdArgumentDot!!.fourthArgumentDot
val elem8 = firstArgumentDot()!!.secondArgumentDot!!.thirdArgumentDot + firstArgumentDot!!.secondArgumentDot!!.thirdArgumentDot!!.fourthArgumentDot


val elem9 = firstArgumentDot.secondArgumentDot.thirdArgumentDot.fourthArgumentDot.fifthArgumentDot.sixthArgumentDot
val elem9 = firstArgumentDot().secondArgumentDot.thirdArgumentDot().fourthArgumentDot.fifthArgumentDot.sixthArgumentDot


val elem10 = firstArgumentDot.secondArgumentDot.thirdArgumentDot
.fourthArgumentDot.fifthArgumentDot.sixthArgumentDot
val elem10 = firstArgumentDot.secondArgumentDot().thirdArgumentDot
.fourthArgumentDot.fifthArgumentDot().sixthArgumentDot


val elem11 = firstArgumentDot.secondArgumentDot.thirdArgumentDot.fourthArgumentDot
val elem11 = firstArgumentDot.secondArgumentDot.thirdArgumentDot().fourthArgumentDot
.fifthArgumentDot.sixthArgumentDot


val elem12 = firstArgumentDot.secondArgumentDot.thirdArgumentDot + firstArgumentDot.secondArgumentDot.thirdArgumentDot.fourthArgumentDot
val elem12 = firstArgumentDot.secondArgumentDot.thirdArgumentDot + firstArgumentDot.secondArgumentDot().thirdArgumentDot.fourthArgumentDot


val elem13 = firstArgumentDot!!.secondArgumentDot?.thirdArgumentDot.fourthArgumentDot!!.fifthArgumentDot?.sixthArgumentDot
val elem13 = firstArgumentDot!!.secondArgumentDot?.thirdArgumentDot().fourthArgumentDot!!.fifthArgumentDot()?.sixthArgumentDot


val elem14 = firstArgumentDot.secondArgumentDot?.thirdArgumentDot!!.fourthArgumentDot?.fifthArgumentDot.sixthArgumentDot
val elem14 = firstArgumentDot.secondArgumentDot?.thirdArgumentDot()!!.fourthArgumentDot?.fifthArgumentDot.sixthArgumentDot


val elem15 = firstArgumentDot?.secondArgumentDot!!.thirdArgumentDot.fourthArgumentDot.fifthArgumentDot!!.sixthArgumentDot
val elem15 = firstArgumentDot?.secondArgumentDot!!.thirdArgumentDot.fourthArgumentDot().fifthArgumentDot!!.sixthArgumentDot


val elem16 = firstArgumentDot.secondArgumentDot.thirdArgumentDot.fourthArgumentDot.fifthArgumentDot.sixthArgumentDot


val elem17 = firstArgumentDot!!.secondArgumentDot.thirdArgumentDot!!.fourthArgumentDot.fifthArgumentDot!!.sixthArgumentDot


val elem18 = firstArgumentDot.secondArgumentDot?.thirdArgumentDot.fourthArgumentDot?.fifthArgumentDot.sixthArgumentDot


private val holder: java.util.concurrent.atomic.AtomicReference<T> = java.util.concurrent.atomic.AtomicReference(valueToStore)


private val holder: kotlin.native.concurrent.AtomicReference<T> = kotlin.native.concurrent.AtomicReference(valueToStore)