Skip to content

Commit 9cbc9de

Browse files
committed
style: ktlint updates
1 parent ed4dd92 commit 9cbc9de

35 files changed

Lines changed: 1346 additions & 1005 deletions

File tree

.editorconfig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
root = true
22

33
[*.{kt,kts}]
4-
disabled_rules = filename
5-
max_line_length = off
64
insert_final_newline = true
75
ij_kotlin_name_count_to_use_star_import = 999
86
ij_kotlin_name_count_to_use_star_import_for_members = 999
97
ij_java_class_count_to_use_import_on_demand = 999
108
ij_kotlin_allow_trailing_comma = true
119
ij_kotlin_allow_trailing_comma_on_call_site = true
10+
11+
ktlint_ignore_back_ticked_identifier = true
12+
13+
# Disabled annotation formatting so @Inject constructor() doesn't go to new line
14+
ktlint_standard_annotation = disabled

android/src/main/java/com/kroger/telemetry/android/facet/ToastFacet.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ package com.kroger.telemetry.android.facet
2626

2727
import com.kroger.telemetry.facet.Facet
2828

29-
public data class ToastFacet(val message: String) : Facet
29+
public data class ToastFacet(
30+
val message: String,
31+
) : Facet

android/src/main/java/com/kroger/telemetry/android/relay/LogRelay.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ private val logPrinter: (PrintRelay.Message) -> Unit = { message ->
4242
Log.println(message.significance.toLogPriority(), message.tag, message.value)
4343
}
4444

45-
private fun Significance.toLogPriority(): Int = when (this) {
46-
Significance.VERBOSE -> Log.VERBOSE
47-
Significance.DEBUG -> Log.DEBUG
48-
Significance.INFORMATIONAL -> Log.INFO
49-
Significance.WARNING -> Log.WARN
50-
Significance.ERROR -> Log.ERROR
51-
Significance.INTERNAL_ERROR -> Log.ERROR
52-
}
45+
private fun Significance.toLogPriority(): Int =
46+
when (this) {
47+
Significance.VERBOSE -> Log.VERBOSE
48+
Significance.DEBUG -> Log.DEBUG
49+
Significance.INFORMATIONAL -> Log.INFO
50+
Significance.WARNING -> Log.WARN
51+
Significance.ERROR -> Log.ERROR
52+
Significance.INTERNAL_ERROR -> Log.ERROR
53+
}

