Skip to content

Commit

Permalink
## Whats Added:
Browse files Browse the repository at this point in the history
 * add analytic fully-qualified
 * add test
 * correct warning message

## Issue (#1403)
  • Loading branch information
Arrgentum committed Jun 28, 2022
1 parent 5f77cad commit f7e6ed1
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ import com.pinterest.ktlint.core.ast.isWhiteSpaceWithNewline
import com.pinterest.ktlint.core.ast.nextCodeSibling
import com.pinterest.ktlint.core.ast.parent
import com.pinterest.ktlint.core.ast.prevCodeSibling
import com.sun.org.apache.xpath.internal.operations.Bool
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType
import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet
import org.jetbrains.kotlin.fir.builder.Context
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.KtParameterList
Expand Down Expand Up @@ -158,12 +160,14 @@ 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')))
}
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 +197,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('{'))) {
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"
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)

0 comments on commit f7e6ed1

Please sign in to comment.