Skip to content

Commit

Permalink
### Whats added:
Browse files Browse the repository at this point in the history
 * corrected logic fix and warn String Template in LineLength rule
 * added logic fix and warn long Dot Qualified Expression and Safe Access Expression in LineLength rule
 * added logic fix and warn Value Arguments List in LineLength rule
 * added and corrected fix and warn tests in LineLength rule
 * corrected code and KDoc method appendNewlineMergingWhiteSpace in AstNodeUtils.kt
 * fix code with diktat:fix@diktat
 * added comments to classes and functions
 * correct code with running detect

 ### Issue (#1243)
  • Loading branch information
Arrgentum committed May 31, 2022
1 parent e75580c commit 4b5a2d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,11 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
private fun parserDotQualifiedExpression(wrongNode: ASTNode, configuration: LineLengthConfiguration): LongLineFixableCases {
val nodeDot = searchRightSplitAfterType(wrongNode, configuration, DOT)
val nodeSafeAccess = searchRightSplitAfterType(wrongNode, configuration, SAFE_ACCESS)
nodeDot?.let {
return DotQualifiedExpression(wrongNode)
return nodeDot?.let {
DotQualifiedExpression(wrongNode)
} ?: nodeSafeAccess?.let {
return DotQualifiedExpression(wrongNode)
}
return None()
DotQualifiedExpression(wrongNode)
} ?: None()
}

private fun checkFunAndProperty(wrongNode: ASTNode) =
Expand Down Expand Up @@ -563,7 +562,7 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(

/**
* This method uses recursion to store dot qualified expression node in the order in which they are located
* Also dotList contains nodes with PREFIX_EXPRESSION element type ( !isFoo(), !isValid)
* Also dotList contains nodes with PREFIX_EXPRESSION element type ( !isFoo(), !isValid))
*
*@param node node in which to search
*@param dotList mutable list of ASTNode to store nodes
Expand Down Expand Up @@ -630,7 +629,7 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
}

/**
* Finds the first binary expression or dat closer to the separator
* Finds the first binary expression or dot and safe access closer to the separator
*/
@Suppress("UnsafeCallOnNullableType")
private fun searchRightSplitAfterType(
Expand Down Expand Up @@ -676,29 +675,17 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
private class None : LongLineFixableCases(KotlinParser().createNode("ERROR"))

/**
* @property node node
* Class Comment show that long line should be split in comment
* @property hasNewLineBefore flag to handle type of comment: ordinary comment (long part of which should be moved to the next line)
* and inline comments (which should be moved entirely to the previous line)
* @property indexLastSpace index of last space to substring comment
*/

/**
* Class Comment show that long line should be split in comment
* @property hasNewLineBefore
* @property indexLastSpace
*/
private class Comment(
node: ASTNode,
val hasNewLineBefore: Boolean,
val indexLastSpace: Int = 0
) : LongLineFixableCases(node)

/**
* @property node node
* @property delimiterIndex index to split
* @property isOneLineString flag is string is one line
*/

/**
* Class StringTemplate show that long line should be split in string template
* @property delimiterIndex
Expand All @@ -718,9 +705,9 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
/**
* Class LongBinaryExpression show that long line should be split between other parts long binary expression,
* after one of operation reference
* @property maximumLineLength
* @property leftOffset
* @property binList
* @property maximumLineLength is number of maximum line length
* @property leftOffset is offset before start [node]
* @property binList is list of Binary Expression which are children of [node]
*/
private class LongBinaryExpression(
node: ASTNode,
Expand Down Expand Up @@ -752,8 +739,8 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(

/**
* Class WhenEntry show that line should be split in WhenEntry node:
* Added LBRACE and RBRACE nodes
* Split line in space after LBRACE node and before RBRACE node
* Added [LBRACE] and [RBRACE] nodes
* Split line in space after [LBRACE] node and before [RBRACE] node
*/
private class WhenEntry(node: ASTNode) : LongLineFixableCases(node)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ fun ASTNode.leaveExactlyNumNewLines(num: Int) {
}

/**
* If [whiteSpaceNode] is not null and has type [WHITE_SPACE], prepend a line break to it's text.
* Otherwise, insert a new node with a line break before [beforeNode]
* If [whiteSpaceNode] is not null and has type [WHITE_SPACE] and this [WHITE_SPACE] contains 1 line, prepend a line break to it's text.
* If [whiteSpaceNode] is null or has`t type [WHITE_SPACE], insert a new node with a line break before [beforeNode]
*
* @param whiteSpaceNode a node that can possibly be modified
* @param beforeNode a node before which a new WHITE_SPACE node will be inserted
Expand Down

0 comments on commit 4b5a2d0

Please sign in to comment.