Skip to content

Commit

Permalink
Added this operator references to the list with similar operator refe…
Browse files Browse the repository at this point in the history
…rences (#1393)

### Whats added:
 * Add 2 operator references
 * Corrected comment

### Issue(#1393)
  • Loading branch information
Arrgentum authored Jun 22, 2022
1 parent b4fed8f commit 75bf80f
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import com.pinterest.ktlint.core.ast.ElementType.ELVIS
import com.pinterest.ktlint.core.ast.ElementType.EOL_COMMENT
import com.pinterest.ktlint.core.ast.ElementType.EQ
import com.pinterest.ktlint.core.ast.ElementType.EQEQ
import com.pinterest.ktlint.core.ast.ElementType.EQEQEQ
import com.pinterest.ktlint.core.ast.ElementType.EXCL
import com.pinterest.ktlint.core.ast.ElementType.EXCLEQ
import com.pinterest.ktlint.core.ast.ElementType.EXCLEQEQEQ
import com.pinterest.ktlint.core.ast.ElementType.FILE
import com.pinterest.ktlint.core.ast.ElementType.FLOAT_CONSTANT
import com.pinterest.ktlint.core.ast.ElementType.FUN
Expand Down Expand Up @@ -570,8 +572,8 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
) : LongLineFixableCases(node) {
/**
* Fix a binary expression -
* If the transfer is done on the Elvis operator, then transfers it to a new line
* If not on the Elvis operator, then transfers it to a new line after the operation reference
* - If the transfer is done on the Elvis operator, then transfers it to a new line
* - If not on the Elvis operator, then transfers it to a new line after the operation reference
*/
@Suppress("UnsafeCallOnNullableType")
override fun fix() {
Expand All @@ -595,16 +597,18 @@ class LineLength(configRules: List<RulesConfig>) : DiktatRule(
}

/**
* This method stored all the nodes that have BINARY_EXPRESSION or PREFIX_EXPRESSION element type.
* Return List of the Pair <node, offset>
* First elem in List - Logic Binary Expression (&& ||)
* Second elem in List - Comparison Binary Expression (> < == >= <= !=)
* Other types (Arithmetical and Bit operation) (+ - * / % >> << *= += -= /= %= ++ -- ! in !in etc)
* This method stored all the nodes that have [BINARY_EXPRESSION] or [PREFIX_EXPRESSION] element type.
* - First elem in List - Logic Binary Expression (`&&`, `||`)
* - Second elem in List - Comparison Binary Expression (`>`, `<`, `==`, `>=`, `<=`, `!=`, `===`, `!==`)
* - Other types (Arithmetical and Bitwise operation) (`+`, `-`, `*`, `/`, `%`, `>>`, `<<`, `&`, `|`, `~`, `^`, `>>>`, `<<<`,
* `*=`, `+=`, `-=`, `/=`, `%=`, `++`, `--`, `in` `!in`, etc.)
*
* @return the list of node-to-offset pairs.
*/
@Suppress("TYPE_ALIAS")
private fun searchSomeSplitInBinaryExpression(parent: ASTNode, configuration: LineLengthConfiguration): List<Pair<ASTNode, Int>?> {
val logicListOperationReference = listOf(OROR, ANDAND)
val compressionListOperationReference = listOf(GT, LT, EQEQ, GTEQ, LTEQ, EXCLEQ)
val compressionListOperationReference = listOf(GT, LT, EQEQ, GTEQ, LTEQ, EXCLEQ, EQEQEQ, EXCLEQEQEQ)
val binList: MutableList<ASTNode> = mutableListOf()
searchBinaryExpression(parent, binList)
val rightBinList = binList.map {
Expand Down Expand Up @@ -752,8 +756,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) {
override fun fix() {
Expand Down

0 comments on commit 75bf80f

Please sign in to comment.