Skip to content

Commit

Permalink
Ignore ResponseBody
Browse files Browse the repository at this point in the history
  • Loading branch information
kozaxinan committed Aug 3, 2023
1 parent c878f58 commit ae4272e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ internal abstract class RetrofitReturnTypeDetector : Detector(), UastScanner {
val returnType = node.returnType
return when {
node.isSuspend() -> findAllInnerFields(node.parameters.last().type as PsiClassType)
returnType is PsiClassType && returnType.isResponseBody() -> emptySet()
returnType is PsiClassType && returnType.isNotUnitOrVoid() ->
findAllInnerFields(returnType)

Expand All @@ -72,6 +73,8 @@ internal abstract class RetrofitReturnTypeDetector : Detector(), UastScanner {
private fun PsiClassType.isNotUnitOrVoid() =
!canonicalText.contains("Unit") && !canonicalText.contains("Void")

private fun PsiClassType.isResponseBody() = canonicalText.contains("ResponseBody")

private fun hasRetrofitAnnotation(method: UMethod): Boolean {
return context
.evaluator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,32 @@ internal class NetworkLayerClassImmutabilityDetectorTest : LintDetectorTest() {
.expectClean()
}

@Test
fun `test kotlin file with RetrofitBody`() {
lint()
.files(
retrofit(),
rxjava(),
kotlin(
"""
package foo
import io.reactivex.Completable
import retrofit2.http.GET
interface Api {
@GET("url")
fun get(): ResponseBody
}
""".trimIndent()
)
)
.issues(ISSUE_NETWORK_LAYER_IMMUTABLE_CLASS_RULE)
.run()
.expectClean()
}

@Test
fun `test kotlin file with val and Parcelable`() {
lint()
Expand Down

0 comments on commit ae4272e

Please sign in to comment.