Skip to content

Commit 2442538

Browse files
chore(lint): Add ktlint (#4406)
* Adds ktlint * Fixes kotlin lint issues --------- Co-authored-by: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com>
1 parent 07851c7 commit 2442538

File tree

13 files changed

+343
-258
lines changed

13 files changed

+343
-258
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
"clean": "lerna run clean",
88
"circularDepCheck": "lerna run circularDepCheck",
99
"test": "lerna run test",
10-
"fix": "run-s fix:lerna fix:android fix:clang fix:swift",
10+
"fix": "run-s fix:lerna fix:android fix:clang fix:swift fix:kotlin",
1111
"fix:lerna": "lerna run fix",
1212
"fix:android": "run-s 'java:format fix' java:pmd",
1313
"fix:clang": "run-s 'clang:format fix'",
1414
"fix:swift": "run-s 'swift:lint fix'",
15-
"lint": "run-s lint:lerna lint:android lint:clang lint:swift",
15+
"fix:kotlin": "npx ktlint --relative --format '!**/node_modules/**'",
16+
"lint": "run-s lint:lerna lint:android lint:clang lint:swift lint:kotlin",
1617
"lint:lerna": "lerna run lint",
1718
"lint:android": "run-s 'java:format lint' java:pmd",
1819
"lint:clang": "run-s 'clang:format lint'",
1920
"lint:swift": "run-s 'swift:lint lint'",
21+
"lint:kotlin": "npx ktlint --relative '!**/node_modules/**'",
2022
"java:format": "./scripts/google-java-format.sh",
2123
"java:pmd": "./scripts/pmd.sh",
2224
"clang:format": "./scripts/clang-format.sh",
@@ -27,6 +29,7 @@
2729
},
2830
"devDependencies": {
2931
"@expo/swiftlint": "^0.57.1",
32+
"@naturalcycles/ktlint": "^1.13.0",
3033
"@sentry/cli": "2.40.0",
3134
"clang-format": "^1.8.0",
3235
"downlevel-dts": "^0.11.0",

packages/core/RNSentryAndroidTester/app/src/androidTest/java/io/sentry/react/RNSentryModuleImplTest.kt

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import org.junit.runners.JUnit4
1919

2020
@RunWith(JUnit4::class)
2121
class RNSentryModuleImplTest {
22-
2322
private lateinit var module: RNSentryModuleImpl
2423
private lateinit var context: Context
2524

@@ -35,12 +34,13 @@ class RNSentryModuleImplTest {
3534
fun fetchNativeDeviceContextsWithNullContext() {
3635
val options = SentryAndroidOptions()
3736
val scope = Scope(options)
38-
val promise = PromiseImpl({
39-
assertEquals(1, it.size)
40-
assertEquals(null, it[0])
41-
}, {
42-
fail("Promise was rejected unexpectedly")
43-
})
37+
val promise =
38+
PromiseImpl({
39+
assertEquals(1, it.size)
40+
assertEquals(null, it[0])
41+
}, {
42+
fail("Promise was rejected unexpectedly")
43+
})
4444
module.fetchNativeDeviceContexts(promise, options, null, scope)
4545
}
4646

@@ -50,12 +50,13 @@ class RNSentryModuleImplTest {
5050

5151
val options = NotAndroidSentryOptions()
5252
val scope = Scope(options)
53-
val promise = PromiseImpl({
54-
assertEquals(1, it.size)
55-
assertEquals(null, it[0])
56-
}, {
57-
fail("Promise was rejected unexpectedly")
58-
})
53+
val promise =
54+
PromiseImpl({
55+
assertEquals(1, it.size)
56+
assertEquals(null, it[0])
57+
}, {
58+
fail("Promise was rejected unexpectedly")
59+
})
5960
module.fetchNativeDeviceContexts(promise, options, context, scope)
6061
}
6162

@@ -69,17 +70,18 @@ class RNSentryModuleImplTest {
6970
scope.addBreadcrumb(Breadcrumb("Breadcrumb2-RN").apply { origin = "react-native" })
7071
scope.addBreadcrumb(Breadcrumb("Breadcrumb2-RN").apply { origin = "react-native" })
7172

72-
val promise = PromiseImpl({
73-
assertEquals(1, it.size)
74-
assertEquals(true, it[0] is WritableMap)
75-
val actual = it[0] as WritableMap
76-
val breadcrumbs = actual.getArray("breadcrumbs")
77-
assertEquals(2, breadcrumbs?.size())
78-
assertEquals("Breadcrumb2-Native", breadcrumbs?.getMap(0)?.getString("message"))
79-
assertEquals("Breadcrumb3-Native", breadcrumbs?.getMap(1)?.getString("message"))
80-
}, {
81-
fail("Promise was rejected unexpectedly")
82-
})
73+
val promise =
74+
PromiseImpl({
75+
assertEquals(1, it.size)
76+
assertEquals(true, it[0] is WritableMap)
77+
val actual = it[0] as WritableMap
78+
val breadcrumbs = actual.getArray("breadcrumbs")
79+
assertEquals(2, breadcrumbs?.size())
80+
assertEquals("Breadcrumb2-Native", breadcrumbs?.getMap(0)?.getString("message"))
81+
assertEquals("Breadcrumb3-Native", breadcrumbs?.getMap(1)?.getString("message"))
82+
}, {
83+
fail("Promise was rejected unexpectedly")
84+
})
8385

8486
module.fetchNativeDeviceContexts(promise, options, context, scope)
8587
}

packages/core/RNSentryAndroidTester/app/src/androidTest/java/io/sentry/rnsentryandroidtester/RNSentryMapConverterTest.kt

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
package io.sentry.rnsentryandroidtester
22

3+
import android.content.Context
34
import androidx.test.ext.junit.runners.AndroidJUnit4
45
import androidx.test.platform.app.InstrumentationRegistry
56
import com.facebook.react.bridge.Arguments
67
import com.facebook.soloader.SoLoader
78
import io.sentry.react.RNSentryMapConverter
8-
import org.junit.Assert.*
9+
import org.junit.Assert.assertEquals
10+
import org.junit.Assert.assertNull
11+
import org.junit.Before
912
import org.junit.Test
1013
import org.junit.runner.RunWith
11-
import android.content.Context;
12-
import org.junit.Before
1314
import java.math.BigDecimal
1415
import java.math.BigInteger
1516

1617
class Unknown
1718

18-
1919
@RunWith(AndroidJUnit4::class)
2020
class MapConverterTest {
21-
2221
@Before
2322
fun setUp() {
2423
val context: Context = InstrumentationRegistry.getInstrumentation().targetContext
@@ -103,95 +102,95 @@ class MapConverterTest {
103102
@Test
104103
fun convertsMapWithUnknownValueKey() {
105104
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("unknown" to Unknown()))
106-
val expectedMap = Arguments.createMap();
105+
val expectedMap = Arguments.createMap()
107106
expectedMap.putNull("unknown")
108107
assertEquals(expectedMap, actualMap)
109108
}
110109

111110
@Test
112111
fun convertsMapWithNullKey() {
113112
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("null" to null))
114-
val expectedMap = Arguments.createMap();
113+
val expectedMap = Arguments.createMap()
115114
expectedMap.putNull("null")
116115
assertEquals(expectedMap, actualMap)
117116
}
118117

119118
@Test
120119
fun convertsMapWithBooleanKey() {
121120
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("boolean" to true))
122-
val expectedMap = Arguments.createMap();
121+
val expectedMap = Arguments.createMap()
123122
expectedMap.putBoolean("boolean", true)
124123
assertEquals(expectedMap, actualMap)
125124
}
126125

127126
@Test
128127
fun convertsMapWithDoubleKey() {
129128
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("double" to Double.MAX_VALUE))
130-
val expectedMap = Arguments.createMap();
129+
val expectedMap = Arguments.createMap()
131130
expectedMap.putDouble("double", Double.MAX_VALUE)
132131
assertEquals(expectedMap, actualMap)
133132
}
134133

135134
@Test
136135
fun convertsMapWithIntegerKey() {
137136
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("integer" to Integer.MAX_VALUE))
138-
val expectedMap = Arguments.createMap();
137+
val expectedMap = Arguments.createMap()
139138
expectedMap.putInt("integer", Integer.MAX_VALUE)
140139
assertEquals(expectedMap, actualMap)
141140
}
142141

143142
@Test
144143
fun convertsMapWithByteKey() {
145144
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("byte" to Byte.MAX_VALUE))
146-
val expectedMap = Arguments.createMap();
145+
val expectedMap = Arguments.createMap()
147146
expectedMap.putInt("byte", Byte.MAX_VALUE.toInt())
148147
assertEquals(expectedMap, actualMap)
149148
}
150149

