Skip to content

Commit

Permalink
PIMOB-2183: Update KtLint version and .editorconfig & run ktlintFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
jheng-hao-lin-cko committed Oct 10, 2023
1 parent a61c12b commit ae2efb2
Show file tree
Hide file tree
Showing 358 changed files with 1,997 additions and 1,823 deletions.
18 changes: 7 additions & 11 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# top-most EditorConfig file
root = true

[*.{kt,kts}]
# true (recommended) / false
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
# Comma-separated list of rules to disable (Since 0.34.0)
# Note that rules in any ruleset other than the standard ruleset will need to be prefixed
# by the ruleset identifier.
disabled_rules = experimental:annotation, import-ordering, indent
# Max symbols in line
max_line_length = 120
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
ij_any_method_parameters_wrap = normal
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true

# According to https://kotlinlang.org/docs/reference/coding-conventions.html#names-for-test-methods it is acceptable to write method names
# in natural language. When using natural language, the description tends to be longer. Allow lines containing an identifier between
# backticks to be longer than the maximum line length. (Since 0.41.0)
[**/test/**.kt]
ktlint_ignore_back_ticked_identifier = true
max_line_length = unset
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object Versions {
const val espresso = "3.3.0"

// Static code analyze
const val ktlint = "0.45.2"
const val ktlint = "0.50.0"
const val detect = "1.20.0"

// Logger
Expand Down
16 changes: 8 additions & 8 deletions checkout/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import com.checkout.buildsrc.BuildConfigFieldName
import com.checkout.buildsrc.applyAndroidJUnit4Configuration
import com.checkout.buildsrc.applyAndroidJUnit5Configuration
import com.checkout.buildsrc.applyCommonLibConfigurations
import com.checkout.buildsrc.applyAndroidJUnit4Configuration
import com.checkout.buildsrc.applyNetworkConfigurations
import com.checkout.buildsrc.BuildConfigFieldName
import com.checkout.buildsrc.applyJacocoTestReport
import com.checkout.buildsrc.applyNetworkConfigurations

plugins {
id("com.android.library")
Expand All @@ -26,19 +26,19 @@ android {
buildConfigField(
"String",
BuildConfigFieldName.productVersion,
"\"${CheckoutConfig.version}\""
"\"${CheckoutConfig.version}\"",
)

buildConfigField(
"String",
BuildConfigFieldName.productName,
"\"${CheckoutConfig.pomName}\""
"\"${CheckoutConfig.pomName}\"",
)

buildConfigField(
"String",
BuildConfigFieldName.productIdentifier,
"\"${CheckoutConfig.groupId}.${CheckoutConfig.artifactId}\""
"\"${CheckoutConfig.groupId}.${CheckoutConfig.artifactId}\"",
)

consumerProguardFiles("consumer-rules.pro")
Expand All @@ -51,15 +51,15 @@ android {
buildConfigField(
"Boolean",
BuildConfigFieldName.defaultLogcatMonitoring,
"false"
"false",
)
}

debug {
buildConfigField(
"Boolean",
BuildConfigFieldName.defaultLogcatMonitoring,
"true"
"true",
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions checkout/src/main/java/com/checkout/CardValidatorFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public object CardValidatorFactory {
ExpiryDateValidator(),
CvvValidator(),
CardNumberValidator(LuhnChecker()),
EventLoggerProvider.provide()
EventLoggerProvider.provide(),
)
}

Expand All @@ -35,7 +35,7 @@ public object CardValidatorFactory {
return CardDetailsValidator(
ExpiryDateValidator(),
CvvValidator(),
CardNumberValidator(LuhnChecker())
CardNumberValidator(LuhnChecker()),
)
}
}
16 changes: 8 additions & 8 deletions checkout/src/main/java/com/checkout/CheckoutApiServiceFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ public object CheckoutApiServiceFactory {
public fun create(
publicKey: String,
environment: Environment,
context: Context
context: Context,
): CheckoutApiService {
val logger = EventLoggerProvider.provide()

logger.setup(context, environment)

return CheckoutApiClient(
provideTokenRepository(publicKey, environment),
provideThreeDSExecutor(logger)
provideThreeDSExecutor(logger),
)
}

private fun provideTokenRepository(
publicKey: String,
environment: Environment
environment: Environment,
): TokenRepository = TokenRepositoryImpl(
networkApiClient = provideNetworkApiClient(publicKey, environment.url),
cardToTokenRequestMapper = CardToTokenRequestMapper(),
Expand All @@ -59,25 +59,25 @@ public object CheckoutApiServiceFactory {
CardValidatorFactory.createInternal(),
AddressValidator(),
PhoneValidator(),
AddressToAddressValidationRequestDataMapper()
AddressToAddressValidationRequestDataMapper(),
),
validateCVVTokenizationDataUseCase = ValidateCVVTokenizationDataUseCase(CVVComponentValidatorFactory.create()),
logger = TokenizationEventLogger(EventLoggerProvider.provide()),
publicKey = publicKey,
cvvTokenizationNetworkDataMapper = CVVTokenizationNetworkDataMapper()
cvvTokenizationNetworkDataMapper = CVVTokenizationNetworkDataMapper(),
)

private fun provideNetworkApiClient(
publicKey: String,
url: String
url: String,
) = TokenNetworkApiClient(
url,
OkHttpProvider.createOkHttpClient(publicKey),
Moshi.Builder().addLast(KotlinJsonAdapterFactory()).build()
Moshi.Builder().addLast(KotlinJsonAdapterFactory()).build(),
)

private fun provideThreeDSExecutor(logger: Logger<LoggingEvent>): Executor<ThreeDSRequest> = ThreeDSExecutor(
ProcessThreeDSUseCase(),
ThreeDSEventLogger(logger)
ThreeDSEventLogger(logger),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.checkout.tokenization.repository.TokenRepository

internal class CheckoutApiClient(
private val tokenRepository: TokenRepository,
private val threeDSExecutor: Executor<ThreeDSRequest>
private val threeDSExecutor: Executor<ThreeDSRequest>,
) : CheckoutApiService {

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.checkout.api.logging
import com.checkout.logging.LoggingEventType

internal enum class ApiClientEventType(override val eventId: String) : LoggingEventType {
INITIALIZE("checkout_api_client_initialised")
INITIALIZE("checkout_api_client_initialised"),
}
47 changes: 24 additions & 23 deletions checkout/src/main/java/com/checkout/base/model/CardScheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,77 +43,77 @@ public enum class CardScheme(
* Card scheme icon.
*/
@DrawableRes
public val imageId: Int = R.drawable.cko_ic_scheme_placeholder
public val imageId: Int = R.drawable.cko_ic_scheme_placeholder,
) {
AMERICAN_EXPRESS(
cvvLength = setOf(4),
regex = Regex("^3[47]\\d{13}$"),
eagerRegex = Regex("^3[47]\\d*$"),
maxNumberLength = 15,
numberSeparatorPattern = listOf(4, 11),
imageId = R.drawable.cko_ic_scheme_amex
imageId = R.drawable.cko_ic_scheme_amex,
),
DINERS_CLUB(
cvvLength = setOf(3),
regex = Regex("^3(0[0-5]|[68]\\d)\\d{11,16}$"),
eagerRegex = Regex("^3(0|[68])\\d*$"),
maxNumberLength = 19,
numberSeparatorPattern = listOf(4, 9, 14, 19),
imageId = R.drawable.cko_ic_scheme_diners
imageId = R.drawable.cko_ic_scheme_diners,
),
DISCOVER(
cvvLength = setOf(3),
regex = Regex("^6(?:011|4[4-9]\\d|5\\d{2})\\d{12}$"),
eagerRegex = Regex("^6(011|4[4-9]|5)\\d*$"),
maxNumberLength = 16,
numberSeparatorPattern = listOf(4, 9, 14),
imageId = R.drawable.cko_ic_scheme_discover
imageId = R.drawable.cko_ic_scheme_discover,
),
JCB(
cvvLength = setOf(3),
regex = Regex("^35\\d{14}$"),
eagerRegex = Regex("^35\\d*$"),
maxNumberLength = 19,
numberSeparatorPattern = listOf(4, 9, 14, 19),
imageId = R.drawable.cko_ic_scheme_jcb
imageId = R.drawable.cko_ic_scheme_jcb,
),
MADA(
cvvLength = setOf(3),
regex = Regex(
"^(4(0(0861|1757|6996|7(197|395)|9201)|1(2565|0685|7633|9593)|2(281(7|8|9)|8(331|67(1|2|3)))" +
"|3(1361|2328|4107|9954)|4(0(533|647|795)|5564|6(393|404|672))|5(5(036|708)|7865|7997|8456)" +
"|6(2220|854(0|1|2|3))|8(301(0|1|2)|4783|609(4|5|6)|931(7|8|9))|93428)|5(0(4300|6968|8160)" +
"|13213|2(0058|1076|4(130|514)|9(415|741))|3(0(060|906)|1(095|196)|2013|5(825|989)|6023|7767" +
"|9931)|4(3(085|357)|9760)|5(4180|7606|8848)|8(5265|8(8(4(5|6|7|8|9)|5(0|1))|98(2|3))" +
"|9(005|206)))|6(0(4906|5141)|36120)|9682(0(1|2|3|4|5|6|7|8|9)|1(0|1)))\\d{10}$"
"|3(1361|2328|4107|9954)|4(0(533|647|795)|5564|6(393|404|672))|5(5(036|708)|7865|7997|8456)" +
"|6(2220|854(0|1|2|3))|8(301(0|1|2)|4783|609(4|5|6)|931(7|8|9))|93428)|5(0(4300|6968|8160)" +
"|13213|2(0058|1076|4(130|514)|9(415|741))|3(0(060|906)|1(095|196)|2013|5(825|989)|6023|7767" +
"|9931)|4(3(085|357)|9760)|5(4180|7606|8848)|8(5265|8(8(4(5|6|7|8|9)|5(0|1))|98(2|3))" +
"|9(005|206)))|6(0(4906|5141)|36120)|9682(0(1|2|3|4|5|6|7|8|9)|1(0|1)))\\d{10}$",
),
eagerRegex = Regex(
"^(4(0(0861|1757|6996|7(197|395)|9201)|1(2565|0685|7633|9593)|2(281(7|8|9)|8(331|67(1|2|3)))" +
"|3(1361|2328|4107|9954)|4(0(533|647|795)|5564|6(393|404|672))|5(5(036|708)|7865|7997|8456)" +
"|6(2220|854(0|1|2|3))|8(301(0|1|2)|4783|609(4|5|6)|931(7|8|9))|93428)" +
"|5(0(4300|6968|8160)|13213|2(0058|1076|4(130|514)|9(415|741))" +
"|3(0(060|906)|1(095|196)|2013|5(825|989)|6023|7767|9931)|4(3(085|357)|9760)|5(4180|7606|8848)" +
"|8(5265|8(8(4(5|6|7|8|9)|5(0|1))|98(2|3))|9(005|206)))|6(0(4906|5141)|36120)" +
"|9682(0(1|2|3|4|5|6|7|8|9)|1(0|1)))\\d*$"
"|3(1361|2328|4107|9954)|4(0(533|647|795)|5564|6(393|404|672))|5(5(036|708)|7865|7997|8456)" +
"|6(2220|854(0|1|2|3))|8(301(0|1|2)|4783|609(4|5|6)|931(7|8|9))|93428)" +
"|5(0(4300|6968|8160)|13213|2(0058|1076|4(130|514)|9(415|741))" +
"|3(0(060|906)|1(095|196)|2013|5(825|989)|6023|7767|9931)|4(3(085|357)|9760)|5(4180|7606|8848)" +
"|8(5265|8(8(4(5|6|7|8|9)|5(0|1))|98(2|3))|9(005|206)))|6(0(4906|5141)|36120)" +
"|9682(0(1|2|3|4|5|6|7|8|9)|1(0|1)))\\d*$",
),
imageId = R.drawable.cko_ic_scheme_mada
imageId = R.drawable.cko_ic_scheme_mada,
),
MAESTRO(
cvvLength = setOf(0, 3),
regex = Regex(
"^(?:5[06789]\\d\\d|(?!6011[0234])(?!60117[4789])(?!60118[6789])(?!60119)" +
"(?!64[456789])(?!65)6\\d{3})\\d{8,15}$"
"(?!64[456789])(?!65)6\\d{3})\\d{8,15}$",
),
eagerRegex = Regex("^(5[0|6-8]\\d{0,17}|6\\d{0,18})$"),
maxNumberLength = 19,
numberSeparatorPattern = listOf(4, 9, 14, 19),
imageId = R.drawable.cko_ic_scheme_maestro
imageId = R.drawable.cko_ic_scheme_maestro,
),
MASTERCARD(
cvvLength = setOf(3),
regex = Regex("^(5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)\\d{12}$"),
eagerRegex = Regex("^(2[3-7]|22[2-9]|5[1-5])\\d*$"),
imageId = R.drawable.cko_ic_scheme_mastercard
imageId = R.drawable.cko_ic_scheme_mastercard,
),
VISA(
cvvLength = setOf(3),
Expand All @@ -128,8 +128,9 @@ public enum class CardScheme(
regex = Regex(""),
eagerRegex = Regex(""),
maxNumberLength = 19,
numberSeparatorPattern = listOf(4, 9, 14, 19)
);
numberSeparatorPattern = listOf(4, 9, 14, 19),
),
;

public companion object {
@JvmStatic
Expand All @@ -141,7 +142,7 @@ public enum class CardScheme(
@JvmStatic
public fun fromString(cardSchemeValue: String): CardScheme = CardScheme.values().find { cardScheme ->
cardScheme.name.contains(
cardSchemeValue.uppercase().substringBefore("_").substringBefore(" ")
cardSchemeValue.uppercase().substringBefore("_").substringBefore(" "),
)
} ?: UNKNOWN
}
Expand Down
8 changes: 4 additions & 4 deletions checkout/src/main/java/com/checkout/base/model/Country.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.checkout.base.model

public enum class Country(
public val iso3166Alpha2: String,
public val dialingCode: String
public val dialingCode: String,
) {
AFGHANISTAN("AF", "93"),
ALAND_ISLANDS("AX", "358"),
Expand Down Expand Up @@ -254,13 +254,13 @@ public enum class Country(
WESTERN_SAHARA("EH", "2125288"),
YEMEN("YE", "967"),
ZAMBIA("ZM", "260"),
ZIMBABWE("ZW", "263");
ZIMBABWE("ZW", "263"),
;

public companion object {

@JvmStatic
public fun from(iso3166Alpha2: String?): Country? {

val country: Country? = values().firstOrNull {
it.iso3166Alpha2.equals(iso3166Alpha2, true)
}
Expand All @@ -271,7 +271,7 @@ public enum class Country(
internal fun getCountry(dialingCode: String?, iso3166Alpha2: String?): Country? {
val country: Country? = values().firstOrNull { country ->
country.dialingCode.equals(dialingCode, true) &&
country.iso3166Alpha2.equals(iso3166Alpha2, true)
country.iso3166Alpha2.equals(iso3166Alpha2, true)
}

return country
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import com.checkout.base.util.EnvironmentConstants

public enum class Environment(public val url: String) {
PRODUCTION(EnvironmentConstants.PRODUCTION_SERVER_URL),
SANDBOX(EnvironmentConstants.SANDBOX_SERVER_URL)
SANDBOX(EnvironmentConstants.SANDBOX_SERVER_URL),
}
6 changes: 3 additions & 3 deletions checkout/src/main/java/com/checkout/logging/EventLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ internal class EventLogger(private val logger: CheckoutEventLogger) : Logger<Log
context: Context,
environment: Environment,
identifier: String,
version: String
version: String,
) {
if (needToSetup) {
logger.enableRemoteProcessor(
environment.toLoggingEnvironment(),
provideProcessorMetadata(context, environment, identifier, version)
provideProcessorMetadata(context, environment, identifier, version),
)
resetSession()
needToSetup = false
Expand Down Expand Up @@ -56,6 +56,6 @@ internal class EventLogger(private val logger: CheckoutEventLogger) : Logger<Log
context,
environment.toLoggingName(),
identifier,
version
version,
)
}
2 changes: 1 addition & 1 deletion checkout/src/main/java/com/checkout/logging/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface Logger<T> {
context: Context,
environment: Environment,
identifier: String = BuildConfig.PRODUCT_IDENTIFIER,
version: String = BuildConfig.PRODUCT_VERSION
version: String = BuildConfig.PRODUCT_VERSION,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.util.Date
public class LoggingEvent constructor(
internal val eventType: LoggingEventType,
override val monitoringLevel: MonitoringLevel = MonitoringLevel.INFO,
override val properties: Map<String, Any> = emptyMap()
override val properties: Map<String, Any> = emptyMap(),
) : Event {

override val time: Date = Date()
Expand Down
6 changes: 3 additions & 3 deletions checkout/src/main/java/com/checkout/network/OkHttpProvider.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.checkout.network

import com.checkout.network.utils.OkHttpConstants.CALL_TIMEOUT_MS
import com.checkout.network.utils.OkHttpConstants.CONNECTION_TIMEOUT_MS
import com.checkout.network.utils.OkHttpConstants.READ_TIMEOUT_MS
import com.checkout.network.extension.addLocalInterceptors
import com.checkout.network.extension.addRequestInterceptors
import com.checkout.network.extension.buildConnectionSpecs
import com.checkout.network.utils.OkHttpConstants.CALL_TIMEOUT_MS
import com.checkout.network.utils.OkHttpConstants.CONNECTION_TIMEOUT_MS
import com.checkout.network.utils.OkHttpConstants.READ_TIMEOUT_MS
import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit

Expand Down
Loading

0 comments on commit ae2efb2

Please sign in to comment.