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

Bugfix/long line in string template #1297

Merged
merged 63 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
0d62a5f
### Whats added:
May 16, 2022
89baaaa
Merge branch 'master' into bugfix/LongLine_in_StringTemplate
May 16, 2022
c00df8b
### Whats added:
May 16, 2022
5e52117
### Whats added:
May 20, 2022
949f78a
### Whats added:
May 24, 2022
abba36f
### Whats added:
May 24, 2022
6854102
### Whats added:
May 24, 2022
544011f
### Whats added:
May 24, 2022
58716cf
### Whats added:
May 24, 2022
df885f8
### Whats added:
May 24, 2022
fda30f6
### Whats added:
May 24, 2022
566f62f
### Whats added:
May 24, 2022
6b0ba56
### Whats added:
May 24, 2022
ebf05b1
### Whats added:
May 24, 2022
998ee8b
### Whats added:
May 25, 2022
ac942e6
### Whats added:
May 25, 2022
8c3d6b8
### Whats added:
May 25, 2022
ca89cbd
### Whats added:
May 25, 2022
e75580c
### Whats added:
May 25, 2022
4b5a2d0
### Whats added:
May 31, 2022
e7fc444
### Whats added:
May 31, 2022
09812b6
### Whats added:
May 31, 2022
a5e91dc
### Whats added:
May 31, 2022
a06a4e3
### Whats added:
May 31, 2022
410a743
### Whats added:
May 31, 2022
ada81be
### Whats added:
May 31, 2022
417e2d7
### Whats added:
May 31, 2022
4d2f87c
### Whats added:
May 31, 2022
ebf5e2b
### Whats added:
May 31, 2022
6201472
### Whats added:
May 31, 2022
b7060c1
### Whats added:
May 31, 2022
ba164c5
Merge branch 'master' into bugfix/LongLine_in_StringTemplate
Arrgentum May 31, 2022
a3630f1
### Whats added:
Jun 1, 2022
9cf7b09
Merge remote-tracking branch 'origin/bugfix/LongLine_in_StringTemplat…
Jun 1, 2022
2bcc2f8
### Whats added:
Jun 1, 2022
3a37ead
### Whats added:
Jun 1, 2022
21c44f1
### Whats added:
Jun 1, 2022
778ee66
### Whats added:
Jun 1, 2022
7d88336
Merge branch 'master' into bugfix/LongLine_in_StringTemplate
Arrgentum Jun 1, 2022
7c1675c
merged condition and other logics, fixed recursive logic, renamed fun…
Jun 1, 2022
79b4040
moved fix logic to class methods
Jun 7, 2022
7e01fc0
Merge branch 'master' into bugfix/LongLine_in_StringTemplate
Arrgentum Jun 7, 2022
a2b1b60
moved fix logic to class methods
Jun 7, 2022
8e8013b
Merge remote-tracking branch 'origin/bugfix/LongLine_in_StringTemplat…
Jun 7, 2022
b743379
moved fix logic to class methods
Jun 7, 2022
d1feaf3
moved fix logic to class methods
Jun 7, 2022
6ccdb65
corrected code
Jun 7, 2022
29f14b1
corrected code
Jun 7, 2022
b62d473
corrected code
Jun 7, 2022
20a5498
corrected code
Jun 7, 2022
276fd00
corrected code
Jun 7, 2022
61d4bac
corrected code
Jun 7, 2022
228a24f
corrected code
Jun 7, 2022
76f261b
corrected code
Jun 8, 2022
68d4b1a
corrected code
Jun 8, 2022
e494594
corrected code
Jun 8, 2022
2a4ce0f
corrected code
Jun 8, 2022
66f1df5
Merge branch 'master' into bugfix/LongLine_in_StringTemplate
Arrgentum Jun 15, 2022
22c79b9
Merge branch 'master' into bugfix/LongLine_in_StringTemplate
Arrgentum Jun 15, 2022
8be353c
Merge branch 'master' into bugfix/LongLine_in_StringTemplate
Arrgentum Jun 15, 2022
910738a
fix all
Jun 16, 2022
95c1b0b
Merge remote-tracking branch 'origin/bugfix/LongLine_in_StringTemplat…
Jun 16, 2022
f29777f
Merge branch 'master' into bugfix/LongLine_in_StringTemplate
Arrgentum Jun 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,17 @@ 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
*/
fun ASTNode.appendNewlineMergingWhiteSpace(whiteSpaceNode: ASTNode?, beforeNode: ASTNode?) {
if (whiteSpaceNode != null && whiteSpaceNode.elementType == WHITE_SPACE) {
(whiteSpaceNode as LeafPsiElement).rawReplaceWithText("\n${whiteSpaceNode.text}")
if (whiteSpaceNode.text.lines().size == 1) {
0x6675636b796f75676974687562 marked this conversation as resolved.
Show resolved Hide resolved
(whiteSpaceNode as LeafPsiElement).rawReplaceWithText("\n${whiteSpaceNode.text}")
}
} else {
addChild(PsiWhiteSpaceImpl("\n"), beforeNode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,14 @@ class LineLengthFixTest : FixTestBase("test/paragraph3/long_line", ::LineLength)
fun `fix expression in condition`() {
fixAndCompare("LongExpressionInConditionExpected.kt", "LongExpressionInConditionTest.kt", rulesConfigListLineLength)
}

@Test
fun `fix long Dot Qualified Expression`() {
fixAndCompare("LongDotQualifiedExpressionExpected.kt", "LongDotQualifiedExpressionTest.kt", rulesConfigListLineLength)
}

@Test
fun `fix long value arguments list`() {
fixAndCompare("LongValueArgumentsListExpected.kt", "LongValueArgumentsListTest.kt", rulesConfigListLineLength)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class LineLengthWarnTest : LintTestBase(::LineLength) {
| }
|}
""".trimMargin(),
LintError(14, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 143", false),
LintError(18, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 142", false)
LintError(14, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 143", true),
LintError(18, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 142", true)
)
}

Expand Down Expand Up @@ -223,7 +223,8 @@ class LineLengthWarnTest : LintTestBase(::LineLength) {
|}
""".trimMargin(),
LintError(8, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 130", false),
LintError(9, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 123", false)
LintError(9, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 123", true)

)
}

Expand All @@ -235,7 +236,7 @@ class LineLengthWarnTest : LintTestBase(::LineLength) {
|@Query(value = "ASDAASDASDASDASDASDASDASDAASDASDASDASDASDASDASDAASDASDASDASDASDASD")
|fun foo() = println("ASDAASDASDASDASDASDASDASDAASDASDASDASDASDASDASDAASDASDASDASDASDASD")
""".trimMargin(),
LintError(1, 1, ruleId, "${LONG_LINE.warnText()} max line length 40, but was 84", false),
LintError(1, 1, ruleId, "${LONG_LINE.warnText()} max line length 40, but was 84", true),
LintError(2, 1, ruleId, "${LONG_LINE.warnText()} max line length 40, but was 89", true),
rulesConfigList = shortLineLength
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ fun foo() {
val variable =
Methoooooooooooooooooooooooooood() ?: "some loooooong string"

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

var headerKdoc = firstCodeNode.prevSibling {
it.elementType == KDOC
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package test.paragraph3.long_line

val G =
ThisIsVeryyyyLooooonNameDooootQualifiedExpressioWithoutDot.lalalala.lalalal

val A = This.Is.Veeeeryyyyyyy.Loooooong.Dot
.Qualified.Expression

val B = This?.Is?.Veeeeryyyyyyy?.Loooooong?.Dot
?.Qualified?.Expression

val C = This!!.Is!!.Veeeeryyyyyyy!!.Loooooong!!
.Dot!!.Qualified!!.Expression

val D = This.Is.Veeeeryyyyyyy.Loooooong.Dot
.Qualified.Expression

val E = This?.Is?.Veeeeryyyyyyy?.Loooooong?.Dot
?.Qualified?.Expression

val F = This!!.Is!!.Veeeeryyyyyyy!!.Loooooong!!
.Dot!!.Qualified!!.Expression
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package test.paragraph3.long_line

val G = ThisIsVeryyyyLooooonNameDooootQualifiedExpressioWithoutDot.lalalala.lalalal

val A = This.Is.Veeeeryyyyyyy.Loooooong.Dot.Qualified.Expression

val B = This?.Is?.Veeeeryyyyyyy?.Loooooong?.Dot?.Qualified?.Expression

val C = This!!.Is!!.Veeeeryyyyyyy!!.Loooooong!!.Dot!!.Qualified!!.Expression

val D = This.Is.Veeeeryyyyyyy.Loooooong.Dot
.Qualified.Expression

val E = This?.Is?.Veeeeryyyyyyy?.Loooooong?.Dot
?.Qualified?.Expression

val F = This!!.Is!!.Veeeeryyyyyyy!!.Loooooong!!
.Dot!!.Qualified!!.Expression
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package org.cqfn.diktat.resources.paragraph3.longline
class veryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong {
// looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongggggggggggggggggggggggggg
//looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongggggggggggggggggggggggggg
val s = "d" +
" s d d d d ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
val s =
"d s d d d d ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ fun foo() {
// ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ElementType.IF -> handleIfElse(node)
ElementType.EOL_COMMENT, ElementType.BLOCK_COMMENT -> handleEolAndBlockComments(node, configuration)
ElementType.KDOC -> handleKdocComments(node, configuration)
ElementType.KDOC ->
handleKdocComments(node, configuration)
// ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
else -> {
// this is a generated else block
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package test.paragraph3.long_line

@Query(value = "select * from test inner join" +
" test_execution on test.id = test_execution.test_id and test_execution.st", nativeQuery = true)
@Query(
value = "select * from test inner join test_execution on test.id = test_execution.test_id and test_execution.st",
nativeQuery = true
)
fun retrieveBatches(limit: Int, offset: Int, executionId: Long): Some

@Query(value = "select * from test inner join" +
" test_execution on test.id = test_execution.test_id and test_execution.status = 'READY' and test_execution.test_suite_execution_id = ?3 limit ?1 offset ?2", nativeQuery = true)
@Query(
value = "select * from test inner join test_execution on test.id = test_execution.test_id and test_execution.status = 'READY' and test_execution.test_suite_execution_id = ?3 limit ?1 offset ?2",
nativeQuery = true
)
fun some(limit: Int, offset: Int, executionId: Long): List<Test>

@Query(value = "select * from test inner joi", nativeQuery = true)
@Query(value = "select * from test inner joi",
nativeQuery = true)
fun test(limit: Int, offset: Int, executionId: Long): List<Test>

@Query(value = "select * from test inner joibbb", nativeQuery = true)
@Query(value = "select * from test inner joibbb",
nativeQuery = true)
fun cornerCase(limit: Int, offset: Int, executionId: Long): List<Test>

@Query(value = "select * from test inner join" +
" test_execution on test.id = test_execution.test_id and test_execution.status = 'READY' and test_execution.test_suite_execution_id = ?3 limit ?1 offset ?2", nativeQuery = true)
@Query(
value = "select * from test inner join test_execution on test.id = test_execution.test_id and test_execution.status = 'READY' and test_execution.test_suite_execution_id = ?3 limit ?1 offset ?2",
nativeQuery = true
)
fun some(limit: Int, offset: Int, executionId: Long) =
println("testtesttesttesttesttesttesttesttesttesttesttest")
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package test.paragraph3.long_line

fun foo() =
println("fhdbsfkhfbvsjfkvbhjdksfvhbhhjhjhjnaljfbkshvjdsjdnlvbdkhkjncdkljskbfvhdsjndlvfkbdhfjdncjsdcscsdcsdcsdcdd")
fun foo() = println(
"fhdbsfkhfbvsjfkvbhjdksfvhbhhjhjhjnaljfbkshvjdsjdnlvbdkhkjncdkljskbfvhdsjndlvfkbdhfjdncjsdcscsdcsdcsdcdd"
)

fun foo () { println("fhdbsfkhfbvsjfkvbhjdksfvhbhhjhjhjnaljfbkshvjdsjdnlvbdkhkjncdkljskbfvhdsjndlvfkbdhfjdncjsdcscsdcsdcsdcdd") }
fun foo () { println(
"fhdbsfkhfbvsjfkvbhjdksfvhbhhjhjhjnaljfbkshvjdsjdnlvbdkhkjncdkljskbfvhdsjndlvfkbdhfjdncjsdcscsdcsdcsdcdd"
) }
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ fun foo() {
fun foo() {
val veryLoooooooooooooooooongNamesList =
listOf<String>("Jack", "Nick")
veryLoooooooooooooooooongNamesList.forEach {
name ->
veryLoooooooooooooooooongNamesList
.forEach { name ->
if (name == "Nick") {
veryLoooooooooooooooooongNamesList.map { val str = "This string shouldn't be split"}
veryLoooooooooooooooooongNamesList
.map { val str = "This string shouldn't be split"}
name.map { val str =
"This string should be split" }
}

}
}

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

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

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

val longStringExpression2 =
"String starts at the line len limit"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package test.paragraph3.long_line

val LongWithVar2 = "${s + "a"} is a string"
val LongWithVar2 =
"${s + "a"} is a string"
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ object Observables {
val someCode = 15
// Some
// looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line
@Deprecated("New type inference algorithm in Kotlin 1.4 makes this method obsolete. Method will be removed in" +
" future RxKotlin release.",
replaceWith = ReplaceWith("Observable.combineLatest(source1, source2, source3, source4, combineFunction)", "io.reactivex.Observable"),
level = DeprecationLevel.WARNING)
@Deprecated(
"New type inference algorithm in Kotlin 1.4 makes this method obsolete. Method will be removed in future RxKotlin release.",
replaceWith = ReplaceWith("Observable.combineLatest(source1, source2, source3, source4, combineFunction)",
"io.reactivex.Observable"),
level = DeprecationLevel.WARNING
)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
inline fun <T1 : Any, T2 : Any, T3 : Any, T4 : Any, R : Any> combineLatest() {}
Expand All @@ -15,9 +17,12 @@ 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()) "skfnvsdcsdcscskdjdfvd" else "dfjvndsdcsdcsdcskjnbvif" + 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 = """
Expand Down Expand Up @@ -46,4 +51,7 @@ class Foo() {
}
""".trimIndent()
}

val stringName = "This is long string template with binary expression. test should be up in level binary" +
" expression and cannot split in operation reference and should be split this long string template" + "this string should be after operated reference"
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ class Foo() {
}
""".trimIndent()
}

val stringName = "This is long string template with binary expression. test should be up in level binary expression and cannot split in operation reference and should be split this long string template" + "this string should be after operated reference"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package test.paragraph3.long_line

val firstArgument = 1
val secondArgument = 2
val thirdArgument = 3
val fourthArgument = 4
val fifthArguments = 5
val sixthArguments = 6
val seventhArguments = 7
val eighthArguments = 8

// Many arguments in function
val result1 = ManyParamInFunction(firstArgument,
secondArgument, thirdArgument, fourthArgument,
fifthArguments, sixthArguments, seventhArguments,
eighthArguments)

//
val result2 = veryLongNameFun(firstArgument,
secondArgument)

// first argument cannot to be able to stay in
// the first line
val result3 = veryLongNameInFirstParam(
firstArgument, secondArgument, thirdArgument
)

// first argument cannot to be able to stay in
// the first line
val result4 = veryLongNameInFirstParam(
firstArgument
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package test.paragraph3.long_line

val firstArgument = 1
val secondArgument = 2
val thirdArgument = 3
val fourthArgument = 4
val fifthArguments = 5
val sixthArguments = 6
val seventhArguments = 7
val eighthArguments = 8

// Many arguments in function
val result1 = ManyParamInFunction(firstArgument, secondArgument, thirdArgument, fourthArgument, fifthArguments, sixthArguments, seventhArguments, eighthArguments)

//
val result2 = veryLongNameFun(firstArgument, secondArgument)

// first argument cannot to be able to stay in the first line
val result3 = veryLongNameInFirstParam(firstArgument, secondArgument, thirdArgument)

// first argument cannot to be able to stay in the first line
val result4 = veryLongNameInFirstParam(firstArgument)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.cqfn.diktat

val A = This.Is.Veeeeryyyyyyy.Loooooong.Dot.Qualified.Expression
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.cqfn.diktat

/**
* @return
*/
val A = This.Is.Veeeeryyyyyyy.Loooooong.Dot.Qualified.Expression