151150
@Test
152151
fun convertsMapWithShortKey() {
153152
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("short" to Short.MAX_VALUE))
154-
val expectedMap = Arguments.createMap();
153+
val expectedMap = Arguments.createMap()
155154
expectedMap.putInt("short", Short.MAX_VALUE.toInt())
156155
assertEquals(expectedMap, actualMap)
157156
}
158157

159158
@Test
160159
fun convertsMapWithFloatKey() {
161160
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("float" to Float.MAX_VALUE))
162-
val expectedMap = Arguments.createMap();
161+
val expectedMap = Arguments.createMap()
163162
expectedMap.putDouble("float", Float.MAX_VALUE.toDouble())
164163
assertEquals(expectedMap, actualMap)
165164
}
166165

167166
@Test
168167
fun convertsMapWithLongKey() {
169168
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("long" to Long.MAX_VALUE))
170-
val expectedMap = Arguments.createMap();
169+
val expectedMap = Arguments.createMap()
171170
expectedMap.putDouble("long", Long.MAX_VALUE.toDouble())
172171
assertEquals(expectedMap, actualMap)
173172
}
174173

175174
@Test
176175
fun convertsMapWithInBigDecimalKey() {
177176
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("big_decimal" to BigDecimal.TEN))
178-
val expectedMap = Arguments.createMap();
177+
val expectedMap = Arguments.createMap()
179178
expectedMap.putDouble("big_decimal", BigDecimal.TEN.toDouble())
180179
assertEquals(expectedMap, actualMap)
181180
}
182181

