From 27b400fdf3bd8ce7120ca66fc1de39d3f1a5804a Mon Sep 17 00:00:00 2001 From: Tanguy Date: Tue, 2 Aug 2022 17:38:16 +0200 Subject: [PATCH] Fix styleCheck:usage (#27) --- protobuf_serialization.nimble | 8 +++++++- protobuf_serialization/files/type_generator.nim | 2 +- protobuf_serialization/numbers/varint.nim | 6 +++--- protobuf_serialization/stdlib_writers.nim | 6 +++--- tests/test_stdlib.nim | 4 ++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/protobuf_serialization.nimble b/protobuf_serialization.nimble index 088e171..f7a8602 100644 --- a/protobuf_serialization.nimble +++ b/protobuf_serialization.nimble @@ -14,9 +14,15 @@ requires "nim >= 1.2.0", "serialization", "combparser" +const styleCheckStyle = + if (NimMajor, NimMinor) < (1, 6): + "hint" + else: + "error" + proc test(args, path: string) = exec "nim " & getEnv("TEST_LANG", "c") & " " & getEnv("NIMFLAGS") & " " & args & - " -r --hints:off --skipParentCfg " & path + " -r --hints:off --skipParentCfg --styleCheck:usages --styleCheck:" & styleCheckStyle & " " & path task test, "Run all tests": #Explicitly specify the call depth limit in case the default changes in the future. diff --git a/protobuf_serialization/files/type_generator.nim b/protobuf_serialization/files/type_generator.nim index 3d95a7b..052e871 100644 --- a/protobuf_serialization/files/type_generator.nim +++ b/protobuf_serialization/files/type_generator.nim @@ -120,7 +120,7 @@ proc protoToTypesInternal*(filepath: string, proto: string): NimNode = result.add( newNimNode(nnkTypeDef).add( newNimNode(nnkPragmaExpr).add( - newNimNode(nnkPostFix).add(ident("*"), ident(name)), + newNimNode(nnkPostfix).add(ident("*"), ident(name)), newNimNode(nnkPragma).add(ident("protobuf3")) ), newEmptyNode(), diff --git a/protobuf_serialization/numbers/varint.nim b/protobuf_serialization/numbers/varint.nim index f6ca5af..c4271a7 100644 --- a/protobuf_serialization/numbers/varint.nim +++ b/protobuf_serialization/numbers/varint.nim @@ -119,7 +119,7 @@ func viSizeof(base: VarIntWrapped, raw: uint32 or uint64): int = result = max((log2trunc(raw) + 7) div 7, 1) func encodeVarInt*( - res: var openarray[byte], + res: var openArray[byte], outLen: var int, value: VarIntWrapped ): VarIntStatus = @@ -175,7 +175,7 @@ func encodeVarInt*(value: VarIntWrapped): seq[byte] = var outLen: int if encodeVarInt(result, outLen, value) != VarIntStatus.Success: when value is LUIntWrapped: - {.fatal: "LibP2P VarInts require using the following signature: `encodeVarInt(var openarray[byte], outLen: var int, value: VarIntWrapped): VarIntStatus`.".} + {.fatal: "LibP2P VarInts require using the following signature: `encodeVarInt(var openArray[byte], outLen: var int, value: VarIntWrapped): VarIntStatus`.".} else: doAssert(false) result.setLen(outLen) @@ -219,7 +219,7 @@ func decodeBinaryValue[E]( return VarIntStatus.Success func decodeVarInt*( - bytes: openarray[byte], + bytes: openArray[byte], inLen: var int, res: var VarIntWrapped ): VarIntStatus = diff --git a/protobuf_serialization/stdlib_writers.nim b/protobuf_serialization/stdlib_writers.nim index 1503216..a0d3dc1 100644 --- a/protobuf_serialization/stdlib_writers.nim +++ b/protobuf_serialization/stdlib_writers.nim @@ -16,7 +16,7 @@ proc encodeNumber[T](stream: OutputStream, value: T) = else: {.fatal: "Trying to encode a number which isn't wrapped. This should never happen.".} -proc stdLibToProtobuf[R]( +proc stdlibToProtobuf[R]( stream: OutputStream, _: typedesc[R], unusedFieldName: static string, @@ -124,7 +124,7 @@ proc stdlibToProtobuf[R, T]( var seqInstance: seq[T] for value in setInstance: seqInstance.add(value) - stream.stdLibToProtobuf(ty, fieldName, fieldNumber, seqInstance) + stream.stdlibToProtobuf(ty, fieldName, fieldNumber, seqInstance) proc stdlibToProtobuf[R, T]( stream: OutputStream, @@ -133,4 +133,4 @@ proc stdlibToProtobuf[R, T]( fieldNumber: int, setInstance: HashSet[T] ) {.inline.} = - stream.stdLibToProtobuf(ty, fieldName, fieldNumber, setInstance.toSeq()) + stream.stdlibToProtobuf(ty, fieldName, fieldNumber, setInstance.toSeq()) diff --git a/tests/test_stdlib.nim b/tests/test_stdlib.nim index eb32df9..9de580a 100644 --- a/tests/test_stdlib.nim +++ b/tests/test_stdlib.nim @@ -73,12 +73,12 @@ suite "Test Standard Lib Objects Encoding/Decoding": check Protobuf.decode(Protobuf.encode(setInstance), type(HashSet[string])) == setInstance test "Can encode/decode stdlib fields where a pragma was used to specify encoding": - let pragmad = PragmadStdLib( + let pragmad = PragmadStdlib( x: @[5'i32, -3'i32, 300'i32, -612'i32], #y: [6'u32, 4'u32, 301'u32, 613'u32, 216'u32], z: @[5.5'f32, 3.2'f32, 925.123].toHashSet() ) - check Protobuf.decode(Protobuf.encode(pragmad), PragmadStdLib) == pragmad + check Protobuf.decode(Protobuf.encode(pragmad), PragmadStdlib) == pragmad test "Can encode boolean seqs": #/arrays": let boold = BooldStdlib(