Fix for styleCheck:usages (#96)

This commit is contained in:
Tanguy 2021-12-27 11:27:21 +01:00 committed by GitHub
parent c2aae352f7
commit 908632aa07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 22 deletions

View File

@ -78,7 +78,7 @@ proc main() {.async.} =
try: try:
let ws = await connectServer(path, deflateFactory) let ws = await connectServer(path, deflateFactory)
while ws.readystate != ReadyState.Closed: while ws.readyState != ReadyState.Closed:
# echo back # echo back
let data = await ws.recvMsg() let data = await ws.recvMsg()
let opCode = if ws.binary: let opCode = if ws.binary:

View File

@ -31,7 +31,7 @@ proc rndBin*(size: int): seq[byte] =
proc waitForClose*(ws: WSSession) {.async.} = proc waitForClose*(ws: WSSession) {.async.} =
try: try:
while ws.readystate != ReadyState.Closed: while ws.readyState != ReadyState.Closed:
discard await ws.recvMsg() discard await ws.recvMsg()
except CatchableError: except CatchableError:
trace "Closing websocket" trace "Closing websocket"

View File

@ -73,7 +73,7 @@ suite "UTF-8 DFA validator":
proc waitForClose(ws: WSSession) {.async.} = proc waitForClose(ws: WSSession) {.async.} =
try: try:
while ws.readystate != ReadyState.Closed: while ws.readyState != ReadyState.Closed:
discard await ws.recvMsg() discard await ws.recvMsg()
except CatchableError: except CatchableError:
trace "Closing websocket" trace "Closing websocket"

View File

@ -26,7 +26,7 @@ requires "zlib"
task test, "run tests": task test, "run tests":
# dont't need to run it, only want to test if it is compileable # dont't need to run it, only want to test if it is compileable
exec "nim c -c --verbosity:0 --hints:off -d:chronicles_log_level=TRACE -d:chronicles_sinks:json ./tests/testcommon" exec "nim c -c --verbosity:0 --hints:off -d:chronicles_log_level=TRACE -d:chronicles_sinks:json --styleCheck:usages --styleCheck:error ./tests/testcommon"
exec "nim --hints:off c -r --opt:speed -d:debug --verbosity:0 --hints:off -d:chronicles_log_level=INFO ./tests/testcommon.nim" exec "nim --hints:off c -r --opt:speed -d:debug --verbosity:0 --hints:off -d:chronicles_log_level=INFO ./tests/testcommon.nim"
rmFile "./tests/testcommon" rmFile "./tests/testcommon"

View File

@ -19,7 +19,7 @@ type
TokenKind = enum TokenKind = enum
tkError tkError
tkSemcol tkSemCol
tkComma tkComma
tkEqual tkEqual
tkName tkName
@ -38,7 +38,7 @@ const
'[','{',']','}', ';',':','\'',',','<','.','>','/','?','|'} '[','{',']','}', ';',':','\'',',','<','.','>','/','?','|'}
QCHAR = WHITES + LCHAR + SEPARATORS QCHAR = WHITES + LCHAR + SEPARATORS
proc parseName[T: BChar](lex: var Lexer, data: openarray[T]) = proc parseName[T: BChar](lex: var Lexer, data: openArray[T]) =
while lex.pos < data.len: while lex.pos < data.len:
let cc = data[lex.pos] let cc = data[lex.pos]
if cc notin LCHAR: if cc notin LCHAR:
@ -46,7 +46,7 @@ proc parseName[T: BChar](lex: var Lexer, data: openarray[T]) =
lex.token.add cc lex.token.add cc
inc lex.pos inc lex.pos
proc parseQuoted[T: BChar](lex: var Lexer, data: openarray[T]) = proc parseQuoted[T: BChar](lex: var Lexer, data: openArray[T]) =
while lex.pos < data.len: while lex.pos < data.len:
let cc = data[lex.pos] let cc = data[lex.pos]
case cc: case cc:
@ -70,7 +70,7 @@ proc parseQuoted[T: BChar](lex: var Lexer, data: openarray[T]) =
lex.tok = tkError lex.tok = tkError
proc next[T: BChar](lex: var Lexer, data: openarray[T]) = proc next[T: BChar](lex: var Lexer, data: openArray[T]) =
while lex.pos < data.len: while lex.pos < data.len:
if data[lex.pos] notin WHITES: if data[lex.pos] notin WHITES:
break break
@ -85,7 +85,7 @@ proc next[T: BChar](lex: var Lexer, data: openarray[T]) =
case c case c
of ';': of ';':
inc lex.pos inc lex.pos
lex.tok = tkSemcol lex.tok = tkSemCol
return return
of ',': of ',':
inc lex.pos inc lex.pos
@ -107,7 +107,7 @@ proc next[T: BChar](lex: var Lexer, data: openarray[T]) =
lex.tok = tkError lex.tok = tkError
return return
proc parseExt*[T: BChar](data: openarray[T], output: var seq[AppExt]): bool = proc parseExt*[T: BChar](data: openArray[T], output: var seq[AppExt]): bool =
var lex: Lexer var lex: Lexer
var ext: AppExt var ext: AppExt
lex.next(data) lex.next(data)

