Add inspection to replace not-null assertion with elvis return
#KT-30381 Fixed
This commit is contained in:
committed by
Dmitry Gridin
parent
1c0c01725b
commit
dffcfdc02f
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.ReplaceNotNullAssertionWithElvisReturnInspection
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun test(i: Int?) {
|
||||
val x = i!!<caret>
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun test(i: Int?) {
|
||||
val x = i ?: return
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun foo(): Int? = null
|
||||
|
||||
fun test() {
|
||||
foo()!!<caret>
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun foo(): Int? = null
|
||||
|
||||
fun test() {
|
||||
foo() ?: return
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class Foo(val i: Int?)
|
||||
|
||||
fun test(foo: Foo): Int? {
|
||||
val x = foo.i!!<caret>
|
||||
return x
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class Foo(val i: Int?)
|
||||
|
||||
fun test(foo: Foo): Int? {
|
||||
val x = foo.i ?: return null
|
||||
return x
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class Foo {
|
||||
fun baz(): Int? = null
|
||||
}
|
||||
|
||||
fun test(foo: Foo): Int? {
|
||||
foo.baz()!!<caret>
|
||||
return 0
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class Foo {
|
||||
fun baz(): Int? = null
|
||||
}
|
||||
|
||||
fun test(foo: Foo): Int? {
|
||||
foo.baz() ?: return null
|
||||
return 0
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun test(i: Int?) {
|
||||
val x = i!!<caret> + 1
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun test(i: Int?) {
|
||||
val x = (i ?: return) + 1
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(list: List<String>, number: Int?) {
|
||||
list.forEach {
|
||||
number!!<caret>
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
fun test(list: List<String>, number: Int?) {
|
||||
list.forEach {
|
||||
number ?: return@forEach
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
fun test(list: List<String>, number: Int?) {
|
||||
val x: List<Int> = list.map {
|
||||
number!!<caret>
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: none
|
||||
fun test(i: Int?): Int {
|
||||
val x = i!!<caret>
|
||||
return x
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// PROBLEM: none
|
||||
fun test(i: Int?): Int? {
|
||||
return i!!<caret>
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// PROBLEM: none
|
||||
fun test(i: Int?): Int? {
|
||||
return (i!!<caret>)
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun test(a: Int?): Int? {
|
||||
return check(a!!<caret>)
|
||||
}
|
||||
|
||||
fun check(i: Int): Int = i
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun test(a: Int?): Int? {
|
||||
return check(a ?: return null)
|
||||
}
|
||||
|
||||
fun check(i: Int): Int = i
|
||||
idea/testData/inspectionsLocal/replaceNotNullAssertionWithElvisReturn/unnecessaryNotNullAssertion.kt
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
// PROBLEM: none
|
||||
fun test(i: Int) {
|
||||
val x = i!!<caret>
|
||||
}
|
||||
Reference in New Issue
Block a user