-
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.
Improve autofix in AVOID_NULL_CHECKS rule (#1201)
* Improve autofix in AVOID_NULL_CHECKS rule ### What's done: * improved autofix: now we don't use `let` and `run` in some cases * added tests (#899) * Improve autofix in AVOID_NULL_CHECKS rule ### What's done: * improved autofix: now we don't use `let` and `run` in some cases * added tests (#899) * Improve autofix in AVOID_NULL_CHECKS rule ### What's done: * improved autofix: now we don't use `let` and `run` in some cases * added tests (#899) * Improve autofix in AVOID_NULL_CHECKS rule ### What's done: * improved autofix: now we don't use `let` and `run` in some cases * added tests (#899) * Improve autofix in AVOID_NULL_CHECKS rule ### What's done: * improved autofix: now we don't use `let` and `run` in some cases * added tests (#1149) * Improve autofix in AVOID_NULL_CHECKS rule ### What's done: * improved autofix: now we don't use `let` and `run` in some cases * improved autofix: now we count statements, not lines * added tests (#1201) * Improve autofix in AVOID_NULL_CHECKS rule ### What's done: * improved autofix: now we don't use `let` and `run` in some cases * improved autofix: now we count statements, not lines * added tests (#1201) * Improve autofix in AVOID_NULL_CHECKS rule ### What's done: * improved autofix: now we don't use `let` and `run` in some cases * improved autofix: now we count statements, not lines * added tests (#1201) Co-authored-by: sanyavertolet <[email protected]> Co-authored-by: Andrey Kuleshov <[email protected]>
- Loading branch information
1 parent
cd0f00c
commit e8b4a51
Showing
8 changed files
with
226 additions
and
62 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
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
45 changes: 45 additions & 0 deletions
45
...at-rules/src/test/resources/test/paragraph4/null_checks/IfConditionAssignCheckExpected.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,45 @@ | ||
package test.paragraph4.null_checks | ||
|
||
fun foo() { | ||
val x = a?.let { | ||
f(a) | ||
} ?: g(a) | ||
|
||
val y = a ?: 0 | ||
|
||
x ?: println("NULL") | ||
|
||
val z = x ?: run { | ||
println("NULL") | ||
0 | ||
} | ||
|
||
x?.let { | ||
f(x) | ||
} ?: run { | ||
println("NULL") | ||
g(x) | ||
} | ||
} | ||
|
||
fun bar() { | ||
val x = a?.let { | ||
f(a) | ||
} ?: g(a) | ||
|
||
val y = a ?: 0 | ||
|
||
x ?: println("NULL") | ||
|
||
val z = x ?: run { | ||
println("NULL") | ||
0 | ||
} | ||
|
||
x?.let { | ||
f(x) | ||
} ?: run { | ||
println("NULL") | ||
g(x) | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
diktat-rules/src/test/resources/test/paragraph4/null_checks/IfConditionAssignCheckTest.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,53 @@ | ||
package test.paragraph4.null_checks | ||
|
||
fun foo() { | ||
val x = if (a != null) f(a) else g(a) | ||
|
||
val y = if (a != null) a else 0 | ||
|
||
if (x != null) { | ||
x | ||
} else { | ||
println("NULL") | ||
} | ||
|
||
val z = if (x != null) { | ||
x | ||
} else { | ||
println("NULL") | ||
0 | ||
} | ||
|
||
if (x != null) { | ||
f(x) | ||
} else { | ||
println("NULL") | ||
g(x) | ||
} | ||
} | ||
|
||
fun bar() { | ||
val x = if (a == null) g(a) else f(a) | ||
|
||
val y = if (a == null) 0 else a | ||
|
||
if (x == null) { | ||
println("NULL") | ||
} else { | ||
x | ||
} | ||
|
||
val z = if (x == null) { | ||
println("NULL") | ||
0 | ||
} else { | ||
x | ||
} | ||
|
||
if (x == null) { | ||
println("NULL") | ||
g(x) | ||
} else { | ||
f(x) | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -15,10 +15,7 @@ fun foo() { | |
|
||
prop?.let { | ||
doAnotherSmth() | ||
} | ||
?: run { | ||
doSmth() | ||
} | ||
} ?: doSmth() | ||
} | ||
|
||
fun fooo() { | ||
|