Skip to content

Commit 89342e9

Browse files
authored
Merge pull request #5 from thepeerstack/feature/code-quality
Setup Ktlint
2 parents 8879451 + e7ccd49 commit 89342e9

25 files changed

+91
-123
lines changed

.github/workflows/android.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ jobs:
2323
- name: Grant execute permission for gradlew
2424
run: chmod +x gradlew
2525

26-
# This will be enabled after the code-quality PR is merged
27-
# - name: Run Ktlint
28-
# uses: lucasnlm/ktlint-action@master
29-
#
30-
# - name: Check code quality
31-
# run: ./gradlew thepeer-android:ktlint
26+
- name: Check code quality with Ktlint
27+
run: ./gradlew thepeer-android:ktlint --stacktrace
3228

3329
- name: Build thepeer-android library
3430
run: ./gradlew thepeer-android:build

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- id: get_version
2323
uses: battila7/get-version-action@v2
2424
- name: Get version from tag
25-
run: echo ${{ teps.get_version.outputs.version-without-v }}
25+
run: echo ${{ steps.get_version.outputs.version-without-v }}
2626

2727

2828
# Builds the release artifacts of the library

build.gradle

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ task clean(type: Delete) {
2222
}
2323

2424
ext {
25-
// Compose
26-
composeVersion = '1.1.1'
27-
constraintLayoutComposeVersion = '1.0.0-rc01'
28-
activityComposeVersion = '1.4.0'
29-
accompanistPagerVersion = '0.20.0'
30-
composeNavigationVersion = '2.3.0'
31-
composeViewModelVersion = '2.4.0'
25+
26+
//ktlint
27+
ktlintVersion = '0.46.1'
3228

3329
// Coroutine
3430
coroutineVersion = '1.5.2'
@@ -42,11 +38,6 @@ ext {
4238
moshiAdaptersVersion = '1.12.0'
4339
moshiKotlinVersion = '1.12.0'
4440

45-
// Retrofit
46-
retrofitVersion = '2.9.0'
47-
retrofitMoshiConverterVersion = '2.9.0'
48-
loggingInterceptorVersion = '4.9.2'
49-
5041
// Mockk
5142
mockkVersion = '1.12.0'
5243

scripts/publish-module.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ afterEvaluate {
5252
}
5353
}
5454
developers {
55+
developer {
56+
id = 'zsmb13'
57+
name = 'Kamsi Oleka'
58+
email = 'kamsy@thepeer.co'
59+
}
60+
developer {
61+
id = 'zsmb14'
62+
name = 'Nsikak Thompson'
63+
email = 'nsikakthompson73@gmail.com'
64+
}
5565
// Add all other devs here...
5666
}
5767

thepeer-android/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ ext {
8080
PUBLISH_ARTIFACT_ID = 'thepeer-android'
8181
}
8282

83-
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"
83+
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"
84+
apply from: "$rootDir/thepeer-android/config/ktlint.gradle"

thepeer-android/config/ktlint.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
configurations {
2+
ktlint
3+
}
4+
5+
dependencies {
6+
ktlint("com.pinterest:ktlint:$ktlintVersion") {
7+
attributes {
8+
attribute(Bundling.BUNDLING_ATTRIBUTE, getObjects().named(Bundling, Bundling.EXTERNAL))
9+
}
10+
}
11+
}
12+
13+
tasks.register("ktlint", JavaExec) {
14+
group = "verification"
15+
description = "Check Kotlin code style."
16+
classpath = configurations.ktlint
17+
main = "com.pinterest.ktlint.Main"
18+
args "**/*.kt" , "!**/build/**/*.kt"
19+
}
20+
21+
tasks.register("ktlintFormat", JavaExec) {
22+
group = "formatting"
23+
description = "Fix Kotlin code style deviations."
24+
classpath = configurations.ktlint
25+
main = "com.pinterest.ktlint.Main"
26+
args "-F", "**/*.kt" , "!**/build/**/*.kt"
27+
}
28+
29+
tasks.register("ktlintAndroidStudio", JavaExec) {
30+
description = "Setup Android Studio to use the same code style as ktlint."
31+
classpath = configurations.ktlint
32+
main = "com.pinterest.ktlint.Main"
33+
args "--android", "applyToIDEAProject", "-y"
34+
}

thepeer-android/src/androidTest/java/co/thepeer/sdk/ExampleInstrumentedTest.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package co.thepeer.sdk
22

3-
import androidx.test.platform.app.InstrumentationRegistry
43
import androidx.test.ext.junit.runners.AndroidJUnit4
5-
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import junit.framework.Assert.assertEquals
66
import org.junit.Test
77
import org.junit.runner.RunWith
88

9-
import org.junit.Assert.*
10-
119
/**
1210
* Instrumented test, which will execute on an Android device.
1311
*
@@ -21,4 +19,4 @@ class ExampleInstrumentedTest {
2119
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
2220
assertEquals("co.thepeer.sdk.test", appContext.packageName)
2321
}
24-
}
22+
}

thepeer-android/src/main/java/co/thepeer/sdk/Thepeer.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Thepeer internal constructor(
2929
private var amount: BigDecimal,
3030
private var currency: String,
3131
private var userReference: String,
32-
private var meta: Map<String, String> = emptyMap(),
32+
private var meta: Map<String, String> = emptyMap()
3333
) {
3434

3535
/**
@@ -76,7 +76,6 @@ class Thepeer internal constructor(
7676
return this
7777
}
7878

79-
8079
fun setCurrency(currency: String): Builder {
8180
this.currency = currency
8281
return this
@@ -102,11 +101,9 @@ class Thepeer internal constructor(
102101
userReference,
103102
meta
104103
)
105-
106104
}
107105
}
108106

109-
110107
/**
111108
* This function will be called to launch ThePeer Send Money Widget
112109
*/
@@ -164,7 +161,6 @@ class Thepeer internal constructor(
164161
resultRegistry.launch(params)
165162
}
166163

167-
168164
private fun getSdkType(type: Enum<ThepeerSDKType>): String {
169165
return when (type) {
170166
ThepeerSDKType.SEND -> {
@@ -178,6 +174,5 @@ class Thepeer internal constructor(
178174
}
179175
else -> ""
180176
}
181-
182177
}
183-
}
178+
}

