KT-17888 Inspection to warn about suspicious combination of == and ===

This commit is contained in:
Dimach
2017-08-14 21:19:33 +03:00
committed by Dmitry Jemerov
parent 83a1d6e5ca
commit b988fb701d
7 changed files with 142 additions and 0 deletions
@@ -0,0 +1,37 @@
<problems>
<problem>
<file>test.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Suspicious combination of == and ===</problem_class>
<description>Suspicious combination of == and ===</description>
</problem>
<problem>
<file>test.kt</file>
<line>6</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Suspicious combination of == and ===</problem_class>
<description>Suspicious combination of == and ===</description>
</problem>
<problem>
<file>test.kt</file>
<line>7</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Suspicious combination of == and ===</problem_class>
<description>Suspicious combination of == and ===</description>
</problem>
<problem>
<file>test.kt</file>
<line>9</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="test.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Suspicious combination of == and ===</problem_class>
<description>Suspicious combination of == and ===</description>
</problem>
</problems>
@@ -0,0 +1 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.SuspiciousEqualsCombination
@@ -0,0 +1,15 @@
object Main {
fun test() {
val type1 = Main
val type = Main
if (type === CONST1 || type == CONST2 && type === CONST3) return
if (type === CONST1 || type == CONST2 && (type === CONST3)) return
if (type === CONST1 || type == CONST2 && !(type === CONST3)) return
if (type === CONST1 || type1 == CONST2 && type === CONST3) return
if (type === CONST1 || type1 == CONST1 && type === CONST3) return
}
val CONST1 = Main;
val CONST2 = Main;
val CONST3 = Main;
}