183182
@Test
184183
fun convertsMapWithBigIntKey() {
185184
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("big_int" to BigInteger.TEN))
186-
val expectedMap = Arguments.createMap();
185+
val expectedMap = Arguments.createMap()
187186
expectedMap.putDouble("big_int", BigInteger.TEN.toDouble())
188187
assertEquals(expectedMap, actualMap)
189188
}
190189

191190
@Test
192191
fun convertsMapWithStringKey() {
193192
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("string" to "string"))
194-
val expectedMap = Arguments.createMap();
193+
val expectedMap = Arguments.createMap()
195194
expectedMap.putString("string", "string")
196195
assertEquals(expectedMap, actualMap)
197196
}
@@ -304,26 +303,32 @@ class MapConverterTest {
304303

305304
@Test
306305
fun convertsComplexMapCorrectly() {
307-
val actual = RNSentryMapConverter.convertToWritable(mapOf(
308-
"integer" to Integer.MAX_VALUE,
309-
"string" to "string1",
310-
"map" to mapOf(
311-
"integer" to Integer.MAX_VALUE,
312-
"string" to "string2",
313-
"map" to mapOf(
314-
"integer" to Integer.MAX_VALUE,
315-
"string" to "string3"
316-
)
317-
),
318-
"list" to listOf(
319-
Integer.MAX_VALUE,
306+
val actual =
307+
RNSentryMapConverter.convertToWritable(
320308
mapOf(
321309
"integer" to Integer.MAX_VALUE,
322-
"string" to "string4",
310+
"string" to "string1",
311+
"map" to
312+
mapOf(
313+
"integer" to Integer.MAX_VALUE,
314+
"string" to "string2",
315+
"map" to
316+
mapOf(
317+
"integer" to Integer.MAX_VALUE,
318+
"string" to "string3",
319+
),
320+
),
321+
"list" to
322+
listOf(
323+
Integer.MAX_VALUE,
324+
mapOf(
325+
"integer" to Integer.MAX_VALUE,
326+
"string" to "string4",
327+
),
328+
"string5",
329+
),
323330
),
324-
"string5",
325-
),
326-
))
331+
)
327332

328333
val expectedMap1 = Arguments.createMap()
329334
val expectedMap2 = Arguments.createMap()

packages/core/RNSentryAndroidTester/app/src/test/java/com/swmansion/rnscreens/ScreenStackFragment.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package com.swmansion.rnscreens
22

33
import androidx.fragment.app.Fragment
44

5-
class ScreenStackFragment(contentLayoutId: Int) : Fragment(contentLayoutId) {
6-
7-
}
5+
class ScreenStackFragment(
6+
contentLayoutId: Int,
7+
) : Fragment(contentLayoutId)

0 commit comments

Comments
 (0)