android/src/main/java/com/kroger/telemetry/android/relay/ToastRelay.kt

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public class ToastRelay internal constructor(
4444
private val toaster: Toaster,
4545
public val configuration: Configuration,
4646
) : Relay {
47-
4847
/**
4948
* A set of configurable options for a ToastRelay.
5049
* @property toastLength Should be one of [Toast.LENGTH_SHORT] or [Toast.LENGTH_LONG]. Defaults to short.
@@ -83,31 +82,42 @@ public class ToastRelay internal constructor(
8382

8483
override suspend fun process(event: Event) {
8584
val toastFacets = event.facets.filterIsInstance(ToastFacet::class.java)
86-
val shouldToastWithoutToastFacet = event.hasHighEnoughSignificance() &&
87-
configuration.toastSignificantEvents
85+
val shouldToastWithoutToastFacet =
86+
event.hasHighEnoughSignificance() &&
87+
configuration.toastSignificantEvents
8888
val shouldToast = toastFacets.isNotEmpty() || shouldToastWithoutToastFacet
8989
if (shouldToast && configuration.enabled) {
9090
val message = toastFacets.firstOrNull()?.message ?: event.description
91-
val correctedLength = when (configuration.toastLength) {
92-
Toast.LENGTH_SHORT -> configuration.toastLength
93-
Toast.LENGTH_LONG -> configuration.toastLength
94-
else -> Toast.LENGTH_SHORT
95-
}
91+
val correctedLength =
92+
when (configuration.toastLength) {
93+
Toast.LENGTH_SHORT -> configuration.toastLength
94+
Toast.LENGTH_LONG -> configuration.toastLength
95+
else -> Toast.LENGTH_SHORT
96+
}
9697
toaster.toast(message, correctedLength)
9798
}
9899
}
99100

100-
private fun Event.hasHighEnoughSignificance(): Boolean = facets
101-
.filterIsInstance(Significance::class.java)
102-
.any { it >= configuration.minimumSignificance }
101+
private fun Event.hasHighEnoughSignificance(): Boolean =
102+
facets
103+
.filterIsInstance(Significance::class.java)
104+
.any { it >= configuration.minimumSignificance }
103105
}
104106

105107
internal interface Toaster {
106-
suspend fun toast(message: String, length: Int)
108+
suspend fun toast(
109+
message: String,
110+
length: Int,
111+
)
107112
}
108113

109-
private class ToasterImpl(private val context: Context) : Toaster {
110-
override suspend fun toast(message: String, length: Int) = withContext(Dispatchers.Main) {
114+
private class ToasterImpl(
115+
private val context: Context,
116+
) : Toaster {
117+
override suspend fun toast(
118+
message: String,
119+
length: Int,
120+
) = withContext(Dispatchers.Main) {
111121
Toast.makeText(context, message, length).show()
112122
}
113123
}
@@ -119,8 +129,9 @@ private interface Toggles {
119129
private fun sampleToastConfig() {
120130
val propertyChangeConfig = ToastRelay.Configuration.Default(toastSignificantEvents = true)
121131

122-
class PropertyBehaviorChangeConfig(private val toggles: Toggles) :
123-
ToastRelay.Configuration by ToastRelay.Configuration.Default() {
132+
class PropertyBehaviorChangeConfig(
133+
private val toggles: Toggles,
134+
) : ToastRelay.Configuration by ToastRelay.Configuration.Default() {
124135
override var enabled: Boolean
125136
get() = toggles["ToastRelay Toggle"]
126137
set(_) = Unit

android/src/test/java/com/kroger/telemetry/android/relay/ToastRelayTest.kt

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ internal class ToastRelayTest {
3939
private class FakeToaster : Toaster {
4040
var didToast = false
4141
var fakeFunToast: (String, Int) -> Unit = { _, _ -> didToast = true }
42-
override suspend fun toast(message: String, length: Int) = fakeFunToast(message, length)
42+
43+
override suspend fun toast(
44+
message: String,
45+
length: Int,
46+
) = fakeFunToast(message, length)
4347
}
4448

4549
private data class TestConfig(
@@ -92,10 +96,11 @@ internal class ToastRelayTest {
9296
@Test
9397
fun `GIVEN toast relay configured to toast all WHEN event received no significance THEN event is not toasted`() =
9498
runTest {
95-
val config = TestConfig().copy(
96-
toastSignificantEvents = true,
97-
minimumSignificance = Significance.ERROR,
98-
)
99+
val config =
100+
TestConfig().copy(
101+
toastSignificantEvents = true,
102+
minimumSignificance = Significance.ERROR,
103+
)
99104
val relay = config.getRelay()
100105

101106
relay.process(
@@ -110,10 +115,11 @@ internal class ToastRelayTest {
110115
@Test
111116
fun `GIVEN toast relay configured to toast all WHEN event received with lower than minimum significance THEN event is not toasted`() =
112117
runTest {
113-
val config = TestConfig().copy(
114-
toastSignificantEvents = true,
115-
minimumSignificance = Significance.ERROR,
116-
)
118+
val config =
119+
TestConfig().copy(
120+
toastSignificantEvents = true,
121+
minimumSignificance = Significance.ERROR,
122+
)
117123
val relay = config.getRelay()
118124

119125
relay.process(
@@ -128,10 +134,11 @@ internal class ToastRelayTest {
128134
@Test
129135
fun `GIVEN toast relay configured to toast all WHEN event received with minimum significance THEN event is toasted`() =
130136
runTest {
131-
val config = TestConfig().copy(
132-
toastSignificantEvents = true,
133-
minimumSignificance = Significance.ERROR,
134-
)
137+
val config =
138+
TestConfig().copy(
139+
toastSignificantEvents = true,
140+
minimumSignificance = Significance.ERROR,
141+
)
135142
val relay = config.getRelay()
136143

137144
relay.process(
@@ -182,8 +189,9 @@ internal class ToastRelayTest {
182189
fun `GIVEN config with mutable backing data WHEN backing data is changed THEN config reflects update`() {
183190
val mutableBackingInstance = mutableListOf(false)
184191

185-
class MutableConfig(private val mutableBackingProp: List<Boolean>) :
186-
ToastRelay.Configuration by ToastRelay.Configuration.Default() {
192+
class MutableConfig(
193+
private val mutableBackingProp: List<Boolean>,
194+
) : ToastRelay.Configuration by ToastRelay.Configuration.Default() {
187195
override var enabled: Boolean
188196
get() = mutableBackingProp.first()
189197
set(_) = Unit

context-aware/src/main/java/com/kroger/telemetry/contextaware/ContextAwareFacetResolver.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import com.kroger.telemetry.facet.FacetResolver
3030
import com.kroger.telemetry.facet.UnresolvedFacet
3131
import javax.inject.Inject
3232

33-
public class ContextAwareFacetResolver @Inject constructor(private val context: Context) :
34-
FacetResolver {
33+
public class ContextAwareFacetResolver @Inject constructor(
34+
private val context: Context,
35+
) : FacetResolver {
3536
override fun getType(): Class<ContextAwareFacet> = ContextAwareFacet::class.java
3637

3738
override fun resolve(unresolvedFacet: UnresolvedFacet): List<Facet> =

context-aware/src/test/java/com/kroger/telemetry/contextaware/ContextAwareFacetResolverTest.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import org.junit.jupiter.api.BeforeEach
3232
import org.junit.jupiter.api.Test
3333

3434
public class ContextAwareFacetResolverTest {
35-
3635
private val context: Context = mockk()
3736
private lateinit var contextAwareFacetResolver: ContextAwareFacetResolver
3837

@@ -53,11 +52,10 @@ public class ContextAwareFacetResolverTest {
5352
@Test
5453
public fun `Given an ContextAwareFacetResolver, When resolve is called on a ContextAwareFacet, Then return the resolved Facet`() {
5554
val testFacet = object : Facet {}
56-
val testUnresolvedFacet = object : ContextAwareFacet {
57-
override fun resolve(context: Context): Facet {
58-
return testFacet
55+
val testUnresolvedFacet =
56+
object : ContextAwareFacet {
57+
override fun resolve(context: Context): Facet = testFacet
5958
}
60-
}
6159

6260
val sut = contextAwareFacetResolver.resolve(testUnresolvedFacet)
6361

firebase/src/androidTest/java/com/kroger/telemetry/firebase/FirebaseAnalyticsRelayTest.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("ktlint:standard:max-line-length")
2+
13
package com.kroger.telemetry.firebase
24

35
import androidx.core.os.bundleOf
@@ -9,7 +11,6 @@ import org.junit.runner.RunWith
911

1012
@RunWith(AndroidJUnit4::class)
1113
internal class FirebaseAnalyticsRelayTest {
12-
1314
@Test
1415
fun given_event_with_firebase_facet_with_data_WHEN_recorded_THEN_data_matches_in_logged_event() =
1516
runBlocking {
@@ -19,11 +20,12 @@ internal class FirebaseAnalyticsRelayTest {
1920
val val1 = "val1"
2021
val val2 = 2
2122

22-
val facetWithData = object : DeveloperMetricsFacet {
23-
override val eventName: String = fakeName
24-
override val compute: () -> Map<String, Any?> =
25-
{ mapOf<String, Any?>(key1 to val1, key2 to val2) }
26-
}
23+
val facetWithData =
24+
object : DeveloperMetricsFacet {
25+
override val eventName: String = fakeName
26+
override val compute: () -> Map<String, Any?> =
27+
{ mapOf<String, Any?>(key1 to val1, key2 to val2) }
28+
}
2729

2830
val bundleToCompare = bundleOf(key1 to val1, key2 to val2)
2931

firebase/src/main/java/com/kroger/telemetry/firebase/CrashlyticsWrapper.kt

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ package com.kroger.telemetry.firebase
3232
* @sample crashlyticsWrapperImplementation
3333
*/
3434
public interface CrashlyticsWrapper {
35-
3635
/**
3736
* Records a custom key and value to be associated with subsequent fatal and non-fatal reports. Multiple calls to this method
3837
* with the same key will update the value for that key. The value of any key at the time of a fatal or non-fatal event will
@@ -44,7 +43,10 @@ public interface CrashlyticsWrapper {
4443
*
4544
*@param value A value to be associated with the given key
4645
*/
47-
public fun setCustomKey(key: String, value: String)
46+
public fun setCustomKey(
47+
key: String,
48+
value: String,
49+
)
4850

4951
/**
5052
* Records a custom key and value to be associated with subsequent fatal and non-fatal reports. Multiple calls to this method
@@ -57,7 +59,10 @@ public interface CrashlyticsWrapper {
5759
*
5860
*@param value A value to be associated with the given key
5961
*/
60-
public fun setCustomKey(key: String, value: Boolean)
62+
public fun setCustomKey(
63+
key: String,
64+
value: Boolean,
65+
)
6166

6267
/**
6368
* Records a custom key and value to be associated with subsequent fatal and non-fatal reports. Multiple calls to this method
@@ -70,7 +75,10 @@ public interface CrashlyticsWrapper {
7075
*
7176
*@param value A value to be associated with the given key
7277
*/
73-
public fun setCustomKey(key: String, value: Int)
78+
public fun setCustomKey(
79+
key: String,
80+
value: Int,
81+
)
7482

7583
/**
7684
* Records a custom key and value to be associated with subsequent fatal and non-fatal reports. Multiple calls to this method
@@ -83,7 +91,10 @@ public interface CrashlyticsWrapper {
8391
*
8492
*@param value A value to be associated with the given key
8593
*/
86-
public fun setCustomKey(key: String, value: Long)
94+
public fun setCustomKey(
95+
key: String,
96+
value: Long,
97+
)
8798

8899
/**
89100
* Records a custom key and value to be associated with subsequent fatal and non-fatal reports. Multiple calls to this method
@@ -96,7 +107,10 @@ public interface CrashlyticsWrapper {
96107
*
97108
*@param value A value to be associated with the given key
98109
*/
99-
public fun setCustomKey(key: String, value: Float)
110+
public fun setCustomKey(
111+
key: String,
112+
value: Float,
113+
)
100114

101115
/**
102116
* Records a custom key and value to be associated with subsequent fatal and non-fatal reports. Multiple calls to this method
@@ -109,7 +123,10 @@ public interface CrashlyticsWrapper {
109123
*
110124
*@param value A value to be associated with the given key
111125
*/
112-
public fun setCustomKey(key: String, value: Double)
126+
public fun setCustomKey(
127+
key: String,
128+
value: Double,
129+
)
113130

114131
/**
115132
* Records a non-fatal report to send to Crashlytics.

firebase/src/main/java/com/kroger/telemetry/firebase/FirebaseAnalyticsRelay.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ import javax.inject.Inject
4040
public class FirebaseAnalyticsRelay @Inject constructor(
4141
private val firebaseAnalytics: FirebaseAnalytics,
4242
) : Relay by Relay.buildTypedRelay<DeveloperMetricsFacet>(
43-
{ facet ->
44-
firebaseAnalytics.logEvent(facet.eventName, facet.compute()?.toBundle())
45-
},
46-
)
43+
{ facet ->
44+
firebaseAnalytics.logEvent(facet.eventName, facet.compute()?.toBundle())
45+
},
46+
)
4747

4848
internal fun Map<String, Any?>.toBundle(): Bundle = bundleOf(*this.toList().toTypedArray())

0 commit comments

Comments
 (0)