-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed
NO_BRACES_IN_CONDITIONALS_AND_LOOPS
fail inside scope functio…
…ns (#1739) Fixed `NO_BRACES_IN_CONDITIONALS_AND_LOOPS` fail inside scope functions ### What's done: * Reworked indent handling before `if` using `findIndentBeforeNode()` function. * Added tests for cases when conditionals and loops are inside scope functions. * Added `with` to scope functions list. Closes #1270
- Loading branch information
Showing
6 changed files
with
223 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...les/src/test/resources/test/paragraph3/braces/IfElseBracesInsideScopeFunctionsExpected.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package test.paragraph3.braces | ||
|
||
fun foo1() { | ||
str.apply { | ||
if (x > 0) { | ||
foo() | ||
} else { | ||
bar() | ||
} | ||
} | ||
} | ||
|
||
fun foo2() { | ||
str.let { if (x > 0) { foo() } | ||
else { | ||
bar() | ||
} | ||
} | ||
} | ||
|
||
fun foo3() { | ||
str.run { | ||
while (x > 0) { | ||
if (x > 0) { | ||
foo() | ||
} else { | ||
bar() | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun foo4() { | ||
str.with { while (x > 0) { | ||
if (x > 0) { | ||
foo() | ||
} else { bar() } | ||
} | ||
} | ||
} | ||
|
||
fun foo5() { | ||
str.also { | ||
while (x > 0) { if (x > 0) { | ||
foo() | ||
} else { | ||
bar() | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun foo6() { | ||
str.apply { | ||
if (x > 0) { | ||
foo() | ||
} else if (y > 0) { | ||
abc() | ||
} else { | ||
bar() | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...t-rules/src/test/resources/test/paragraph3/braces/IfElseBracesInsideScopeFunctionsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package test.paragraph3.braces | ||
|
||
fun foo1() { | ||
str.apply { | ||
if (x > 0) foo() | ||
else bar() | ||
} | ||
} | ||
|
||
fun foo2() { | ||
str.let { if (x > 0) { foo() } | ||
else bar() | ||
} | ||
} | ||
|
||
fun foo3() { | ||
str.run { | ||
while (x > 0) { | ||
if (x > 0) foo() | ||
else bar() | ||
} | ||
} | ||
} | ||
|
||
fun foo4() { | ||
str.with { while (x > 0) { | ||
if (x > 0) foo() | ||
else { bar() } | ||
} | ||
} | ||
} | ||
|
||
fun foo5() { | ||
str.also { | ||
while (x > 0) { if (x > 0) foo() | ||
else bar() | ||
} | ||
} | ||
} | ||
|
||
fun foo6() { | ||
str.apply { | ||
if (x > 0) foo() | ||
else if (y > 0) abc() | ||
else bar() | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ules/src/test/resources/test/paragraph3/braces/LoopsBracesInsideScopeFunctionsExpected.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package test.paragraph3.braces | ||
|
||
fun foo1() { | ||
str.apply { | ||
for (i in 1..100) { | ||
println(i) | ||
} | ||
} | ||
} | ||
|
||
fun foo2() { | ||
str.let { while (x > 0) { | ||
println(i) | ||
} | ||
} | ||
} | ||
|
||
fun foo3() { | ||
str.run { | ||
do { | ||
println(i) | ||
} | ||
while (x > 0) | ||
} | ||
} | ||
|
||
fun foo4() { | ||
str.with { do { | ||
println(i) | ||
} | ||
while (x > 0) | ||
} | ||
} | ||
|
||
fun foo5() { | ||
str.also { | ||
for (i in 1..100) { | ||
while (x > 0) | ||
{ | ||
println(i) | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...at-rules/src/test/resources/test/paragraph3/braces/LoopsBracesInsideScopeFunctionsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package test.paragraph3.braces | ||
|
||
fun foo1() { | ||
str.apply { | ||
for (i in 1..100) println(i) | ||
} | ||
} | ||
|
||
fun foo2() { | ||
str.let { while (x > 0) println(i) | ||
} | ||
} | ||
|
||
fun foo3() { | ||
str.run { | ||
do println(i) | ||
while (x > 0) | ||
} | ||
} | ||
|
||
fun foo4() { | ||
str.with { do println(i) | ||
while (x > 0) | ||
} | ||
} | ||
|
||
fun foo5() { | ||
str.also { | ||
for (i in 1..100) { | ||
while (x > 0) | ||
println(i) | ||
} | ||
} | ||
} |