Skip to content

Commit

Permalink
Upgrade ktlint and add twitter compose rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal authored and greyson-signal committed Feb 14, 2023
1 parent 52e9b31 commit 605289a
Show file tree
Hide file tree
Showing 174 changed files with 574 additions and 373 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ root = true

[*.kt]
indent_size = 2
twitter_compose_allowed_composition_locals=LocalExtendedColors
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ wire {

ktlint {
// Use a newer version to resolve https://github.com/JLLeitschuh/ktlint-gradle/issues/507
version = "0.43.2"
version = "0.47.1"
}

def canonicalVersionCode = 1213
Expand Down Expand Up @@ -596,6 +596,7 @@ dependencies {
androidTestUtil testLibs.androidx.test.orchestrator

implementation project(':core-ui')
ktlintRuleset libs.ktlint.twitter.compose
}

def getLastCommitTimestamp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ChangeNumberViewModelTest {

InstrumentationApplicationDependencyProvider.addMockWebRequestHandlers(
Get("/v1/devices") { MockResponse().success(MockProvider.primaryOnlyDeviceList) },
Put("/v1/accounts/number") { MockResponse().failure(500) },
Put("/v1/accounts/number") { MockResponse().failure(500) }
)

// WHEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ConversationItemPreviewer {
sentTimeMillis = System.currentTimeMillis(),
serverTimeMillis = System.currentTimeMillis(),
receivedTimeMillis = System.currentTimeMillis(),
attachments = PointerAttachment.forPointers(Optional.of(attachments)),
attachments = PointerAttachment.forPointers(Optional.of(attachments))
)

SignalDatabase.messages.insertSecureDecryptedMessageInbox(message, SignalDatabase.threads.getOrCreateThreadIdFor(other)).get()
Expand All @@ -88,7 +88,7 @@ class ConversationItemPreviewer {
sentTimeMillis = System.currentTimeMillis(),
serverTimeMillis = System.currentTimeMillis(),
receivedTimeMillis = System.currentTimeMillis(),
attachments = PointerAttachment.forPointers(Optional.of(attachments)),
attachments = PointerAttachment.forPointers(Optional.of(attachments))
)

val insert = SignalDatabase.messages.insertSecureDecryptedMessageInbox(message, SignalDatabase.threads.getOrCreateThreadIdFor(other)).get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MmsTableTest_stories {
sentTimeMillis = 2,
serverTimeMillis = 2,
receivedTimeMillis = 2,
storyType = StoryType.STORY_WITH_REPLIES,
storyType = StoryType.STORY_WITH_REPLIES
),
-1L
).get().messageId
Expand Down Expand Up @@ -160,7 +160,7 @@ class MmsTableTest_stories {
sentTimeMillis = System.currentTimeMillis(),
serverTimeMillis = 2,
receivedTimeMillis = 2,
storyType = StoryType.STORY_WITH_REPLIES,
storyType = StoryType.STORY_WITH_REPLIES
),
-1L
).get().messageId
Expand All @@ -174,7 +174,7 @@ class MmsTableTest_stories {
sentTimeMillis = System.currentTimeMillis(),
serverTimeMillis = 2,
receivedTimeMillis = 2,
storyType = StoryType.STORY_WITH_REPLIES,
storyType = StoryType.STORY_WITH_REPLIES
),
-1L
).get().messageId
Expand Down Expand Up @@ -219,7 +219,7 @@ class MmsTableTest_stories {
sentTimeMillis = 200,
serverTimeMillis = 2,
receivedTimeMillis = 2,
storyType = StoryType.STORY_WITH_REPLIES,
storyType = StoryType.STORY_WITH_REPLIES
),
-1L
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
PnpChangeSet(
id = PnpIdResolver.PnpNoopId(result.id),
operations = linkedSetOf(
PnpOperation.SetE164(result.id, E164_A),
PnpOperation.SetE164(result.id, E164_A)
)
),
result.changeSet
Expand Down Expand Up @@ -407,7 +407,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
val result = applyAndAssert(
listOf(
Input(E164_A, null, null),
Input(null, PNI_A, null),
Input(null, PNI_A, null)
),
Update(E164_A, PNI_A, null),
Output(E164_A, PNI_A, null)
Expand All @@ -432,7 +432,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
val result = applyAndAssert(
listOf(
Input(E164_A, null, null),
Input(null, PNI_A, null),
Input(null, PNI_A, null)
),
Update(E164_A, PNI_A, ACI_A),
Output(E164_A, PNI_A, ACI_A)
Expand Down Expand Up @@ -461,7 +461,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
val result = applyAndAssert(
listOf(
Input(E164_A, null, null),
Input(E164_B, PNI_A, null),
Input(E164_B, PNI_A, null)
),
Update(E164_A, PNI_A, null),
Output(E164_A, PNI_A, null)
Expand All @@ -475,7 +475,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
PnpOperation.SetPni(
recipientId = result.firstId,
pni = PNI_A
),
)
)
),
result.changeSet
Expand All @@ -487,7 +487,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
val result = applyAndAssert(
listOf(
Input(E164_A, PNI_B, null),
Input(null, PNI_A, null),
Input(null, PNI_A, null)
),
Update(E164_A, PNI_A, null),
Output(E164_A, PNI_A, null)
Expand All @@ -501,7 +501,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
PnpOperation.Merge(
primaryId = result.firstId,
secondaryId = result.secondId
),
)
)
),
result.changeSet
Expand All @@ -513,7 +513,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
val result = applyAndAssert(
listOf(
Input(E164_A, PNI_B, null),
Input(E164_B, PNI_A, null),
Input(E164_B, PNI_A, null)
),
Update(E164_A, PNI_A, null),
Output(E164_A, PNI_A, null)
Expand All @@ -536,7 +536,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
val result = applyAndAssert(
listOf(
Input(E164_A, PNI_B, null, pniSession = true),
Input(E164_B, PNI_A, null, pniSession = true),
Input(E164_B, PNI_A, null, pniSession = true)
),
Update(E164_A, PNI_A, null),
Output(E164_A, PNI_A, null)
Expand All @@ -561,7 +561,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
val result = applyAndAssert(
listOf(
Input(E164_A, PNI_A, null),
Input(null, null, ACI_A),
Input(null, null, ACI_A)
),
Update(E164_A, PNI_A, ACI_A),
Output(E164_A, PNI_A, ACI_A)
Expand All @@ -574,7 +574,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
PnpOperation.Merge(
primaryId = result.secondId,
secondaryId = result.firstId
),
)
)
),
result.changeSet
Expand All @@ -586,7 +586,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
val result = applyAndAssert(
listOf(
Input(E164_B, PNI_A, null),
Input(null, null, ACI_A),
Input(null, null, ACI_A)
),
Update(E164_A, PNI_A, ACI_A),
Output(E164_A, PNI_A, ACI_A)
Expand All @@ -599,11 +599,11 @@ class RecipientTableTest_processPnpTupleToChangeSet {
PnpOperation.RemovePni(result.firstId),
PnpOperation.SetPni(
recipientId = result.secondId,
pni = PNI_A,
pni = PNI_A
),
PnpOperation.SetE164(
recipientId = result.secondId,
e164 = E164_A,
e164 = E164_A
)
)
),
Expand All @@ -616,7 +616,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
val result = applyAndAssert(
listOf(
Input(E164_B, PNI_A, null),
Input(E164_C, null, ACI_A),
Input(E164_C, null, ACI_A)
),
Update(E164_A, PNI_A, ACI_A),
Output(E164_A, PNI_A, ACI_A)
Expand All @@ -629,11 +629,11 @@ class RecipientTableTest_processPnpTupleToChangeSet {
PnpOperation.RemovePni(result.firstId),
PnpOperation.SetPni(
recipientId = result.secondId,
pni = PNI_A,
pni = PNI_A
),
PnpOperation.SetE164(
recipientId = result.secondId,
e164 = E164_A,
e164 = E164_A
),
PnpOperation.ChangeNumberInsert(
recipientId = result.secondId,
Expand All @@ -651,7 +651,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
val result = applyAndAssert(
listOf(
Input(E164_A, PNI_A, null),
Input(E164_B, PNI_B, ACI_A),
Input(E164_B, PNI_B, ACI_A)
),
Update(E164_A, PNI_A, ACI_A),
Output(E164_A, PNI_A, ACI_A)
Expand Down Expand Up @@ -683,7 +683,7 @@ class RecipientTableTest_processPnpTupleToChangeSet {
val result = applyAndAssert(
listOf(
Input(E164_A, PNI_A, null),
Input(E164_B, null, ACI_A),
Input(E164_B, null, ACI_A)
),
Update(E164_A, PNI_A, ACI_A),
Output(E164_A, PNI_A, ACI_A)
Expand Down Expand Up @@ -726,7 +726,8 @@ class RecipientTableTest_processPnpTupleToChangeSet {

private fun insertMockSessionFor(account: ServiceId, address: ServiceId) {
SignalDatabase.rawDatabase.insert(
SessionTable.TABLE_NAME, null,
SessionTable.TABLE_NAME,
null,
contentValuesOf(
SessionTable.ACCOUNT_ID to account.toString(),
SessionTable.ADDRESS to address.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ class StorySendTableTest {

messageId1 = MmsHelper.insert(
recipient = distributionListRecipient1,
storyType = StoryType.STORY_WITHOUT_REPLIES,
storyType = StoryType.STORY_WITHOUT_REPLIES
)

messageId2 = MmsHelper.insert(
recipient = distributionListRecipient2,
storyType = StoryType.STORY_WITH_REPLIES,
storyType = StoryType.STORY_WITH_REPLIES
)

messageId3 = MmsHelper.insert(
recipient = distributionListRecipient3,
storyType = StoryType.STORY_WITHOUT_REPLIES,
storyType = StoryType.STORY_WITHOUT_REPLIES
)

recipients6to15 = recipients1to10.takeLast(5) + recipients11to20.take(5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class PreKeysSyncJobTest {
Put("/v2/keys/signed?identity=pni") { r ->
pniSignedPreKey = r.parsedRequestBody()
MockResponse().success()
},
}
)

// WHEN
Expand Down Expand Up @@ -107,7 +107,7 @@ class PreKeysSyncJobTest {

InstrumentationApplicationDependencyProvider.addMockWebRequestHandlers(
Get("/v2/keys?identity=aci") { MockResponse().success(PreKeyStatus(100)) },
Get("/v2/keys?identity=pni") { MockResponse().success(PreKeyStatus(100)) },
Get("/v2/keys?identity=pni") { MockResponse().success(PreKeyStatus(100)) }
)

// WHEN
Expand All @@ -134,7 +134,7 @@ class PreKeysSyncJobTest {

InstrumentationApplicationDependencyProvider.addMockWebRequestHandlers(
Get("/v2/keys?identity=aci") { MockResponse().success(PreKeyStatus(100)) },
Put("/v2/keys/signed?identity=pni") { MockResponse().success() },
Put("/v2/keys/signed?identity=pni") { MockResponse().success() }
)

// WHEN
Expand Down Expand Up @@ -173,7 +173,7 @@ class PreKeysSyncJobTest {
Put("/v2/keys/?identity=pni") { r ->
pniPreKeyStateRequest = r.parsedRequestBody()
MockResponse().success()
},
}
)

// WHEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RxTestSchedulerRule(
val ioTestScheduler: TestScheduler = defaultTestScheduler,
val computationTestScheduler: TestScheduler = defaultTestScheduler,
val singleTestScheduler: TestScheduler = defaultTestScheduler,
val newThreadTestScheduler: TestScheduler = defaultTestScheduler,
val newThreadTestScheduler: TestScheduler = defaultTestScheduler
) : ExternalResource() {

override fun before() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TestProtos private constructor() {
}

fun metadata(
address: AddressProto = address().build(),
address: AddressProto = address().build()
): MetadataProto.Builder {
return MetadataProto.newBuilder()
.setAddress(address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.io.IOException
*/
class SignalBackupAgent : BackupAgent() {
private val items: List<AndroidBackupItem> = listOf(
KbsAuthTokens,
KbsAuthTokens
)

override fun onBackup(oldState: ParcelFileDescriptor?, data: BackupDataOutput, newState: ParcelFileDescriptor) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/thoughtcrime/securesms/avatar/Avatar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sealed class Avatar(
data class Text(
val text: String,
val color: Avatars.ColorPair,
override val databaseId: DatabaseId,
override val databaseId: DatabaseId
) : Avatar(databaseId) {
override fun withDatabaseId(databaseId: DatabaseId): Avatar {
return copy(databaseId = databaseId)
Expand All @@ -35,7 +35,7 @@ sealed class Avatar(
data class Vector(
val key: String,
val color: Avatars.ColorPair,
override val databaseId: DatabaseId,
override val databaseId: DatabaseId
) : Avatar(databaseId) {
override fun withDatabaseId(databaseId: DatabaseId): Avatar {
return copy(databaseId = databaseId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object Avatars {
"avatar_sunset" to DefaultAvatar(R.drawable.ic_avatar_sunset, "A120"),
"avatar_surfboard" to DefaultAvatar(R.drawable.ic_avatar_surfboard, "A110"),
"avatar_soccerball" to DefaultAvatar(R.drawable.ic_avatar_soccerball, "A130"),
"avatar_football" to DefaultAvatar(R.drawable.ic_avatar_football, "A220"),
"avatar_football" to DefaultAvatar(R.drawable.ic_avatar_football, "A220")
)

@DrawableRes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ class AvatarPickerFragment : Fragment(R.layout.avatar_picker_fragment) {
val selectedPosition = items.indexOfFirst { it.isSelected }

adapter.submitList(items) {
if (selectedPosition > -1)
if (selectedPosition > -1) {
recycler.smoothScrollToPosition(selectedPosition)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.thoughtcrime.securesms.avatar.AvatarColorItem
import org.thoughtcrime.securesms.avatar.Avatars

data class TextAvatarCreationState(
val currentAvatar: Avatar.Text,
val currentAvatar: Avatar.Text
) {
fun colors(): List<AvatarColorItem> = Avatars.colors.map { AvatarColorItem(it, currentAvatar.color == it) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.thoughtcrime.securesms.avatar.AvatarColorItem
import org.thoughtcrime.securesms.avatar.Avatars

data class VectorAvatarCreationState(
val currentAvatar: Avatar.Vector,
val currentAvatar: Avatar.Vector
) {
fun colors(): List<AvatarColorItem> = Avatars.colors.map { AvatarColorItem(it, currentAvatar.color == it) }
}

0 comments on commit 605289a

Please sign in to comment.