Browse Source

Enable detekt rules `UnnecessaryParentheses` and cleanup the code.

pull/935/head
Benoit Marty 1 year ago
parent
commit
c75eabbcb0
  1. 2
      features/location/api/src/main/kotlin/io/element/android/features/location/api/internal/ModifierCenterBottomEdge.kt
  2. 3
      features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/loginpassword/LoginPasswordState.kt
  3. 2
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/ExtraPadding.kt
  4. 2
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/html/HtmlDocument.kt
  5. 2
      features/messages/impl/src/test/kotlin/io/element/android/features/messages/attachments/AttachmentsPreviewPresenterTest.kt
  6. 2
      features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/invite/RoomInviteMembersPresenter.kt
  7. 8
      features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/members/RoomMemberListPresenterTests.kt
  8. 10
      features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/components/RoomSummaryRow.kt
  9. 2
      libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt
  10. 2
      libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/atomic/atoms/ElementLogoAtom.kt
  11. 2
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/item/event/EventMessageMapper.kt
  12. 4
      libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/components/SelectedUsersList.kt
  13. 2
      libraries/mediaupload/impl/src/main/kotlin/io/element/android/libraries/mediaupload/ImageCompressor.kt
  14. 2
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/RoomGroupMessageCreator.kt
  15. 2
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannels.kt
  16. 3
      tools/detekt/detekt.yml

2
features/location/api/src/main/kotlin/io/element/android/features/location/api/internal/ModifierCenterBottomEdge.kt

