From 86101df73ce1aaa066824471f4b52a149750d279 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Fri, 14 Oct 2022 22:39:06 +0200 Subject: [PATCH] clean syntax --- build.gradle.kts | 2 +- docker-compose.yml | 2 +- .../kotlin/fr/postgresjson/definition/Function.kt | 11 ++++------- .../kotlin/fr/postgresjson/utils/LoggerDelegate.kt | 2 +- .../kotlin/fr/postgresjson/utils/searchSqlFiles.kt | 2 +- src/test/kotlin/fr/postgresjson/ConnectionTest.kt | 6 +++--- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 78fc83f..9d0c400 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -41,7 +41,7 @@ tasks.test { useJUnit() useJUnitPlatform() systemProperty("junit.jupiter.execution.parallel.enabled", true) - if (disableLint.toBoolean() == false) { + if (!disableLint.toBoolean()) { finalizedBy(tasks.ktlintCheck) } } diff --git a/docker-compose.yml b/docker-compose.yml index 0e8ea03..e36c83c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: context: docker/postgresql restart: always ports: - - 5555:5432 + - "5555:5432" environment: POSTGRES_DB: json_test POSTGRES_USER: test diff --git a/src/main/kotlin/fr/postgresjson/definition/Function.kt b/src/main/kotlin/fr/postgresjson/definition/Function.kt index 02c6dc1..1afa240 100644 --- a/src/main/kotlin/fr/postgresjson/definition/Function.kt +++ b/src/main/kotlin/fr/postgresjson/definition/Function.kt @@ -21,7 +21,7 @@ class Function( val queryMatch = functionRegex.find(script) if (queryMatch !== null) { - val functionName = queryMatch.groups.get("name")?.value?.trim() ?: error("Function name not found") + val functionName = queryMatch.groups["name"]?.value?.trim() ?: error("Function name not found") val functionParameters = queryMatch.groups["params"]?.value?.trim() this.returns = queryMatch.groups["return"]?.value?.trim() ?: "" @@ -51,15 +51,12 @@ class Function( fun getDefinition(): String { return parameters .filter { it.direction == Parameter.Direction.IN } - .joinToString(", ") { "${it.name} ${it.type}" }.let { - "$name ($it)" - } + .joinToString(", ") { "${it.name} ${it.type}" } + .let { "$name ($it)" } } fun getParametersIndexedByName(): Map { - return parameters.map { - it.name to it - }.toMap() + return parameters.associateBy { it.name } } infix fun `has same definition`(other: Function): Boolean { diff --git a/src/main/kotlin/fr/postgresjson/utils/LoggerDelegate.kt b/src/main/kotlin/fr/postgresjson/utils/LoggerDelegate.kt index bc27e00..3435a3e 100644 --- a/src/main/kotlin/fr/postgresjson/utils/LoggerDelegate.kt +++ b/src/main/kotlin/fr/postgresjson/utils/LoggerDelegate.kt @@ -6,5 +6,5 @@ import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty internal class LoggerDelegate : ReadOnlyProperty { - override fun getValue(thisRef: R, property: KProperty<*>) = LoggerFactory.getLogger(thisRef.javaClass.packageName) + override fun getValue(thisRef: R, property: KProperty<*>): Logger = LoggerFactory.getLogger(thisRef.javaClass.packageName) } diff --git a/src/main/kotlin/fr/postgresjson/utils/searchSqlFiles.kt b/src/main/kotlin/fr/postgresjson/utils/searchSqlFiles.kt index 36f2e68..4e41e21 100644 --- a/src/main/kotlin/fr/postgresjson/utils/searchSqlFiles.kt +++ b/src/main/kotlin/fr/postgresjson/utils/searchSqlFiles.kt @@ -14,7 +14,7 @@ import kotlin.streams.asSequence fun URL.searchSqlFiles() = this.toURI().searchSqlFiles() -fun URI.searchSqlFiles() = sequence { +fun URI.searchSqlFiles() = sequence { val logger: Logger = LoggerFactory.getLogger("sqlFilesSearch") val uri: URI = this@searchSqlFiles logger.debug("""SQL files found in "${uri.toString().substringAfter('!')}" :""") diff --git a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt index e3545c0..bca640b 100644 --- a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt +++ b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt @@ -9,15 +9,15 @@ import fr.postgresjson.entity.Parameter import fr.postgresjson.entity.UuidEntity import fr.postgresjson.serializer.deserialize import fr.postgresjson.serializer.toTypeReference +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.api.assertThrows import java.util.UUID import kotlin.test.assertContains import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertNull import kotlin.test.assertTrue -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.TestInstance -import org.junit.jupiter.api.assertThrows @TestInstance(TestInstance.Lifecycle.PER_CLASS) class ConnectionTest : TestAbstract() {