diktat
diktat copied to clipboard
Bug in WRONG_NEWLINES
Example:
vall foo = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes)
&& !hasReturnKdoc && !isReferenceExpressionWithSameName
Diktat will glue two lines into one and break on warning LONG_LINE
The reason, I believe, is that we don't allow line to start with operator (&&
in this case), but apparently we move the entire string on the previous line. We should only move the operator and let other rules handle operands placement.
Here is a peace of code:
val foo = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes)
&& !hasReturnKdoc && !isReferenceExpressionWithSameName
Here is what NewlinesRule does with this code:
val foo = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes)&&
!hasReturnKdoc && !isReferenceExpressionWithSameName
Here is what LongLine does with this code:
val foo = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType &&
hasNotExpressionBodyTypes)
&& !hasReturnKdoc && !isReferenceExpressionWithSameName
As far as I can see from tests, this problem is not caused by neither NewlinesRule nor LongLine.
Now it looks like this
Diktat: 1.1.0 + Kotlin: 1.6
Test1
LineLength = 180
Initial code №1:
val elem = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes)
&& !hasReturnKdoc && !isReferenceExpressionWithSameName
Observed behavior №1:
val elem = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc && !isReferenceExpressionWithSameName
Test2
LineLength >= 184
Initial code №2:
val elem = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc && !isReferenceExpressionWithSameName
Observed behavior №2:
val elem = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc && !isReferenceExpressionWithSameName
Test3
LineLength < 184 and > 147
Initial code №3:
val elem = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc && !isReferenceExpressionWithSameName
Observed behavior №3:
val elem = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc &&
!isReferenceExpressionWithSameName
Test4
LineLength < 148 and >= 139
Initial code №4:
val elem = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc && !isReferenceExpressionWithSameName
Observed behavior №4:
val elem = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) &&
!hasReturnKdoc && !isReferenceExpressionWithSameName
Test5
LineLength < 130 and >= 100
Initial code №5:
val elem = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc && !isReferenceExpressionWithSameName
Observed behavior №5:
val elem = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType &&
hasNotExpressionBodyTypes) && !hasReturnKdoc && !isReferenceExpressionWithSameName
Test6 - ERROR
LineLength = 150
Initial code №6:
val elem = (hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc && !isReferenceExpressionWithSameName
Observed behavior №6:
val elem =
(hasExplicitNotUnitReturnType || isFunWithExpressionBody && !hasExplicitUnitReturnType && hasNotExpressionBodyTypes) && !hasReturnKdoc && !isReferenceExpressionWithSameName
But wigth LineLength = 132, 133, 72, 73 this does not happen
Result
The error of this issue has already been resolved But if the separator falls at the beginning of the last word - may be not correct fix