Skip to content

Commit d3f16a3

Browse files
committed
fix: fix linting issues in the compat layer
1 parent c9bfe82 commit d3f16a3

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"@typescript-eslint/quotes": ["error", "double"],
66
"require-await": "off",
77
"@typescript-eslint/strict-boolean-expressions": "off",
8+
"@typescript-eslint/no-extraneous-class": "off",
89
"@typescript-eslint/no-explicit-any": "off",
910
"no-await-in-loop": "off",
1011
"class-methods-use-this": "off"

src/compat.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ class Socket extends EventEmitter {
151151
case "stream":
152152
this._socket = new zmq.Stream()
153153
break
154+
default:
155+
throw new Error(`Invalid socket type: ${type}`)
154156
}
155157

156-
const recv = async () => {
158+
const recv = () => {
157159
this.once("_flushRecv", async () => {
158160
while (!this._socket.closed && !this._paused) {
159161
await this._recv()
@@ -257,7 +259,7 @@ class Socket extends EventEmitter {
257259
.catch(err => {
258260
process.nextTick(() => {
259261
if (cb) {
260-
cb(err)
262+
cb(err as Error)
261263
} else {
262264
this.emit("error", err)
263265
}
@@ -281,7 +283,7 @@ class Socket extends EventEmitter {
281283
.catch(err => {
282284
process.nextTick(() => {
283285
if (cb) {
284-
cb(err)
286+
cb(err as Error)
285287
} else {
286288
this.emit("error", err)
287289
}
@@ -303,10 +305,10 @@ class Socket extends EventEmitter {
303305

304306
send(
305307
message: zmq.MessageLike[] | zmq.MessageLike,
306-
flags: number | undefined | null = 0,
308+
givenFlags: number | undefined | null = 0,
307309
cb: Callback | undefined = undefined,
308310
) {
309-
flags = (flags ?? 0) | 0
311+
const flags = (givenFlags ?? 0) | 0
310312
this._msg = this._msg.concat(message)
311313
if ((flags & sendOptions.ZMQ_SNDMORE) === 0) {
312314
this._sendQueue.push([this._msg, cb])
@@ -474,8 +476,9 @@ class Socket extends EventEmitter {
474476
}
475477
}
476478

477-
setsockopt(option: number | keyof typeof shortOptions, value: any) {
478-
option = typeof option !== "number" ? shortOptions[option] : option
479+
setsockopt(givenOption: number | keyof typeof shortOptions, value: any) {
480+
const option =
481+
typeof givenOption === "number" ? givenOption : shortOptions[givenOption]
479482

480483
switch (option) {
481484
case longOptions.ZMQ_AFFINITY:
@@ -613,8 +616,9 @@ class Socket extends EventEmitter {
613616
return this
614617
}
615618

616-
getsockopt(option: number | keyof typeof shortOptions) {
617-
option = typeof option !== "number" ? shortOptions[option] : option
619+
getsockopt(givenOption: number | keyof typeof shortOptions) {
620+
const option =
621+
typeof givenOption !== "number" ? shortOptions[givenOption] : givenOption
618622

619623
switch (option) {
620624
case longOptions.ZMQ_AFFINITY:
@@ -736,10 +740,9 @@ for (const key in shortOptions) {
736740
get(this: Socket) {
737741
return this.getsockopt(shortOptions[key as keyof typeof shortOptions])
738742
},
739-
set(this: Socket, val: string | Buffer) {
740-
if ("string" === typeof val) {
741-
val = Buffer.from(val, "utf8")
742-
}
743+
set(this: Socket, givenVal: string | Buffer) {
744+
const val =
745+
typeof givenVal === "string" ? Buffer.from(givenVal, "utf8") : givenVal
743746
return this.setsockopt(
744747
shortOptions[key as keyof typeof shortOptions],
745748
val,

0 commit comments

Comments
 (0)