Introduce inspection for determining if a forEach parameter is unused
#KT-22068 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
c3b2d1829f
commit
e81eee4cc1
@@ -0,0 +1,10 @@
|
||||
fun test() {
|
||||
val items = sequenceOf<Any>()
|
||||
items.forEach {
|
||||
ForEachable().forEach {}
|
||||
}
|
||||
}
|
||||
|
||||
class ForEachable {
|
||||
fun forEach(action: (ForEachable) -> Unit) {}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>3</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Iterated elements are not used in forEach</problem_class>
|
||||
<description>Loop parameter 'it' is unused</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>4</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Iterated elements are not used in forEach</problem_class>
|
||||
<description>Loop parameter 'item' is unused</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>7</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Iterated elements are not used in forEach</problem_class>
|
||||
<description>Loop parameter 'it' is unused</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>correctReference.kt</file>
|
||||
<line>3</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/correctReference.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Iterated elements are not used in forEach</problem_class>
|
||||
<description>Loop parameter 'it' is unused</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.ForEachParameterNotUsedInspection
|
||||
// WITH_RUNTIME
|
||||
@@ -0,0 +1,11 @@
|
||||
fun test() {
|
||||
val items = listOf<Any>()
|
||||
items.forEach { }
|
||||
items.forEach { item -> }
|
||||
items.forEach { doSomething(it) }
|
||||
items.forEach { item -> doSomething(item) }
|
||||
items.forEach { items.forEach { doSomething(it) } }
|
||||
items.forEach { items.forEach { thing -> doSomething(it); doSomething(thing) } }
|
||||
}
|
||||
|
||||
fun doSomething(item: Any) {}
|
||||
Reference in New Issue
Block a user