thepeer-android/src/main/java/co/thepeer/sdk/model/ThePeerTransaction.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import android.os.Parcelable
44
import kotlinx.parcelize.Parcelize
55
import java.math.BigDecimal
66

7-
87
@Parcelize
98
data class ThepeerEvent(
109
val event: String,
1110
val data: ThepeerTransaction
1211
) : Parcelable
1312

14-
1513
@Parcelize
1614
data class ThepeerTransaction(
1715
val id: String,
@@ -29,7 +27,6 @@ data class ThepeerTransaction(
2927

3028
) : Parcelable
3129

32-
3330
@Parcelize
3431
data class ThepeerUser(
3532
val name: String,
@@ -39,7 +36,6 @@ data class ThepeerUser(
3936
val reference: String?
4037
) : Parcelable
4138

42-
4339
@Parcelize
4440
data class ThepeerBusiness(
4541
val name: String,
@@ -54,11 +50,10 @@ data class ThepeerCheckout(
5450
val status: String,
5551
val linked_account: LinkedAccount
5652

57-
5853
) : Parcelable
5954

6055
@Parcelize
6156
data class LinkedAccount(
6257
val user: ThepeerUser,
6358
val business: ThepeerBusiness
64-
) : Parcelable
59+
) : Parcelable

thepeer-android/src/main/java/co/thepeer/sdk/model/ThepeerParam.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ data class ThepeerParam(
1515
val currency: String,
1616
val userReference: String,
1717
val emailAddress: String? = null,
18-
val meta: Map<String, String>,
19-
): Parcelable
18+
val meta: Map<String, String>
19+
) : Parcelable
2020

21-
22-
enum class ThepeerSDKType{SEND, CHECKOUT, DIRECT_CHARGE, NONE}
21+
enum class ThepeerSDKType { SEND, CHECKOUT, DIRECT_CHARGE, NONE }

0 commit comments

Comments
 (0)