Skip to content

Commit

Permalink
Fixes UseRequire issues caught by by fixing a false negative detekt i…
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis committed Jul 18, 2023
1 parent 8991bd9 commit 2be916e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
Expand Up @@ -25,9 +25,9 @@ class WPTooltipViewBehavior : CoordinatorLayout.Behavior<WPTooltipView> {
}

override fun onDependentViewChanged(parent: CoordinatorLayout, child: WPTooltipView, dependency: View): Boolean {
if (child.position != ABOVE) {
require(child.position == ABOVE) {
// Remove this condition if you want to support different TooltipPosition
throw IllegalArgumentException("This behavior only supports TooltipPosition.ABOVE")
"This behavior only supports TooltipPosition.ABOVE"
}

if (dependency.measuredWidth == 0 || child.measuredWidth == 0) {
Expand Down
Expand Up @@ -70,19 +70,16 @@ class StatsViewAllViewModelFactory(
@StringRes private val titleResource: Int
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(StatsViewAllViewModel::class.java)) {
@Suppress("UNCHECKED_CAST")
return StatsViewAllViewModel(
mainDispatcher,
bgDispatcher,
useCase,
statsSiteProvider,
dateSelector,
titleResource
) as T
} else {
throw IllegalArgumentException("ViewModel Not Found")
}
require(!modelClass.isAssignableFrom(StatsViewAllViewModel::class.java)) { "ViewModel Not Found" }
@Suppress("UNCHECKED_CAST")
return StatsViewAllViewModel(
mainDispatcher,
bgDispatcher,
useCase,
statsSiteProvider,
dateSelector,
titleResource
) as T
}

class Builder @Inject constructor(
Expand Down
Expand Up @@ -80,16 +80,13 @@ class AutoSavePostIfNotDraftUseCase @Inject constructor(
callback: OnAutoSavePostIfNotDraftCallback
) {
val remotePostId = RemoteId(remotePostPayload.post.remotePostId)
if (remotePostPayload.post.isLocalDraft) {
throw IllegalArgumentException("Local drafts should not be auto-saved")
}
if (postStatusContinuations.containsKey(remotePostId) ||
autoSaveContinuations.containsKey(remotePostId)
require(!remotePostPayload.post.isLocalDraft) { "Local drafts should not be auto-saved" }
require(
!postStatusContinuations.containsKey(remotePostId) && !autoSaveContinuations.containsKey(remotePostId)
) {
throw IllegalArgumentException(
"This post is already being processed. Make sure not to start an autoSave " +
"or update draft action while another one is going on."
)
"This post is already being processed. Make sure not to start an autoSave " +
"or update draft action while another one is going on."

}
coroutineScope.launch {
val onPostStatusFetched = fetchRemotePostStatus(remotePostPayload)
Expand Down

0 comments on commit 2be916e

Please sign in to comment.