Redundant arrow: support removing of 'it ->' #KT-28631 Fixed
This commit is contained in:
@@ -30,7 +30,9 @@ class RedundantLambdaArrowInspection : AbstractKotlinInspection() {
|
||||
val arrow = functionLiteral.arrow ?: return@lambdaExpressionVisitor
|
||||
val parameters = functionLiteral.valueParameters
|
||||
val singleParameter = parameters.singleOrNull()
|
||||
if (parameters.isNotEmpty() && singleParameter?.isSingleUnderscore != true) return@lambdaExpressionVisitor
|
||||
if (parameters.isNotEmpty() && singleParameter?.isSingleUnderscore != true && singleParameter?.name != "it") {
|
||||
return@lambdaExpressionVisitor
|
||||
}
|
||||
|
||||
if (lambdaExpression.getStrictParentOfType<KtWhenEntry>()?.expression == lambdaExpression) return@lambdaExpressionVisitor
|
||||
if (lambdaExpression.getStrictParentOfType<KtContainerNodeForControlStructureBody>()?.let {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fun foo(f: (String) -> Unit) {}
|
||||
|
||||
fun print(s: String) {}
|
||||
|
||||
fun bar() {
|
||||
foo { <caret>it ->
|
||||
print(it)
|
||||
print(it)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun foo(f: (String) -> Unit) {}
|
||||
|
||||
fun print(s: String) {}
|
||||
|
||||
fun bar() {
|
||||
foo {
|
||||
print(it)
|
||||
print(it)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
fun foo(f: () -> Unit) {}
|
||||
fun foo(f: (String) -> Unit) {}
|
||||
|
||||
fun bar() {
|
||||
foo { <caret>_ -> }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fun foo(f: () -> Unit) {}
|
||||
fun foo(f: (String) -> Unit) {}
|
||||
|
||||
fun bar() {
|
||||
foo { <caret>}
|
||||
|
||||
+5
@@ -4482,6 +4482,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/redundantLambdaArrow/inIfWhenEntry2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("it.kt")
|
||||
public void testIt() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantLambdaArrow/it.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantLambdaArrow/simple.kt");
|
||||
|
||||
Reference in New Issue
Block a user