Redundant arrow: support removing of 'it ->' #KT-28631 Fixed

This commit is contained in:
Mikhail Glukhikh
2018-12-06 16:15:35 +03:00
parent 92150d847a
commit c8c485d27e
6 changed files with 30 additions and 3 deletions
@@ -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>}
@@ -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");