SimplifiableCallChainInspection: replace .sorted().firstOrNull() with .min()
#KT-30725 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
bdac47369c
commit
3de723b8d0
+8
@@ -72,6 +72,14 @@ class SimplifiableCallChainInspection : AbstractCallChainChecker() {
|
||||
Conversion("kotlin.collections.filter", "kotlin.collections.singleOrNull", "singleOrNull"),
|
||||
Conversion("kotlin.collections.filter", "kotlin.collections.isNotEmpty", "any"),
|
||||
Conversion("kotlin.collections.filter", "kotlin.collections.List.isEmpty", "none"),
|
||||
Conversion("kotlin.collections.sorted", "kotlin.collections.firstOrNull", "min"),
|
||||
Conversion("kotlin.collections.sorted", "kotlin.collections.lastOrNull", "max"),
|
||||
Conversion("kotlin.collections.sortedDescending", "kotlin.collections.firstOrNull", "max"),
|
||||
Conversion("kotlin.collections.sortedDescending", "kotlin.collections.lastOrNull", "min"),
|
||||
Conversion("kotlin.collections.sortedBy", "kotlin.collections.firstOrNull", "minBy"),
|
||||
Conversion("kotlin.collections.sortedBy", "kotlin.collections.lastOrNull", "maxBy"),
|
||||
Conversion("kotlin.collections.sortedByDescending", "kotlin.collections.firstOrNull", "maxBy"),
|
||||
Conversion("kotlin.collections.sortedByDescending", "kotlin.collections.lastOrNull", "minBy"),
|
||||
|
||||
Conversion("kotlin.text.filter", "kotlin.text.first", "first"),
|
||||
Conversion("kotlin.text.filter", "kotlin.text.firstOrNull", "firstOrNull"),
|
||||
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).<caret>sortedByDescending { it.second }.firstOrNull()
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).maxBy { it.second }
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).<caret>sortedByDescending { it.second }.lastOrNull()
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).minBy { it.second }
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).<caret>sortedBy { it.second }.firstOrNull()
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).minBy { it.second }
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).<caret>sortedBy { it.second }.lastOrNull()
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf("a" to 1, ,"c" to 3, "b" to 2).maxBy { it.second }
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf(1, 3, 2).<caret>sortedDescending().firstOrNull()
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf(1, 3, 2).max()
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf(1, 3, 2).<caret>sortedDescending().lastOrNull()
|
||||
idea/testData/inspectionsLocal/collections/simplifiableCallChain/sortedDescendingLastOrNull.kt.after
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf(1, 3, 2).min()
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf(1, 3, 2).<caret>sorted().firstOrNull()
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf(1, 3, 2).min()
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf(1, 3, 2).<caret>sorted().lastOrNull()
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// WITH_RUNTIME
|
||||
val x = listOf(1, 3, 2).max()
|
||||
+40
@@ -1291,6 +1291,46 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/collections/simplifiableCallChain/saveComment3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortedByDescendingFirstOrNull.kt")
|
||||
public void testSortedByDescendingFirstOrNull() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/collections/simplifiableCallChain/sortedByDescendingFirstOrNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortedByDescendingLastOrNull.kt")
|
||||
public void testSortedByDescendingLastOrNull() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/collections/simplifiableCallChain/sortedByDescendingLastOrNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortedByFirstOrNull.kt")
|
||||
public void testSortedByFirstOrNull() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/collections/simplifiableCallChain/sortedByFirstOrNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortedByLastOrNull.kt")
|
||||
public void testSortedByLastOrNull() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/collections/simplifiableCallChain/sortedByLastOrNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortedDescendingFirstOrNull.kt")
|
||||
public void testSortedDescendingFirstOrNull() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/collections/simplifiableCallChain/sortedDescendingFirstOrNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortedDescendingLastOrNull.kt")
|
||||
public void testSortedDescendingLastOrNull() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/collections/simplifiableCallChain/sortedDescendingLastOrNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortedFirstOrNull.kt")
|
||||
public void testSortedFirstOrNull() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/collections/simplifiableCallChain/sortedFirstOrNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sortedLastOrNull.kt")
|
||||
public void testSortedLastOrNull() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/collections/simplifiableCallChain/sortedLastOrNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/inspectionsLocal/collections/simplifiableCallChain/primitiveArray")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user