Skip to content

Commit

Permalink
chore(lint): Add ktlint (#4406)
Browse files Browse the repository at this point in the history
* Adds ktlint

* Fixes kotlin lint issues

---------

Co-authored-by: Krystof Woldrich <[email protected]>
  • Loading branch information
antonis and krystofwoldrich authored Jan 10, 2025
1 parent 07851c7 commit 2442538
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 258 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
"clean": "lerna run clean",
"circularDepCheck": "lerna run circularDepCheck",
"test": "lerna run test",
"fix": "run-s fix:lerna fix:android fix:clang fix:swift",
"fix": "run-s fix:lerna fix:android fix:clang fix:swift fix:kotlin",
"fix:lerna": "lerna run fix",
"fix:android": "run-s 'java:format fix' java:pmd",
"fix:clang": "run-s 'clang:format fix'",
"fix:swift": "run-s 'swift:lint fix'",
"lint": "run-s lint:lerna lint:android lint:clang lint:swift",
"fix:kotlin": "npx ktlint --relative --format '!**/node_modules/**'",
"lint": "run-s lint:lerna lint:android lint:clang lint:swift lint:kotlin",
"lint:lerna": "lerna run lint",
"lint:android": "run-s 'java:format lint' java:pmd",
"lint:clang": "run-s 'clang:format lint'",
"lint:swift": "run-s 'swift:lint lint'",
"lint:kotlin": "npx ktlint --relative '!**/node_modules/**'",
"java:format": "./scripts/google-java-format.sh",
"java:pmd": "./scripts/pmd.sh",
"clang:format": "./scripts/clang-format.sh",
Expand All @@ -27,6 +29,7 @@
},
"devDependencies": {
"@expo/swiftlint": "^0.57.1",
"@naturalcycles/ktlint": "^1.13.0",
"@sentry/cli": "2.40.0",
"clang-format": "^1.8.0",
"downlevel-dts": "^0.11.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.junit.runners.JUnit4

@RunWith(JUnit4::class)
class RNSentryModuleImplTest {

private lateinit var module: RNSentryModuleImpl
private lateinit var context: Context

Expand All @@ -35,12 +34,13 @@ class RNSentryModuleImplTest {
fun fetchNativeDeviceContextsWithNullContext() {
val options = SentryAndroidOptions()
val scope = Scope(options)
val promise = PromiseImpl({
assertEquals(1, it.size)
assertEquals(null, it[0])
}, {
fail("Promise was rejected unexpectedly")
})
val promise =
PromiseImpl({
assertEquals(1, it.size)
assertEquals(null, it[0])
}, {
fail("Promise was rejected unexpectedly")
})
module.fetchNativeDeviceContexts(promise, options, null, scope)
}

Expand All @@ -50,12 +50,13 @@ class RNSentryModuleImplTest {

val options = NotAndroidSentryOptions()
val scope = Scope(options)
val promise = PromiseImpl({
assertEquals(1, it.size)
assertEquals(null, it[0])
}, {
fail("Promise was rejected unexpectedly")
})
val promise =
PromiseImpl({
assertEquals(1, it.size)
assertEquals(null, it[0])
}, {
fail("Promise was rejected unexpectedly")
})
module.fetchNativeDeviceContexts(promise, options, context, scope)
}

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

val promise = PromiseImpl({
assertEquals(1, it.size)
assertEquals(true, it[0] is WritableMap)
val actual = it[0] as WritableMap
val breadcrumbs = actual.getArray("breadcrumbs")
assertEquals(2, breadcrumbs?.size())
assertEquals("Breadcrumb2-Native", breadcrumbs?.getMap(0)?.getString("message"))
assertEquals("Breadcrumb3-Native", breadcrumbs?.getMap(1)?.getString("message"))
}, {
fail("Promise was rejected unexpectedly")
})
val promise =
PromiseImpl({
assertEquals(1, it.size)
assertEquals(true, it[0] is WritableMap)
val actual = it[0] as WritableMap
val breadcrumbs = actual.getArray("breadcrumbs")
assertEquals(2, breadcrumbs?.size())
assertEquals("Breadcrumb2-Native", breadcrumbs?.getMap(0)?.getString("message"))
assertEquals("Breadcrumb3-Native", breadcrumbs?.getMap(1)?.getString("message"))
}, {
fail("Promise was rejected unexpectedly")
})

module.fetchNativeDeviceContexts(promise, options, context, scope)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package io.sentry.rnsentryandroidtester

import android.content.Context
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.facebook.react.bridge.Arguments
import com.facebook.soloader.SoLoader
import io.sentry.react.RNSentryMapConverter
import org.junit.Assert.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import android.content.Context;
import org.junit.Before
import java.math.BigDecimal
import java.math.BigInteger

class Unknown


@RunWith(AndroidJUnit4::class)
class MapConverterTest {

@Before
fun setUp() {
val context: Context = InstrumentationRegistry.getInstrumentation().targetContext
Expand Down Expand Up @@ -103,95 +102,95 @@ class MapConverterTest {
@Test
fun convertsMapWithUnknownValueKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("unknown" to Unknown()))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putNull("unknown")
assertEquals(expectedMap, actualMap)
}

@Test
fun convertsMapWithNullKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("null" to null))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putNull("null")
assertEquals(expectedMap, actualMap)
}

@Test
fun convertsMapWithBooleanKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("boolean" to true))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putBoolean("boolean", true)
assertEquals(expectedMap, actualMap)
}

