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

Fix logic "BinaryExpression" in "LineLength" Rule #1292

Merged
merged 38 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6e437e4
first version
Apr 15, 2022
7f32265
Merge branch 'master' into condition
Apr 15, 2022
1a3fafc
fix Binary Expression
Apr 19, 2022
e199296
# fix rule line length (split in binary expression), change 5 expecte…
May 4, 2022
6874cfc
# fix rule line length (split in binary expression), change 5 expecte…
May 4, 2022
298135e
# fix rule line length (split in binary expression), change 5 expecte…
May 4, 2022
b32706a
# fix rule line length (split in binary expression), change 5 expecte…
May 4, 2022
83cb0ec
Merge branch 'master' into condition
Arrgentum May 4, 2022
a3f9dbc
# fix rule line length (split in binary expression), change 5 expecte…
May 4, 2022
8af6958
Merge remote-tracking branch 'origin/condition' into bugfix/Long_line…
May 4, 2022
e612b48
# fix rule line length (split in binary expression), change 5 expecte…
May 4, 2022
a913203
# fix rule line length (split in binary expression), change 5 expecte…
May 4, 2022
4789e76
# fix rule line length (split in binary expression), change 5 expecte…
May 4, 2022
cde3606
# fix rule line length (split in binary expression), change 5 expecte…
May 4, 2022
290d8fd
# fix rule line length (split in binary expression), change 5 expecte…
May 5, 2022
783b3d9
# fix rule line length (split in binary expression), change 5 expecte…
May 5, 2022
dcf2e4f
Merge branch 'master' into condition
orchestr7 May 6, 2022
2df4e32
# fix rule line length (split in binary expression), change 5 expecte…
May 11, 2022
0ad8e36
# fix rule line length (split in binary expression), change 5 expecte…
May 11, 2022
d316e0c
Merge remote-tracking branch 'origin/condition' into bugfix/Long_line…
May 11, 2022
cb03cc0
1) Fixed logic and tests for binary expression in rule "LineLength"
May 11, 2022
fc495d8
Merge branch 'master' into condition
Arrgentum May 11, 2022
075c224
1) Fixed logic and tests for binary expression in rule "LineLength"
May 11, 2022
58535f5
1) Fixed logic and tests for binary expression in rule "LineLength"
May 11, 2022
81ebac5
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
30d4253
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
e372898
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
e59912d
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
e55eedc
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
69f67c0
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
19689c5
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
2f7b875
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
e95ed49
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
0f3c0c9
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
5ee9635
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
3148834
1) Fixed logic and tests for binary expression in rule "LineLength"
May 12, 2022
6944b42
Corrected the code for all comments in the pull request
May 16, 2022
004e368
Corrected the code for all comments in the pull request
May 16, 2022
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 @@ -10,6 +10,7 @@ import org.cqfn.diktat.ruleset.constants.Warnings.PACKAGE_NAME_INCORRECT_PREFIX
import org.cqfn.diktat.ruleset.constants.Warnings.PACKAGE_NAME_INCORRECT_SYMBOLS
import org.cqfn.diktat.ruleset.constants.Warnings.PACKAGE_NAME_MISSING
import org.cqfn.diktat.ruleset.rules.DiktatRule

import org.cqfn.diktat.ruleset.utils.*

import com.pinterest.ktlint.core.ast.ElementType.BLOCK_COMMENT
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@ class LineLengthFixTest : FixTestBase("test/paragraph3/long_line", ::LineLength)
fun `should fix annotation`() {
fixAndCompare("LongLineAnnotationExpected.kt", "LongLineAnnotationTest.kt", rulesConfigListLineLength)
}

