diff --git a/build.gradle b/build.gradle index 14f92db..5c28f43 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ ext { coroutineVersion = "1.6.4" arrowVersion = "0.7.2" + detektVersion = "1.22.0" logbackVersion = '1.2.10' logstashLogbackEncoderVersion = '7.0.1' diff --git a/buildSrc/src/main/groovy/yoframework.kotlin-common-conventions.gradle b/buildSrc/src/main/groovy/yoframework.kotlin-common-conventions.gradle index 1933b2d..48526a9 100644 --- a/buildSrc/src/main/groovy/yoframework.kotlin-common-conventions.gradle +++ b/buildSrc/src/main/groovy/yoframework.kotlin-common-conventions.gradle @@ -54,6 +54,8 @@ dependencies { testRuntimeOnly("org.jetbrains.spek:spek-junit-platform-engine:$spekVersion") { exclude group: 'org.jetbrains.kotlin' } + + detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion" } kotlin { diff --git a/core/src/main/kotlin/id/yoframework/core/extension/logger/Logger.kt b/core/src/main/kotlin/id/yoframework/core/extension/logger/Logger.kt index 7c1ebd1..b82db13 100644 --- a/core/src/main/kotlin/id/yoframework/core/extension/logger/Logger.kt +++ b/core/src/main/kotlin/id/yoframework/core/extension/logger/Logger.kt @@ -65,5 +65,3 @@ fun Logger.log(log: LogType, defaultParam: Map = emptyMap(), vararg } } } - - diff --git a/core/src/main/kotlin/id/yoframework/core/extension/resource/Environment.kt b/core/src/main/kotlin/id/yoframework/core/extension/resource/Environment.kt index f105ad2..69ebbc2 100644 --- a/core/src/main/kotlin/id/yoframework/core/extension/resource/Environment.kt +++ b/core/src/main/kotlin/id/yoframework/core/extension/resource/Environment.kt @@ -33,7 +33,9 @@ fun env(clazz: KClass, key: String, defaultValue: T? = null): T { clazz.isSubclassOf(Boolean::class) -> value.toBoolean() as T else -> throw IllegalArgumentException("${clazz.qualifiedName} Not Supported") } - } else defaultValue ?: throw IllegalArgumentException("Illegal: $key not found and default value is null!") + } else { + defaultValue ?: throw IllegalArgumentException("Illegal: $key not found and default value is null!") + } } inline fun env(key: String, defaultValue: T? = null): T { diff --git a/core/src/main/kotlin/id/yoframework/core/extension/string/String.kt b/core/src/main/kotlin/id/yoframework/core/extension/string/String.kt index 5a5a07c..e1fe110 100644 --- a/core/src/main/kotlin/id/yoframework/core/extension/string/String.kt +++ b/core/src/main/kotlin/id/yoframework/core/extension/string/String.kt @@ -42,4 +42,3 @@ private const val DEFAULT_WIDTH: Int = 42 fun String.abbreviate(width: Int = DEFAULT_WIDTH): String { return StringUtils.abbreviate(this, width) } - diff --git a/core/src/main/kotlin/id/yoframework/core/extension/time/DateTime.kt b/core/src/main/kotlin/id/yoframework/core/extension/time/DateTime.kt index e02afc6..c928d7d 100644 --- a/core/src/main/kotlin/id/yoframework/core/extension/time/DateTime.kt +++ b/core/src/main/kotlin/id/yoframework/core/extension/time/DateTime.kt @@ -24,7 +24,6 @@ import java.time.ZoneId import java.time.format.DateTimeFormatter import java.time.format.DateTimeParseException - fun Int.toYear(): Year { return Year.of(this) } @@ -66,4 +65,3 @@ fun String.fromUnixTimestamp(): LocalDateTime { fun LocalDate?.toFormat(pattern: String): String? { return this?.format(DateTimeFormatter.ofPattern(pattern)) } - diff --git a/core/src/main/kotlin/id/yoframework/core/json/Json.kt b/core/src/main/kotlin/id/yoframework/core/json/Json.kt index 8114cb0..aca1d1e 100644 --- a/core/src/main/kotlin/id/yoframework/core/json/Json.kt +++ b/core/src/main/kotlin/id/yoframework/core/json/Json.kt @@ -27,6 +27,7 @@ import kotlin.reflect.KClass import kotlin.reflect.full.isSubclassOf private val log = logger("Json Extension") + /** * Convert [JsonObject] to [T] object, and throws [IllegalArgumentException] if failed. * Require [com.fasterxml.jackson.module.kotlin.KotlinModule] installed on Json.mapper. diff --git a/core/src/main/kotlin/id/yoframework/core/json/validator/Number.kt b/core/src/main/kotlin/id/yoframework/core/json/validator/Number.kt index 56481a9..a67c253 100644 --- a/core/src/main/kotlin/id/yoframework/core/json/validator/Number.kt +++ b/core/src/main/kotlin/id/yoframework/core/json/validator/Number.kt @@ -93,8 +93,11 @@ inline fun JsonObject.equalTo(key: String, target: T): Vali } } -inline fun JsonObject.greaterThan(key: String, target: T, equals: Boolean = false) - : Validated { +inline fun JsonObject.greaterThan( + key: String, + target: T, + equals: Boolean = false +): Validated { val value = this.saveGet(T::class, key) ?: return NumericError( "$key is not exists ", Numeric.GreaterThan(target, equals) @@ -109,8 +112,11 @@ inline fun JsonObject.greaterThan(key: String, target: T, e } } -inline fun JsonObject.lessThan(key: String, target: T, equals: Boolean = false) - : Validated { +inline fun JsonObject.lessThan( + key: String, + target: T, + equals: Boolean = false +): Validated { val value = this.saveGet(T::class, key) ?: return NumericError( "$key is not exists ", Numeric.LessThan(target, equals) @@ -143,7 +149,10 @@ inline fun JsonObject.numeric( } } .filter { it.isInvalid } - .map { @Suppress("UNCHECKED_CAST") (it as Invalid>).e } + .map { + @Suppress("UNCHECKED_CAST") + (it as Invalid>).e + } return if (errors.isNotEmpty()) { NumericErrors("$key is invalid", errors).invalid() diff --git a/core/src/main/kotlin/id/yoframework/core/module/CoreModule.kt b/core/src/main/kotlin/id/yoframework/core/module/CoreModule.kt index cf0c3fd..74abbcf 100644 --- a/core/src/main/kotlin/id/yoframework/core/module/CoreModule.kt +++ b/core/src/main/kotlin/id/yoframework/core/module/CoreModule.kt @@ -68,5 +68,4 @@ class CoreModule( val validatorFactory = Validation.buildDefaultValidatorFactory() return validatorFactory.validator } - } diff --git a/db/src/main/kotlin/id/yoframework/db/Database.kt b/db/src/main/kotlin/id/yoframework/db/Database.kt index 8ae4201..be21f48 100644 --- a/db/src/main/kotlin/id/yoframework/db/Database.kt +++ b/db/src/main/kotlin/id/yoframework/db/Database.kt @@ -43,7 +43,6 @@ fun createHikariPoolDataSource( driver: String, config: HikariConfig.() -> Unit = {} ): HikariDataSource { - val hikariConfig = HikariConfig() hikariConfig.poolName = name diff --git a/detekt.yml b/detekt.yml index 779f0f7..ae562b6 100644 --- a/detekt.yml +++ b/detekt.yml @@ -41,7 +41,7 @@ complexity: threshold: 10 includeStaticDeclarations: false includePrivateDeclarations: false - ComplexMethod: + CyclomaticComplexMethod: active: true ignoreSingleWhenExpression: true LargeClass: @@ -93,10 +93,6 @@ style: active: true values: ['TODO:', 'FIXME:', 'STOPSHIP:', '@author'] excludes: ['**/detekt-rules-style/**/ForbiddenComment.kt'] - LibraryCodeMustSpecifyReturnType: - active: true - excludes: ['**/*.kt'] - includes: ['**/detekt-api/src/main/**/api/*.kt'] MaxLineLength: active: true excludes: ['**/test/**', '**/*.Test.kt', '**/*.Spec.kt'] @@ -126,3 +122,4 @@ style: performance: SpreadOperator: active: false + diff --git a/extra/src/main/kotlin/id/yoframework/extra/extension/codec/Base32.kt b/extra/src/main/kotlin/id/yoframework/extra/extension/codec/Base32.kt index ff799f7..a08ca5a 100644 --- a/extra/src/main/kotlin/id/yoframework/extra/extension/codec/Base32.kt +++ b/extra/src/main/kotlin/id/yoframework/extra/extension/codec/Base32.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package id.yoframework.extra.extension.codec +package id.yoframework.extra.extension.codec import id.yoframework.core.extension.string.abbreviate import org.apache.commons.codec.binary.Base32 @@ -33,7 +33,6 @@ fun String.base32EncodeToByteArray(): ByteArray { return base32Codec.encode(this.toByteArray()) } - fun T.base32Encode(): String { return base32Codec.encodeToString(this.serializeToByteArray()) } diff --git a/extra/src/main/kotlin/id/yoframework/extra/extension/codec/Base64.kt b/extra/src/main/kotlin/id/yoframework/extra/extension/codec/Base64.kt index 7bc9613..6dfa126 100644 --- a/extra/src/main/kotlin/id/yoframework/extra/extension/codec/Base64.kt +++ b/extra/src/main/kotlin/id/yoframework/extra/extension/codec/Base64.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package id.yoframework.extra.extension.codec +package id.yoframework.extra.extension.codec import id.yoframework.core.extension.string.abbreviate import org.apache.commons.codec.binary.Base64 diff --git a/extra/src/main/kotlin/id/yoframework/extra/extension/pebble/Pebble.kt b/extra/src/main/kotlin/id/yoframework/extra/extension/pebble/Pebble.kt index 940034a..cb5f099 100644 --- a/extra/src/main/kotlin/id/yoframework/extra/extension/pebble/Pebble.kt +++ b/extra/src/main/kotlin/id/yoframework/extra/extension/pebble/Pebble.kt @@ -38,7 +38,6 @@ object Pebble { engine.value() } } - } fun Pebble.compileStringTemplate(templateString: String, strictMode: Boolean = false): PebbleTemplate { diff --git a/extra/src/main/kotlin/id/yoframework/extra/extension/regex/Regex.kt b/extra/src/main/kotlin/id/yoframework/extra/extension/regex/Regex.kt index b31ff94..feb447b 100644 --- a/extra/src/main/kotlin/id/yoframework/extra/extension/regex/Regex.kt +++ b/extra/src/main/kotlin/id/yoframework/extra/extension/regex/Regex.kt @@ -64,11 +64,8 @@ fun String.matchWith(pattern: String): Boolean { * @return Matcher */ fun String.matchTo(pattern: String): Matcher { - if (pattern.isEmpty()) { - throw IllegalArgumentException("Regex pattern is empty") - } + require(pattern.isEmpty()) { "Regex pattern is empty" } val p: Pattern = Pattern.compile(pattern) - return p.matcher(this) } diff --git a/extra/src/main/kotlin/id/yoframework/extra/snowflake/SnowFlake.kt b/extra/src/main/kotlin/id/yoframework/extra/snowflake/SnowFlake.kt index 78e7ffd..c09e26e 100644 --- a/extra/src/main/kotlin/id/yoframework/extra/snowflake/SnowFlake.kt +++ b/extra/src/main/kotlin/id/yoframework/extra/snowflake/SnowFlake.kt @@ -24,8 +24,8 @@ import java.util.concurrent.atomic.AtomicInteger private class SnowFlake(private val machineId: Int) { init { - if (machineId >= MAX_MACHINE_ID || machineId < 0) { - throw IllegalArgumentException("Machine Number must between 0 - ${MAX_MACHINE_ID - 1}") + require(machineId >= MAX_MACHINE_ID || machineId < 0) { + "Machine Number must between 0 - ${MAX_MACHINE_ID - 1}" } } diff --git a/gradle.properties b/gradle.properties index e7a498d..087de9d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Set the project version -version=0.4.8 +version=0.4.9 # Set the JVM heap size org.gradle.jvmargs=-Xms1g -Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options=-Xmx1G @@ -8,10 +8,10 @@ org.gradle.jvmargs=-Xms1g -Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfM org.gradle.daemon=false # Enable the build cache -org.gradle.caching=false +org.gradle.caching=true # Enable parallelize build -org.gradle.parallel=false +org.gradle.parallel=true # Enable configure on demand -org.gradle.configureondemand=false +org.gradle.configureondemand=true diff --git a/grpc/src/main/kotlin/id/yoframework/grpc/Grpc.kt b/grpc/src/main/kotlin/id/yoframework/grpc/Grpc.kt index a5016d3..2998765 100644 --- a/grpc/src/main/kotlin/id/yoframework/grpc/Grpc.kt +++ b/grpc/src/main/kotlin/id/yoframework/grpc/Grpc.kt @@ -30,7 +30,6 @@ fun Vertx.buildGrpcServer( vararg services: BindableService, configuration: (VertxServerBuilder) -> VertxServerBuilder = { it } ): VertxServer { - return VertxServerBuilder .forAddress(this, host, port) .let { @@ -61,4 +60,3 @@ fun Vertx.buildGrpcChannel( return configuration(VertxChannelBuilder.forAddress(this, host, port)) .build() } - diff --git a/hystrix/src/main/kotlin/id/yoframework/hystrix/Hystrix.kt b/hystrix/src/main/kotlin/id/yoframework/hystrix/Hystrix.kt index b3d2ccf..cbcc5f4 100644 --- a/hystrix/src/main/kotlin/id/yoframework/hystrix/Hystrix.kt +++ b/hystrix/src/main/kotlin/id/yoframework/hystrix/Hystrix.kt @@ -51,7 +51,6 @@ fun buildObservableCommandConfig( .applyIf(commandPropertiesDefault) { andCommandPropertiesDefaults(it) } - } fun buildCommandConfig( @@ -61,7 +60,6 @@ fun buildCommandConfig( commandProperties: CommandPropertiesSetter? = null, threadPoolProperties: ThreadPoolPropertiesSetter? = null ): HystrixCommand.Setter { - return HystrixCommand.Setter .withGroupKey(groupKey) .applyIf(commandKey) { @@ -76,7 +74,6 @@ fun buildCommandConfig( .applyIf(threadPoolProperties) { andThreadPoolPropertiesDefaults(it) } - } fun buildCommandProperties( diff --git a/hystrix/src/main/kotlin/id/yoframework/hystrix/HystrixCommand.kt b/hystrix/src/main/kotlin/id/yoframework/hystrix/HystrixCommand.kt index 787ef04..8f555ad 100644 --- a/hystrix/src/main/kotlin/id/yoframework/hystrix/HystrixCommand.kt +++ b/hystrix/src/main/kotlin/id/yoframework/hystrix/HystrixCommand.kt @@ -50,5 +50,3 @@ open class HystrixCommand( } } } - - diff --git a/morphia/src/main/kotlin/id/yoframework/morphia/module/MorphiaModule.kt b/morphia/src/main/kotlin/id/yoframework/morphia/module/MorphiaModule.kt index ecf5a8a..cdb256c 100644 --- a/morphia/src/main/kotlin/id/yoframework/morphia/module/MorphiaModule.kt +++ b/morphia/src/main/kotlin/id/yoframework/morphia/module/MorphiaModule.kt @@ -63,7 +63,9 @@ class MorphiaModule { MongoClient(server) } else { val credentials = MongoCredential.createScramSha1Credential( - mongoUsername, databaseName, mongoPassword.toCharArray() + mongoUsername, + databaseName, + mongoPassword.toCharArray() ) val credentialsList = listOf(credentials) log.info("Initialize MongoClient with $host:$port") diff --git a/web/src/main/kotlin/id/yoframework/web/exception/Exception.kt b/web/src/main/kotlin/id/yoframework/web/exception/Exception.kt index 35cd784..f1de48a 100644 --- a/web/src/main/kotlin/id/yoframework/web/exception/Exception.kt +++ b/web/src/main/kotlin/id/yoframework/web/exception/Exception.kt @@ -52,11 +52,11 @@ data class RequestException( } infix fun T?.orNotFound(message: String): T { - return this ?: throw NullObjectException(message) + return this ?: throw NullObjectException(message) } infix fun T?.orBadRequest(message: String): T { - return this ?: throw BadRequestException(message) + return this ?: throw BadRequestException(message) } infix fun T?.orUnauthorized(message: String): T { diff --git a/web/src/main/kotlin/id/yoframework/web/extension/Request.kt b/web/src/main/kotlin/id/yoframework/web/extension/Request.kt index 8491477..4354c50 100644 --- a/web/src/main/kotlin/id/yoframework/web/extension/Request.kt +++ b/web/src/main/kotlin/id/yoframework/web/extension/Request.kt @@ -42,10 +42,10 @@ fun RoutingContext.principal(): JsonObject? { return this.user()?.principal() } -//@Suppress("deprecation") -//fun RoutingContext.securityUser(): SecurityUser? { +// @Suppress("deprecation") +// fun RoutingContext.securityUser(): SecurityUser? { // return this.user() as? SecurityUser -//} +// } fun RoutingContext.getRemoteIpAddress(): String { return this.request()?.remoteAddress()?.host() ?: "" diff --git a/web/src/main/kotlin/id/yoframework/web/extension/client/WebClient.kt b/web/src/main/kotlin/id/yoframework/web/extension/client/WebClient.kt index da8e220..7497f8a 100644 --- a/web/src/main/kotlin/id/yoframework/web/extension/client/WebClient.kt +++ b/web/src/main/kotlin/id/yoframework/web/extension/client/WebClient.kt @@ -50,7 +50,6 @@ suspend fun WebClient.postForm( val payload = formData.toList().fold(MultiMap.caseInsensitiveMultiMap()) { form, (key, value) -> form.set(key, value) } - return awaitResult { this.postAbs(absoluteURI).apply { headers().addAll(header) }.sendForm(payload, it) } @@ -86,4 +85,3 @@ fun HttpResponse.jsonBody(): JsonObject? { fun HttpResponse.jsonArrayBody(): JsonArray? { return this.bodyAsJsonArray() } - diff --git a/web/src/main/kotlin/id/yoframework/web/module/WebModule.kt b/web/src/main/kotlin/id/yoframework/web/module/WebModule.kt index 5777d3b..9934ecb 100644 --- a/web/src/main/kotlin/id/yoframework/web/module/WebModule.kt +++ b/web/src/main/kotlin/id/yoframework/web/module/WebModule.kt @@ -37,5 +37,4 @@ class WebModule { fun provideWebClient(vertx: Vertx): WebClient { return WebClient.create(vertx) } - }