@Test
fun convertsMapWithDoubleKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("double" to Double.MAX_VALUE))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putDouble("double", Double.MAX_VALUE)
assertEquals(expectedMap, actualMap)
}

@Test
fun convertsMapWithIntegerKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("integer" to Integer.MAX_VALUE))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putInt("integer", Integer.MAX_VALUE)
assertEquals(expectedMap, actualMap)
}

@Test
fun convertsMapWithByteKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("byte" to Byte.MAX_VALUE))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putInt("byte", Byte.MAX_VALUE.toInt())
assertEquals(expectedMap, actualMap)
}

@Test
fun convertsMapWithShortKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("short" to Short.MAX_VALUE))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putInt("short", Short.MAX_VALUE.toInt())
assertEquals(expectedMap, actualMap)
}

@Test
fun convertsMapWithFloatKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("float" to Float.MAX_VALUE))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putDouble("float", Float.MAX_VALUE.toDouble())
assertEquals(expectedMap, actualMap)
}

@Test
fun convertsMapWithLongKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("long" to Long.MAX_VALUE))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putDouble("long", Long.MAX_VALUE.toDouble())
assertEquals(expectedMap, actualMap)
}

@Test
fun convertsMapWithInBigDecimalKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("big_decimal" to BigDecimal.TEN))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putDouble("big_decimal", BigDecimal.TEN.toDouble())
assertEquals(expectedMap, actualMap)
}

@Test
fun convertsMapWithBigIntKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("big_int" to BigInteger.TEN))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putDouble("big_int", BigInteger.TEN.toDouble())
assertEquals(expectedMap, actualMap)
}

@Test
fun convertsMapWithStringKey() {
val actualMap = RNSentryMapConverter.convertToWritable(mapOf("string" to "string"))
val expectedMap = Arguments.createMap();
val expectedMap = Arguments.createMap()
expectedMap.putString("string", "string")
assertEquals(expectedMap, actualMap)
}
Expand Down Expand Up @@ -304,26 +303,32 @@ class MapConverterTest {

@Test
fun convertsComplexMapCorrectly() {
val actual = RNSentryMapConverter.convertToWritable(mapOf(
"integer" to Integer.MAX_VALUE,
"string" to "string1",
"map" to mapOf(
"integer" to Integer.MAX_VALUE,
"string" to "string2",
"map" to mapOf(
"integer" to Integer.MAX_VALUE,
"string" to "string3"
)
),
"list" to listOf(
Integer.MAX_VALUE,
val actual =
RNSentryMapConverter.convertToWritable(
mapOf(
"integer" to Integer.MAX_VALUE,
"string" to "string4",
"string" to "string1",
"map" to
mapOf(
"integer" to Integer.MAX_VALUE,
"string" to "string2",
"map" to
mapOf(
"integer" to Integer.MAX_VALUE,
"string" to "string3",
),
),
"list" to
listOf(
Integer.MAX_VALUE,
mapOf(
"integer" to Integer.MAX_VALUE,
"string" to "string4",
),
"string5",
),
),
"string5",
),
))
)

val expectedMap1 = Arguments.createMap()
val expectedMap2 = Arguments.createMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.swmansion.rnscreens

import androidx.fragment.app.Fragment

class ScreenStackFragment(contentLayoutId: Int) : Fragment(contentLayoutId) {

}
class ScreenStackFragment(
contentLayoutId: Int,
) : Fragment(contentLayoutId)
Loading

0 comments on commit 2442538

Please sign in to comment.