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:
let ws = await connectServer(path, deflateFactory)
while ws.readystate != ReadyState.Closed:
while ws.readyState != ReadyState.Closed:
# echo back
let data = await ws.recvMsg()
let opCode = if ws.binary:

View File

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

View File

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

View File

@ -26,7 +26,7 @@ requires "zlib"
task test, "run tests":
# 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"
rmFile "./tests/testcommon"

View File

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

View File

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

View File

@ -133,7 +133,7 @@ proc send*(
proc handleClose*(
ws: WSSession,
frame: Frame,
payLoad: seq[byte] = @[]) {.async.} =
payload: seq[byte] = @[]) {.async.} =
## Handle close sequence
##
@ -161,7 +161,7 @@ proc handleClose*(
"Invalid close frame with payload length 1!")
else:
try:
code = StatusCodes(uint16.fromBytesBE(payLoad[0..<2]))
code = StatusCodes(uint16.fromBytesBE(payload[0..<2]))
except RangeError:
raise newException(WSInvalidCloseCodeError,
"Status code out of range!")
@ -178,7 +178,7 @@ proc handleClose*(
&"Can't use reserved status code: {code}")
# 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:
raise newException(WSInvalidUTF8,
@ -231,14 +231,14 @@ proc handleControl*(ws: WSSession, frame: Frame) {.async.} =
raise newException(WSPayloadTooLarge,
"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:
payLoad.setLen(frame.length.int)
payload.setLen(frame.length.int)
# 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:
mask(
payLoad.toOpenArray(0, payLoad.high),
payload.toOpenArray(0, payload.high),
frame.maskKey)
# Process control frame payload.
@ -246,20 +246,20 @@ proc handleControl*(ws: WSSession, frame: Frame) {.async.} =
of Opcode.Ping:
if not isNil(ws.onPing):
try:
ws.onPing(payLoad)
ws.onPing(payload)
except CatchableError as exc:
trace "Exception in Ping callback, this is most likely a bug", exc = exc.msg
# send pong to remote
await ws.send(payLoad, Opcode.Pong)
await ws.send(payload, Opcode.Pong)
of Opcode.Pong:
if not isNil(ws.onPong):
try:
ws.onPong(payLoad)
ws.onPong(payload)
except CatchableError as exc:
trace "Exception in Pong callback, this is most likely a bug", exc = exc.msg
of Opcode.Close:
await ws.handleClose(frame, payLoad)
await ws.handleClose(frame, payload)
else:
raise newException(WSInvalidOpcodeError, "Invalid control opcode!")