@Test
fun `fix condition in small function`() {
fixAndCompare("LongConditionInSmallFunctionExpected.kt", "LongConditionInSmallFunctionTest.kt", rulesConfigListDefaultLineLength)
kgevorkyan marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
fun `fix expression in condition`() {
fixAndCompare("LongExpressionInConditionExpected.kt", "LongExpressionInConditionTest.kt", rulesConfigListLineLength)
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
package test.paragraph3.long_line

fun foo() {
val veryLongExpression = Methoooooooooooooooood() +
12345
val veryLongExpression =
kgevorkyan marked this conversation as resolved.
Show resolved Hide resolved
Methoooooooooooooooood() + 12345

val veryLongExpression = Methoooooooooooooooood() ?:
null
val veryLongExpression =
Methoooooooooooooooood() ?: null

val veryLongExpression = a.Methooooood() +
b.field

val variable = someField.filter { it.elementType == KDOC }
val variable = someField.filter {
it.elementType == KDOC
}

// limit at the left side
val variable = a?.filter { it.elementType == KDOC } ?:
null
val variable = a?.filter {
it.elementType == KDOC
} ?: null

// limit at the right side
val variable = bar?.filter { it.b == c } ?:
null
val variable = bar?.filter { it.b == c }
?: null

// limit at the operation reference
val variable = field?.filter { bar == foo } ?:
null
val variable = field?.filter { bar == foo }
?: null

val variable = Methoooooooooooooooooooooooooood() ?:
"some loooooong string"
val variable =
Methoooooooooooooooooooooooooood() ?: "some loooooong string"

val variable = Methooooood() ?: "some" +
" looong string"

var headerKdoc = firstCodeNode.prevSibling { it.elementType == KDOC } ?:
if (firstCodeNode == packageDirectiveNode) importsList?.prevSibling { it.elementType == KDOC } else null
var headerKdoc = firstCodeNode.prevSibling {
it.elementType == KDOC
} ?: if (firstCodeNode == packageDirectiveNode) importsList?.prevSibling { it.elementType == KDOC } else null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package test.paragraph3.long_line

private fun isContainingRequiredPartOfCode(text: String): Boolean =
text.contains("val ", true) || text.contains("var ", true) || text.contains("=", true) ||
(text.contains("{", true) && text.substringAfter("{").contains("}", true))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package test.paragraph3.long_line

private fun isContainingRequiredPartOfCode(text: String): Boolean =
text.contains("val ", true) || text.contains("var ", true) || text.contains("=", true) || (text.contains("{", true) && text.substringAfter("{").contains("}", true))
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package test.paragraph3.long_line

fun foo() {
val veryLooongStringName = "ASDFGHJKL"
val veryLooooooongConstIntName1 = 12345
val veryLooooooongConstIntName2 = 54321
var carry = 1
if (veryLooooooongConstIntName1 >
veryLooooooongConstIntName2) {
carry++
} else if (veryLooooooongConstIntName2 >
123 * 12 && veryLooongStringName != "asd") {
carry+=2
} else if (1234 + 1235 + 1236 + 1237 + 1238 >
124 * 12) {
carry+=3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package test.paragraph3.long_line

fun foo() {
val veryLooongStringName = "ASDFGHJKL"
val veryLooooooongConstIntName1 = 12345
val veryLooooooongConstIntName2 = 54321
var carry = 1
if (veryLooooooongConstIntName1 > veryLooooooongConstIntName2) {
carry++
} else if (veryLooooooongConstIntName2 > 123 * 12 && veryLooongStringName != "asd") {
carry+=2
} else if (1234 + 1235 + 1236 + 1237 + 1238 > 124 * 12) {
carry+=3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
*/
sanyavertolet marked this conversation as resolved.
Show resolved Hide resolved
class ImplicitBackingPropertyRuleTest(configRules: List<RulesConfig>) {
private fun validateAccessors(node: ASTNode, propsWithBackSymbol: List<String>) {
val accessors = node.findAllDescendantsWithSpecificType(PROPERTY_ACCESSOR).filter { it.hasChildOfType(BLOCK) } // Comment, which shouldn't be moved
accessors.filter { it.hasChildOfType(GET_KEYWORD) }.forEach { handleGetAccessors(it, node, propsWithBackSymbol) }
accessors.filter { it.hasChildOfType(SET_KEYWORD) }.forEach { handleSetAccessors(it, node, propsWithBackSymbol) }
val accessors =
node.findAllDescendantsWithSpecificType(PROPERTY_ACCESSOR).filter { it.hasChildOfType(BLOCK) } // Comment, which shouldn't be moved
accessors.filter { it.hasChildOfType(GET_KEYWORD) }.forEach {
handleGetAccessors(it, node, propsWithBackSymbol)
}
accessors.filter { it.hasChildOfType(SET_KEYWORD) }.forEach {
handleSetAccessors(it, node, propsWithBackSymbol)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package test.paragraph3.long_line

fun foo() {
if (( x > 4365873654863745683)||
y<238479283749238&&!isFoo()){}
if (( x > 4365873654863745683) ||
y<238479283749238 && !isFoo()){}
if (q.text == "dc" && !IsFoo() ||
Expand All @@ -9,7 +11,8 @@ fun foo() {
x > 238479283749238 && y < 238479283749238 || g == "text"){}
if (d == "very long text" &&
gh == "very long text" || x > 238479283749238 || y< 238479283749238){}
if (x == 2384792837492387498728947289472987492){}
if (x ==
2384792837492387498728947289472987492){}
if (x == 972938473924535278492792738497){}
if (x == "veery long text to split" ||
x == "es" || y == 123 || b > 12 && jh==234 || h==54){}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test.paragraph3.long_line

fun foo() {
if (( x > 4365873654863745683)||y<238479283749238&&!isFoo()){}
kgevorkyan marked this conversation as resolved.
Show resolved Hide resolved
if (( x > 4365873654863745683) || y<238479283749238 && !isFoo()){}
if (q.text == "dc" && !IsFoo() || x > 238479283749238 && y < 238479283749238 || g == "text"){}
if (q.text == "dc" && !IsFoo() || x > 238479283749238 && y < 238479283749238 || g == "text"){}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,44 @@ fun foo() {
" should be split"

fun foo() {
val veryLoooooooooooooooooongNamesList = listOf<String>("Jack", "Nick")
veryLoooooooooooooooooongNamesList.forEach { name ->
val veryLoooooooooooooooooongNamesList =
listOf<String>("Jack", "Nick")
veryLoooooooooooooooooongNamesList.forEach {
name ->
if (name == "Nick") {
veryLoooooooooooooooooongNamesList.map { val str = "This string shouldn't be split"}
name.map { val str = "This" +
" string should be split" }
name.map { val str =
"This string should be split" }
}

}
}

val longIntExpression = 12345 + 12345 +
12345 + 12345

val longIntExpression = (12345 + 12345 +
12345 + 12345)

val longIntExpression = (12345) + (12345) +
(12345) + (12345)

val LongWithVar2 = "very long" +
" woooooordsdcsdcsdcsdc $variable"

val longStringExpression = "First part" +
"second Part"
"second Part"

val longStringExpression = "First" + "second Part"

val longStringExpression = "First very long" +
" part" + "second Part"

val longStringExpression2 = "String starts at the line len limit"
val longStringExpression2 =
"String starts at the line len limit"

val veryLooooooooooooooooooooooooooooooongVal = "text"

val longIntExpression = (12345 + 12345 +
12345 + 12345)

val longIntExpression = (12345) + (12345) +
(12345) + (12345)
val veryLooooooooooooooooooooooooooooooongVal =
"text"

val veryLongExpression = Method() + 12345 +
baaar()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ fun foo() {

val longIntExpression = 12345 + 12345 + 12345 + 12345

val longIntExpression = (12345 + 12345 + 12345 + 12345)

val longIntExpression = (12345) + (12345) + (12345) + (12345)

val LongWithVar2 = "very long woooooordsdcsdcsdcsdc $variable"

val longStringExpression = "First part" + "second Part"
Expand All @@ -27,10 +31,6 @@ fun foo() {

val veryLooooooooooooooooooooooooooooooongVal = "text"

val longIntExpression = (12345 + 12345 + 12345 + 12345)

val longIntExpression = (12345) + (12345) + (12345) + (12345)

val veryLongExpression = Method() + 12345 + baaar()

val veryLongExpression = Method() + baaar() + 12345
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ val someCode = 15
class Foo() {

fun Fuu() {
logger.log("<-- ${response.code} ${ if (response.message.isEmpty()) "skfnvkdjdfvd" else "dfjvndkjnbvif" + response.message}")
logger.log("<-- ${response.code} ${ if (response.message.isEmpty()) "skfnvkdjdfvd" else "dfjvndkjnbvif" +
response.message}")
logger.log("<-- ${response.code} ${ if (response.message.isEmpty()) "skfnvsdcsdcscskdjdfvd" else "dfjvndsdcsdcsdcskjnbvif" + response.message}")
}

val q = """
<--${respodcnsee.ccode}${if (response.mesdscsage.isEmpty()) "skfnvkdjeeeeeee" else "dfjvndksdcjnbvif" + response.mecsssdcage}
<--${respodcnsee.ccode}${if (response.mesdscsage.isEmpty()) "skfnvkdjeeeeeee" else "dfjvndksdcjnbvif" +
response.mecsssdcage}
""".trimIndent()

val w = """
Expand All @@ -31,15 +33,16 @@ class Foo() {

val e = """
another line
<--${respodcnse.ccode}${if (response.mesdscsage.isEmpty()) "skfnvkdjdsdcfvd" else "dfjvndksdcjnbvif" + response.mecsssdcage}
<--${respodcnse.ccode}${if (response.mesdscsage.isEmpty()) "skfnvkdjdsdcfvd" else "dfjvndksdcjnbvif" +
response.mecsssdcage}
""".trimIndent()

fun foo() {
val q = """
re
${
if (( x > "436587365486374568343658736548637456834365873654863745683436587365486374568343658736548637456834365873654863745683") ||
y<238479283749238 && !isFoo()){}
if (( x >
"436587365486374568343658736548637456834365873654863745683436587365486374568343658736548637456834365873654863745683") || y<238479283749238 && !isFoo()){}
}
""".trimIndent()
}
Expand Down