View File

@ -147,7 +147,7 @@ proc handleTlsConnCb(
maxVersion = tlsHttpServer.maxVersion, maxVersion = tlsHttpServer.maxVersion,
flags = tlsHttpServer.tlsFlags) flags = tlsHttpServer.tlsFlags)
var stream: ASyncStream var stream: AsyncStream
try: try:
stream = AsyncStream( stream = AsyncStream(
reader: tlsStream.reader, reader: tlsStream.reader,

View File

@ -133,7 +133,7 @@ proc send*(
proc handleClose*( proc handleClose*(
ws: WSSession, ws: WSSession,
frame: Frame, frame: Frame,
payLoad: seq[byte] = @[]) {.async.} = payload: seq[byte] = @[]) {.async.} =
## Handle close sequence ## Handle close sequence
## ##
@ -161,7 +161,7 @@ proc handleClose*(
"Invalid close frame with payload length 1!") "Invalid close frame with payload length 1!")
else: else:
try: try:
code = StatusCodes(uint16.fromBytesBE(payLoad[0..<2])) code = StatusCodes(uint16.fromBytesBE(payload[0..<2]))
except RangeError: except RangeError:
raise newException(WSInvalidCloseCodeError, raise newException(WSInvalidCloseCodeError,
"Status code out of range!") "Status code out of range!")
@ -178,7 +178,7 @@ proc handleClose*(
&"Can't use reserved status code: {code}") &"Can't use reserved status code: {code}")
# remaining payload bytes are reason for closing # remaining payload bytes are reason for closing
reason = string.fromBytes(payLoad[2..payLoad.high]) reason = string.fromBytes(payload[2..payload.high])
if not ws.binary and validateUTF8(reason) == false: if not ws.binary and validateUTF8(reason) == false:
raise newException(WSInvalidUTF8, raise newException(WSInvalidUTF8,
@ -231,14 +231,14 @@ proc handleControl*(ws: WSSession, frame: Frame) {.async.} =
raise newException(WSPayloadTooLarge, raise newException(WSPayloadTooLarge,
"Control message payload is greater than 125 bytes!") "Control message payload is greater than 125 bytes!")
var payLoad = newSeq[byte](frame.length.int) var payload = newSeq[byte](frame.length.int)
if frame.length > 0: if frame.length > 0:
payLoad.setLen(frame.length.int) payload.setLen(frame.length.int)
# Read control frame payload. # Read control frame payload.
await ws.stream.reader.readExactly(addr payLoad[0], frame.length.int) await ws.stream.reader.readExactly(addr payload[0], frame.length.int)
if frame.mask: if frame.mask:
mask( mask(
payLoad.toOpenArray(0, payLoad.high), payload.toOpenArray(0, payload.high),
frame.maskKey) frame.maskKey)
# Process control frame payload. # Process control frame payload.
@ -246,20 +246,20 @@ proc handleControl*(ws: WSSession, frame: Frame) {.async.} =
of Opcode.Ping: of Opcode.Ping:
if not isNil(ws.onPing): if not isNil(ws.onPing):
try: try:
ws.onPing(payLoad) ws.onPing(payload)
except CatchableError as exc: except CatchableError as exc:
trace "Exception in Ping callback, this is most likely a bug", exc = exc.msg trace "Exception in Ping callback, this is most likely a bug", exc = exc.msg
# send pong to remote # send pong to remote
await ws.send(payLoad, Opcode.Pong) await ws.send(payload, Opcode.Pong)
of Opcode.Pong: of Opcode.Pong:
if not isNil(ws.onPong): if not isNil(ws.onPong):
try: try:
ws.onPong(payLoad) ws.onPong(payload)
except CatchableError as exc: except CatchableError as exc:
trace "Exception in Pong callback, this is most likely a bug", exc = exc.msg trace "Exception in Pong callback, this is most likely a bug", exc = exc.msg
of Opcode.Close: of Opcode.Close:
await ws.handleClose(frame, payLoad) await ws.handleClose(frame, payload)
else: else:
raise newException(WSInvalidOpcodeError, "Invalid control opcode!") raise newException(WSInvalidOpcodeError, "Invalid control opcode!")