From ad657a6136b93fdb2ac190ef371fef4cd8789868 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Thu, 1 Jun 2023 01:56:14 +0200 Subject: [PATCH] lint --- src/.editorconfig | 9 +++++++++ .../fr/postgresjson/definition/Function.kt | 4 +--- .../fr/postgresjson/definition/Parameter.kt | 4 ++-- .../fr/postgresjson/definition/Returns.kt | 14 ++++++------- .../definition/parse/ParsingFunction.kt | 20 +++++++++---------- .../definition/parse/ParsingHelper.kt | 5 +---- .../functionGenerator/FunctionGenerator.kt | 2 +- .../kotlin/fr/postgresjson/ConnectionTest.kt | 16 +++++++++------ 8 files changed, 41 insertions(+), 33 deletions(-) create mode 100644 src/.editorconfig diff --git a/src/.editorconfig b/src/.editorconfig new file mode 100644 index 0000000..66fbfb1 --- /dev/null +++ b/src/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +tab_width = 4 diff --git a/src/main/kotlin/fr/postgresjson/definition/Function.kt b/src/main/kotlin/fr/postgresjson/definition/Function.kt index ae3ce79..88846dc 100644 --- a/src/main/kotlin/fr/postgresjson/definition/Function.kt +++ b/src/main/kotlin/fr/postgresjson/definition/Function.kt @@ -1,8 +1,6 @@ package fr.postgresjson.definition import fr.postgresjson.definition.Parameter.Direction.IN -import fr.postgresjson.definition.parse.ScriptPart -import fr.postgresjson.definition.parse.trimSpace import java.nio.file.Path class Function( @@ -11,7 +9,7 @@ class Function( val returns: Returns, override val script: String, override val source: Path? = null, -): Resource, ParametersInterface { +) : Resource, ParametersInterface { // private fun NextScript.changeValue(block: (T) -> T): NextScript { // return NextScript(block(value), restOfScript) diff --git a/src/main/kotlin/fr/postgresjson/definition/Parameter.kt b/src/main/kotlin/fr/postgresjson/definition/Parameter.kt index 525b19c..f331519 100644 --- a/src/main/kotlin/fr/postgresjson/definition/Parameter.kt +++ b/src/main/kotlin/fr/postgresjson/definition/Parameter.kt @@ -29,8 +29,8 @@ class Parameter( override val type: ParameterType, val direction: Direction = Direction.IN, val default: String? = null, -): ParameterSimpleI { - constructor(name: String?, type: ParameterType, direction: String = "IN", default: String? = null): this( +) : ParameterSimpleI { + constructor(name: String?, type: ParameterType, direction: String = "IN", default: String? = null) : this( name = name, type = type, direction = direction.let { Direction.valueOf(direction.uppercase(Locale.getDefault())) }, diff --git a/src/main/kotlin/fr/postgresjson/definition/Returns.kt b/src/main/kotlin/fr/postgresjson/definition/Returns.kt index a9900da..7559f60 100644 --- a/src/main/kotlin/fr/postgresjson/definition/Returns.kt +++ b/src/main/kotlin/fr/postgresjson/definition/Returns.kt @@ -7,7 +7,7 @@ sealed class Returns( class Primitive( definition: String, isSetOf: Boolean, - ): Returns(definition, isSetOf) { + ) : Returns(definition, isSetOf) { val name = definition .trim('"') } @@ -15,7 +15,7 @@ sealed class Returns( class PrimitiveList( definition: String, isSetOf: Boolean, - ): Returns(definition, isSetOf) { + ) : Returns(definition, isSetOf) { val name = definition .drop(2) .trim('"') @@ -25,16 +25,16 @@ sealed class Returns( definition: String, isSetOf: Boolean, val parameters: List, - ): Returns(definition, isSetOf) { + ) : Returns(definition, isSetOf) { class ParameterTable( override val name: String, override val type: ParameterType, - ): ParameterSimpleI + ) : ParameterSimpleI } class Any( isSetOf: Boolean, - ): Returns("any", isSetOf) + ) : Returns("any", isSetOf) - class Void: Returns("void", false) -} \ No newline at end of file + class Void : Returns("void", false) +} diff --git a/src/main/kotlin/fr/postgresjson/definition/parse/ParsingFunction.kt b/src/main/kotlin/fr/postgresjson/definition/parse/ParsingFunction.kt index dd59ae6..7953310 100644 --- a/src/main/kotlin/fr/postgresjson/definition/parse/ParsingFunction.kt +++ b/src/main/kotlin/fr/postgresjson/definition/parse/ParsingFunction.kt @@ -2,7 +2,6 @@ package fr.postgresjson.definition.parse import fr.postgresjson.definition.Function import fr.postgresjson.definition.Parameter -import fr.postgresjson.definition.Returns.Void import fr.postgresjson.definition.Parameter.Direction import fr.postgresjson.definition.Parameter.Direction.IN import fr.postgresjson.definition.Parameter.Direction.INOUT @@ -10,6 +9,7 @@ import fr.postgresjson.definition.Parameter.Direction.OUT import fr.postgresjson.definition.ParameterType import fr.postgresjson.definition.Resource.ParseException import fr.postgresjson.definition.Returns +import fr.postgresjson.definition.Returns.Void import java.nio.file.Path import kotlin.text.RegexOption.IGNORE_CASE @@ -26,7 +26,6 @@ internal fun parseFunction(script: String, source: Path? = null): Function { return Function(name, parameters, returns, script, source) } - @Throws(FunctionNameMalformed::class) internal fun ScriptPart.getFunctionName(): NextScript { try { @@ -35,7 +34,7 @@ internal fun ScriptPart.getFunctionName(): NextScript { throw FunctionNameMalformed(this, e) } } -internal class FunctionNameMalformed(val script: ScriptPart, cause: Throwable? = null): +internal class FunctionNameMalformed(val script: ScriptPart, cause: Throwable? = null) : ParseException("Function name is malformed", cause) @Throws(FunctionNotFound::class) @@ -54,7 +53,7 @@ internal fun ScriptPart.getFunctionOrProcedure(): NextScript { ) } -internal class FunctionNotFound(val script: ScriptPart): +internal class FunctionNotFound(val script: ScriptPart) : ParseException("Function not found in script") internal fun ScriptPart.getParameters(): NextScript> { @@ -96,7 +95,7 @@ private fun ScriptPart.getParameterName(): NextScript { throw ParameterNameMalformed(this, e) } } -private class ParameterNameMalformed(val script: ScriptPart, cause: Throwable): +private class ParameterNameMalformed(val script: ScriptPart, cause: Throwable) : ParseException("Parameter name is malformed", cause) @Throws(ParameterTypeMalformed::class) @@ -125,11 +124,12 @@ private fun ScriptPart.getParameterType(): NextScript { name = name.value.trim(), precision = precision.value, scale = scale.value - ), fullType.nextScriptPart.restOfScript + ), + fullType.nextScriptPart.restOfScript ) } -internal class ParameterTypeMalformed(val script: ScriptPart, cause: Throwable): +internal class ParameterTypeMalformed(val script: ScriptPart, cause: Throwable) : ParseException("Parameter type is malformed", cause) @Throws(ParameterDefaultMalformed::class) @@ -146,7 +146,7 @@ private fun ScriptPart.getParameterDefault(): NextScript { } } -private class ParameterDefaultMalformed(val script: ScriptPart): +private class ParameterDefaultMalformed(val script: ScriptPart) : ParseException("Parameter default is malformed") /** @@ -156,5 +156,5 @@ internal fun ScriptPart.getReturns(): NextScript { return NextScript(Void(), "") } -class ParseError(message: String? = null, cause: Throwable? = null): - ParseException(message ?: "Parsing fail", cause) \ No newline at end of file +class ParseError(message: String? = null, cause: Throwable? = null) : + ParseException(message ?: "Parsing fail", cause) diff --git a/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt b/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt index 74d7333..e1fb89b 100644 --- a/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt +++ b/src/main/kotlin/fr/postgresjson/definition/parse/ParsingHelper.kt @@ -128,7 +128,6 @@ internal inline fun ScriptPart.change(block: String.() -> String): ScriptPart { return ScriptPart(restOfScript.run(block)) } - internal fun ScriptPart.getNextInteger(): NextScript { val trimmed = restOfScript.trimStart { !it.isDigit() } val digits = trimmed.takeWhile { it.isDigit() } @@ -136,8 +135,6 @@ internal fun ScriptPart.getNextInteger(): NextScript { return NextScript(digits.toIntOrNull(), restOfScript).trimSpace() } - - internal data class Status( var doubleQuoted: Boolean = false, // " var simpleQuoted: Boolean = false, // ' @@ -161,4 +158,4 @@ internal data class Context( } val nextChar: Char? get() = script.substring(index + 1).getOrNull(0) -} \ No newline at end of file +} diff --git a/src/main/kotlin/fr/postgresjson/functionGenerator/FunctionGenerator.kt b/src/main/kotlin/fr/postgresjson/functionGenerator/FunctionGenerator.kt index b2a3f6b..484661d 100644 --- a/src/main/kotlin/fr/postgresjson/functionGenerator/FunctionGenerator.kt +++ b/src/main/kotlin/fr/postgresjson/functionGenerator/FunctionGenerator.kt @@ -1,11 +1,11 @@ package fr.postgresjson.functionGenerator import fr.postgresjson.definition.Function -import fr.postgresjson.definition.Returns import fr.postgresjson.definition.Parameter import fr.postgresjson.definition.Parameter.Direction.IN import fr.postgresjson.definition.Parameter.Direction.INOUT import fr.postgresjson.definition.Parameter.Direction.OUT +import fr.postgresjson.definition.Returns import fr.postgresjson.utils.searchSqlFiles import fr.postgresjson.utils.toCamelCase import org.slf4j.Logger diff --git a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt index c861691..789c888 100644 --- a/src/test/kotlin/fr/postgresjson/ConnectionTest.kt +++ b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt @@ -9,26 +9,30 @@ import fr.postgresjson.serializer.toTypeReference import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.nulls.shouldBeNull import io.kotest.matchers.nulls.shouldNotBeNull -import org.amshove.kluent.`should be equal to` -import org.junit.jupiter.api.assertThrows import java.util.UUID import kotlin.reflect.full.hasAnnotation import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertTrue +import org.amshove.kluent.`should be equal to` +import org.junit.jupiter.api.assertThrows -class ConnectionTest : StringSpec({ +class ConnectionTest: StringSpec({ val connection = TestConnection() @SqlSerializable class ObjTest(val name: String, val id: UUID = UUID.fromString("2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00")) + @SqlSerializable class ObjTest2(val id: UUID, val title: String, var test: ObjTest?) + @SqlSerializable class ObjTest3(val id: UUID, val first: String, var second: String, var third: Int) + @SqlSerializable class ParameterObject(var third: String) + @SqlSerializable class ObjTestWithParameterObject(val id: UUID, var first: ParameterObject, var second: ParameterObject) class ObjTest4 @@ -112,7 +116,7 @@ class ConnectionTest : StringSpec({ "test call request without args" { val result: ObjTest? = connection.execute( "select json_build_object('id', '2c0243ed-ff4d-4b9f-a52b-e38c71b0ed00', 'name', 'myName')", - object : TypeReference() {} + object: TypeReference() {} ) { assertEquals("myName", this.deserialize()?.name) } @@ -121,7 +125,7 @@ class ConnectionTest : StringSpec({ } "test call request return null" { - val result: ObjTest? = connection.execute("select null;", object : TypeReference() {}) + val result: ObjTest? = connection.execute("select null;", object: TypeReference() {}) result.shouldBeNull() } @@ -137,7 +141,7 @@ class ConnectionTest : StringSpec({ ) assertThrows { - execute("select * from test where false;", object : TypeReference() {}) + execute("select * from test where false;", object: TypeReference() {}) } }