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

Correct fix with string concat #946

Merged
merged 14 commits into from
Jul 2, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
* BinaryExpression - if there is two concatenated strings and new line should be inserted after `+`
* None - if the string can't be split
*/
@Suppress("UnsafeCallOnNullableType")
private fun checkStringTemplate(node: ASTNode, configuration: LineLengthConfiguration): LongLineFixableCases {
var multiLineOffset = 0
val (nodeText, leftOffset) = if (node.text.lines().size > 1 ) {
Expand All @@ -150,7 +151,7 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
.lines()
.takeWhile { it.length < configuration.lineLength }
.forEach { multiLineOffset += it.length }
node.text.lines().find { it.length > 120 }!! to positionByOffset(node.psi.findElementAt(multiLineOffset + 1)!!.node.startOffset).second
node.text.lines().find { it.length > configuration.lineLength }!! to positionByOffset(node.psi.findElementAt(multiLineOffset + 1)!!.node.startOffset).second
} else {
node.text to positionByOffset(node.startOffset).second
}
Expand Down Expand Up @@ -293,6 +294,7 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
val incorrectText = wrongStringTemplate.node.text
val firstPart = incorrectText.substring(0, wrongStringTemplate.delimiterIndex)
val secondPart = incorrectText.substring(wrongStringTemplate.delimiterIndex, incorrectText.length)
// wrongStringTemplate.multiLineOffset equals zero if string in one line
Copy link
Member

Choose a reason for hiding this comment

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

That's not what I meant :) Why do you check if split is at white space only for single-line string?

val isSplitInWhiteSpace = wrongStringTemplate.multiLineOffset == 0 && wrongStringTemplate.node.psi.findElementAt(wrongStringTemplate.delimiterIndex)!!.node.isWhiteSpace()
kentr0w marked this conversation as resolved.
Show resolved Hide resolved
val correctNode =
if (!isSplitInWhiteSpace) {
Expand Down