@ -29,7 +29,7 @@ fun Modifier.centerBottomEdge(scope: BoxScope): Modifier = with(scope) { @@ -29,7 +29,7 @@ fun Modifier.centerBottomEdge(scope: BoxScope): Modifier = with(scope) {
Modifier.align { size, space, _ ->
IntOffset(
x = (space.width - size.width) / 2,
y = (space.height / 2) - size.height,
y = space.height / 2 - size.height,
)
}
)

3
features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/loginpassword/LoginPasswordState.kt

@ -30,7 +30,8 @@ data class LoginPasswordState( @@ -30,7 +30,8 @@ data class LoginPasswordState(
) {
val submitEnabled: Boolean
get() = loginAction !is Async.Failure &&
((formState.login.isNotEmpty() && formState.password.isNotEmpty()))
formState.login.isNotEmpty() &&
formState.password.isNotEmpty()
}
@Parcelize

2
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/ExtraPadding.kt

@ -65,7 +65,7 @@ fun TimelineItem.Event.toExtraPadding(): ExtraPadding { @@ -65,7 +65,7 @@ fun TimelineItem.Event.toExtraPadding(): ExtraPadding {
fun ExtraPadding.getStr(fontSize: TextUnit): String {
if (nbChars == 0) return ""
val timestampFontSize = ElementTheme.typography.fontBodyXsRegular.fontSize // 11.sp
val nbOfSpaces = ((timestampFontSize.value / fontSize.value) * nbChars).toInt() + 1
val nbOfSpaces = (timestampFontSize.value / fontSize.value * nbChars).toInt() + 1
// A space and some unbreakable spaces
return " " + "\u00A0".repeat(nbOfSpaces)
}

2
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/html/HtmlDocument.kt

@ -351,7 +351,7 @@ private fun HtmlMxReply( @@ -351,7 +351,7 @@ private fun HtmlMxReply(
Surface(
modifier = modifier
.padding(bottom = 4.dp)
.offset(x = -(8.dp)),
.offset(x = (-8).dp),
color = MaterialTheme.colorScheme.background,
shape = shape,
) {

2
features/messages/impl/src/test/kotlin/io/element/android/features/messages/attachments/AttachmentsPreviewPresenterTest.kt

@ -86,7 +86,7 @@ class AttachmentsPreviewPresenterTest { @@ -86,7 +86,7 @@ class AttachmentsPreviewPresenterTest {
val loadingState = awaitItem()
assertThat(loadingState.sendActionState).isEqualTo(SendActionState.Sending.Processing)
val failureState = awaitItem()
assertThat(failureState.sendActionState).isEqualTo((SendActionState.Failure(failure)))
assertThat(failureState.sendActionState).isEqualTo(SendActionState.Failure(failure))
assertThat(room.sendMediaCount).isEqualTo(0)
failureState.eventSink(AttachmentsPreviewEvents.ClearSendState)
val clearedState = awaitItem()

2
features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/invite/RoomInviteMembersPresenter.kt

@ -93,7 +93,7 @@ class RoomInviteMembersPresenter @Inject constructor( @@ -93,7 +93,7 @@ class RoomInviteMembersPresenter @Inject constructor(
value = if (value.contains(user)) {
value.filterNot { it == user }
} else {
(value + user)
value + user
}.toImmutableList()
}

8
features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/members/RoomMemberListPresenterTests.kt

@ -72,7 +72,7 @@ class RoomMemberListPresenterTests { @@ -72,7 +72,7 @@ class RoomMemberListPresenterTests {
loadedState.eventSink(RoomMemberListEvents.OnSearchActiveChanged(true))
val searchActiveState = awaitItem()
Truth.assertThat((searchActiveState.isSearchActive)).isTrue()
Truth.assertThat(searchActiveState.isSearchActive).isTrue()
}
}
@ -88,7 +88,7 @@ class RoomMemberListPresenterTests { @@ -88,7 +88,7 @@ class RoomMemberListPresenterTests {
val searchActiveState = awaitItem()
loadedState.eventSink(RoomMemberListEvents.UpdateSearchQuery("something"))
val searchQueryUpdatedState = awaitItem()
Truth.assertThat((searchQueryUpdatedState.searchQuery)).isEqualTo("something")
Truth.assertThat(searchQueryUpdatedState.searchQuery).isEqualTo("something")
val searchSearchResultDelivered = awaitItem()
Truth.assertThat(searchSearchResultDelivered.searchResults).isInstanceOf(SearchBarResultState.NoResults::class.java)
}
@ -106,9 +106,9 @@ class RoomMemberListPresenterTests { @@ -106,9 +106,9 @@ class RoomMemberListPresenterTests {
val searchActiveState = awaitItem()
loadedState.eventSink(RoomMemberListEvents.UpdateSearchQuery("Alice"))
val searchQueryUpdatedState = awaitItem()
Truth.assertThat((searchQueryUpdatedState.searchQuery)).isEqualTo("Alice")
Truth.assertThat(searchQueryUpdatedState.searchQuery).isEqualTo("Alice")
val searchSearchResultDelivered = awaitItem()
Truth.assertThat((searchSearchResultDelivered.searchResults)).isInstanceOf(SearchBarResultState.Results::class.java)
Truth.assertThat(searchSearchResultDelivered.searchResults).isInstanceOf(SearchBarResultState.Results::class.java)
Truth.assertThat((searchSearchResultDelivered.searchResults as SearchBarResultState.Results).results.joined.first().displayName)
.isEqualTo("Alice")

10
features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/components/RoomSummaryRow.kt

@ -155,7 +155,7 @@ private fun RowScope.NameAndTimestampRow(room: RoomListRoomSummary) { @@ -155,7 +155,7 @@ private fun RowScope.NameAndTimestampRow(room: RoomListRoomSummary) {
@Composable
private fun RowScope.LastMessageAndIndicatorRow(room: RoomListRoomSummary) {
// Last Message
val attributedLastMessage = (room.lastMessage as? AnnotatedString)
val attributedLastMessage = room.lastMessage as? AnnotatedString
?: AnnotatedString(room.lastMessage.orEmpty().toString())
Text(
modifier = Modifier
@ -186,10 +186,10 @@ class PercentRectangleSizeShape(private val percent: Float) : Shape { @@ -186,10 +186,10 @@ class PercentRectangleSizeShape(private val percent: Float) : Shape {
val halfPercent = percent / 2f
val path = Path().apply {
val rect = Rect(
0f,
size.height * halfPercent,
size.width,
size.height - (size.height * halfPercent)
left = 0f,
top = size.height * halfPercent,
right = size.width,
bottom = size.height * (1 - halfPercent)
)
addRect(rect)
close()

2
libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt

@ -59,7 +59,7 @@ fun Context.isAnimationEnabled(): Boolean { @@ -59,7 +59,7 @@ fun Context.isAnimationEnabled(): Boolean {
}
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O)
fun supportNotificationChannels() = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
fun supportNotificationChannels() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
/**
* Return the application label of the provided package. If not found, the package is returned.

2
libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/atomic/atoms/ElementLogoAtom.kt

@ -138,7 +138,7 @@ fun Modifier.shapeShadow( @@ -138,7 +138,7 @@ fun Modifier.shapeShadow(
val paint = Paint()
val frameworkPaint = paint.asFrameworkPaint()
if (blurRadius != 0.dp) {
frameworkPaint.maskFilter = (BlurMaskFilter(blurRadius.toPx(), BlurMaskFilter.Blur.NORMAL))
frameworkPaint.maskFilter = BlurMaskFilter(blurRadius.toPx(), BlurMaskFilter.Blur.NORMAL)
}
frameworkPaint.color = color.toArgb()

2
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/item/event/EventMessageMapper.kt

@ -45,7 +45,7 @@ class EventMessageMapper { @@ -45,7 +45,7 @@ class EventMessageMapper {
fun map(message: Message): MessageContent = message.use {
val type = it.msgtype().use(this::mapMessageType)
val inReplyToId = it.inReplyTo()?.eventId?.let(::EventId)
val inReplyToEvent: InReplyTo? = (it.inReplyTo()?.event)?.use { details ->
val inReplyToEvent: InReplyTo? = it.inReplyTo()?.event?.use { details ->
when (details) {
is RepliedToEventDetails.Ready -> {
val senderProfile = details.senderProfile as? ProfileDetails.Ready

4
libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/components/SelectedUsersList.kt

@ -88,7 +88,7 @@ fun SelectedUsersList( @@ -88,7 +88,7 @@ fun SelectedUsersList(
val maxVisibleUsers = rowWidth / userWidthWithSpacing
// Round down the number of visible users to end with a state where one is half visible
val targetFraction = (userWidth / 2) / userWidthWithSpacing
val targetFraction = userWidth / 2 / userWidthWithSpacing
val targetUsers = floor(maxVisibleUsers - targetFraction) + targetFraction
// Work out how much extra spacing we need to reduce the number of users that much, then split it evenly amongst the visible users
@ -153,7 +153,7 @@ private fun ContentToPreview() { @@ -153,7 +153,7 @@ private fun ContentToPreview() {
SelectedUsersList(
selectedUsers = aMatrixUserList().take(6).toImmutableList(),
modifier = Modifier
.width((200 + (i * 20)).dp)
.width((200 + (i * 20).dp)
.border(1.dp, Color.Red)
)
}

2
libraries/mediaupload/impl/src/main/kotlin/io/element/android/libraries/mediaupload/ImageCompressor.kt

@ -91,7 +91,7 @@ class ImageCompressor @Inject constructor( @@ -91,7 +91,7 @@ class ImageCompressor @Inject constructor(
) {
val (width, height) = when (resizeMode) {
is ResizeMode.Approximate -> resizeMode.desiredWidth to resizeMode.desiredHeight
is ResizeMode.Strict -> (resizeMode.maxWidth / 2) to (resizeMode.maxHeight / 2)
is ResizeMode.Strict -> resizeMode.maxWidth / 2 to resizeMode.maxHeight / 2
is ResizeMode.None -> return
}
// Read bounds only

2
libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/RoomGroupMessageCreator.kt

@ -69,7 +69,7 @@ class RoomGroupMessageCreator @Inject constructor( @@ -69,7 +69,7 @@ class RoomGroupMessageCreator @Inject constructor(
val lastMessageTimestamp = events.last().timestamp
val smartReplyErrors = events.filter { it.isSmartReplyError() }
val messageCount = (events.size - smartReplyErrors.size)
val messageCount = events.size - smartReplyErrors.size
val meta = RoomNotification.Message.Meta(
summaryLine = createRoomMessagesGroupSummaryLine(events, roomName, roomIsDirect = !roomIsGroup),
messageCount = messageCount,

2
libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannels.kt

@ -162,7 +162,7 @@ class NotificationChannels @Inject constructor( @@ -162,7 +162,7 @@ class NotificationChannels @Inject constructor(
private const val CALL_NOTIFICATION_CHANNEL_ID = "CALL_NOTIFICATION_CHANNEL_ID_V2"
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O)
private fun supportNotificationChannels() = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
private fun supportNotificationChannels() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
fun openSystemSettingsForSilentCategory(activity: Activity) {
activity.startNotificationChannelSettingsIntent(SILENT_NOTIFICATION_CHANNEL_ID)

3
tools/detekt/detekt.yml

@ -16,6 +16,9 @@ style: @@ -16,6 +16,9 @@ style:
active: true
UnusedParameter:
active: true
UnnecessaryParentheses:
active: true
allowForUnclearPrecedence: false
UnusedImports:
active: true
UnusedPrivateProperty:

Loading…
Cancel
Save