Add inspection to detect functions with SuccessOrFailure return type
Partial implementation of KT-25621 (no quick-fixes yet)
This commit is contained in:
+92
@@ -0,0 +1,92 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>7</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>9</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>15</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function 'incorrectCatching' returning 'SuccessOrFailure<Double>' without the corresponding function 'incorrect' returning 'Double'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>17</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function 'strangeCatching' returning 'SuccessOrFailure<Boolean>' without the corresponding function 'strange' returning 'Boolean'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>23</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>25</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>31</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function 'classIncorrectCatching' returning 'SuccessOrFailure<Double>' without the corresponding function 'classIncorrect' returning 'Double'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>36</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>38</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
<line>40</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
</problems>
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsSuccessOrFailureInspection
|
||||
@@ -0,0 +1,43 @@
|
||||
package kotlin
|
||||
// NO (constructor)
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
// YES
|
||||
fun getSuccess() = SuccessOrFailure("123")
|
||||
// YES
|
||||
fun getSuccessExplicit(): SuccessOrFailure<Int> = SuccessOrFailure(456)
|
||||
// NO (noCatching available)
|
||||
fun correctCatching() = SuccessOrFailure(true)
|
||||
// NO (not SuccessOrFailure)
|
||||
fun correct() = true
|
||||
// YES
|
||||
fun incorrectCatching() = SuccessOrFailure(3.14)
|
||||
// YES
|
||||
fun strangeCatching() = SuccessOrFailure(false)
|
||||
// YES
|
||||
fun strange() = 1
|
||||
|
||||
class Container {
|
||||
// YES
|
||||
fun classGetSuccess() = SuccessOrFailure("123")
|
||||
// YES
|
||||
fun classGetSuccessExplicit(): SuccessOrFailure<Int> = SuccessOrFailure(456)
|
||||
// NO (noCatching available)
|
||||
fun classCorrectCatching() = SuccessOrFailure(true)
|
||||
// NO (not SuccessOrFailure)
|
||||
fun classCorrect() = true
|
||||
// YES
|
||||
fun classIncorrectCatching() = SuccessOrFailure(3.14)
|
||||
}
|
||||
|
||||
fun test() {
|
||||
// YES
|
||||
fun localGetSuccess() = SuccessOrFailure("123")
|
||||
// YES
|
||||
val anonymous = fun() = SuccessOrFailure(45)
|
||||
// YES
|
||||
val lambda = { SuccessOrFailure(true) }
|
||||
// NO yet
|
||||
fun localCatching() = SuccessOrFailure(2.72)
|
||||
}
|
||||
Reference in New Issue
Block a user