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

Added this operator references to the list with similar operator references #1393

Merged
merged 6 commits into from
Jun 22, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,16 @@ 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.)
Fixed Show fixed Hide fixed
* @return the list of node-to-offset pairs.
Fixed Show fixed Hide fixed
*/
@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 +754,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