Skip to content

Commit c2c9f90

Browse files
committed
fix: fix various linting warnings
1 parent 11dc0f8 commit c2c9f90

16 files changed

+100
-51
lines changed

.eslintrc

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
{
2-
"plugins": ["prettier"],
3-
"extends": ["plugin:prettier/recommended", "eslint-config-atomic"],
2+
"plugins": [
3+
"prettier"
4+
],
5+
"extends": [
6+
"eslint-config-atomic"
7+
],
48
"rules": {
5-
"@typescript-eslint/quotes": ["error", "double"],
6-
"require-await": "off"
9+
"@typescript-eslint/quotes": [
10+
"error",
11+
"double"
12+
],
13+
"require-await": "off",
14+
"@typescript-eslint/strict-boolean-expressions": "off",
15+
"@typescript-eslint/no-explicit-any": "off",
16+
"no-await-in-loop": "off",
17+
"class-methods-use-this": "off"
718
},
819
"ignorePatterns": [
920
"node_modules/",
@@ -15,6 +26,8 @@
1526
"script/*.js",
1627
"script/*.d.ts",
1728
"docs/",
18-
"docs-raw/"
29+
"docs-raw/",
30+
"test/unit/compat/",
31+
"test/bench/"
1932
]
2033
}

examples/majordomo/broker.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Broker {
1818
await this.socket.bind(this.address)
1919

2020
const loop = async () => {
21-
for await (const [sender, blank, header, ...rest] of this.socket) {
21+
for await (const [sender, _blank, header, ...rest] of this.socket) {
2222
switch (header.toString()) {
2323
case Header.Client:
2424
this.handleClient(sender, ...rest)
@@ -32,7 +32,7 @@ export class Broker {
3232
}
3333
}
3434

35-
loop()
35+
return loop()
3636
}
3737

3838
async stop() {
@@ -56,8 +56,10 @@ export class Broker {
5656
}
5757

5858
case Message.Reply: {
59-
const [client, blank, ...rep] = rest
60-
this.dispatchReply(worker, client, ...rep)
59+
const [client, _blank, ...rep] = rest
60+
this.dispatchReply(worker, client, ...rep).catch(err => {
61+
console.error(err)
62+
})
6163
break
6264
}
6365

@@ -85,7 +87,7 @@ export class Broker {
8587

8688
dispatchReply(worker: Buffer, client: Buffer, ...rep: Buffer[]) {
8789
const service = this.getWorkerService(worker)
88-
this.getService(service).dispatchReply(worker, client, ...rep)
90+
return this.getService(service).dispatchReply(worker, client, ...rep)
8991
}
9092

9193
deregister(worker: Buffer) {

examples/majordomo/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {Broker} from "./broker"
44
import {Worker} from "./worker"
55

66
async function sleep(msec: number) {
7-
return new Promise(resolve => setTimeout(resolve, msec))
7+
return new Promise(resolve => {
8+
setTimeout(resolve, msec)
9+
})
810
}
911

1012
class TeaWorker extends Worker {
@@ -40,7 +42,7 @@ async function request(
4042
await socket.send(["MDPC01", service, ...req])
4143

4244
try {
43-
const [blank, header, ...res] = await socket.receive()
45+
const [_blank, _header, ...res] = await socket.receive()
4446
console.log(`received '${res.join(", ")}' from '${service}'`)
4547
return res
4648
} catch (err) {
@@ -50,9 +52,9 @@ async function request(
5052

5153
async function main() {
5254
for (const worker of workers) {
53-
worker.start()
55+
await worker.start()
5456
}
55-
broker.start()
57+
await broker.start()
5658

5759
/* Requests are issued in parallel. */
5860
await Promise.all([
@@ -68,9 +70,9 @@ async function main() {
6870
])
6971

7072
for (const worker of workers) {
71-
worker.stop()
73+
await worker.stop()
7274
}
73-
broker.stop()
75+
await broker.stop()
7476
}
7577

7678
main().catch(err => {

examples/majordomo/service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Service {
1515

1616
dispatchRequest(client: Buffer, ...req: Buffer[]) {
1717
this.requests.push([client, req])
18-
this.dispatchPending()
18+
return this.dispatchPending()
1919
}
2020

2121
async dispatchReply(worker: Buffer, client: Buffer, ...rep: Buffer[]) {
@@ -28,12 +28,15 @@ export class Service {
2828

2929
await this.socket.send([client, null, Header.Client, this.name, ...rep])
3030

31-
this.dispatchPending()
31+
return this.dispatchPending()
3232
}
3333

3434
async dispatchPending() {
3535
while (this.workers.size && this.requests.length) {
36-
const [key, worker] = this.workers.entries().next().value!
36+
const [key, worker] = this.workers.entries().next().value as [
37+
string,
38+
Buffer,
39+
]
3740
this.workers.delete(key)
3841
const [client, req] = this.requests.shift()!
3942

@@ -42,6 +45,7 @@ export class Service {
4245
`${client.toString("hex")} req -> ${worker.toString("hex")}`,
4346
)
4447

48+
// eslint-disable-next-line no-await-in-loop
4549
await this.socket.send([
4650
worker,
4751
null,
@@ -59,14 +63,14 @@ export class Service {
5963
`registered worker ${worker.toString("hex")} for '${this.name}'`,
6064
)
6165
this.workers.set(worker.toString("hex"), worker)
62-
this.dispatchPending()
66+
return this.dispatchPending()
6367
}
6468

6569
deregister(worker: Buffer) {
6670
console.log(
6771
`deregistered worker ${worker.toString("hex")} for '${this.name}'`,
6872
)
6973
this.workers.delete(worker.toString("hex"))
70-
this.dispatchPending()
74+
return this.dispatchPending()
7175
}
7276
}

examples/majordomo/worker.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ export class Worker {
1616
await this.socket.send([null, Header.Worker, Message.Ready, this.service])
1717

1818
const loop = async () => {
19-
for await (const [blank1, header, type, client, blank2, ...req] of this
20-
.socket) {
19+
for await (const [
20+
_blank1,
21+
_header,
22+
_type,
23+
client,
24+
_blank2,
25+
...req
26+
] of this.socket) {
2127
const rep = await this.process(...req)
2228
try {
2329
await this.socket.send([
@@ -34,7 +40,7 @@ export class Worker {
3440
}
3541
}
3642

37-
loop()
43+
return loop()
3844
}
3945

4046
async stop() {

examples/threaded-worker/processor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export class Processor {
2222
this.input.bind("inproc://input"),
2323
this.output.bind("inproc://output"),
2424
this.signal.bind("inproc://signal"),
25-
new Promise(resolve => setTimeout(resolve, 100)),
25+
new Promise(resolve => {
26+
setTimeout(resolve, 100)
27+
}),
2628
])
2729

2830
this.exit = Promise.all([ThreadedWorker.spawn(this.threads)])

examples/threaded-worker/threaded-worker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ export class ThreadedWorker {
4343
const listen = async () => {
4444
for await (const [sig] of this.signal) {
4545
if (sig.toString() === "stop") {
46-
this.stop()
46+
await this.stop()
4747
}
4848
}
4949
}
5050

51-
listen()
51+
listen().catch(err => {
52+
throw err
53+
})
5254
}
5355

5456
async stop() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"format": "prettier --write .",
104104
"test.electron.renderer": "run-s build && electron-mocha --renderer",
105105
"lint.clang-format": "clang-format -i -style=file ./src/*.cc ./src/*.h ./src/util/*.h",
106-
"lint-test.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/",
106+
"lint-test.eslint": "eslint ./**/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/",
107107
"lint.eslint": "pnpm run lint-test.eslint --fix",
108108
"lint": "run-p lint.eslint lint.clang-format",
109109
"lint-test": "run-s lint-test.eslint",

src/.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"extends": ["../.eslintrc", "eslint-config-atomic/strict"]
2+
"extends": ["../.eslintrc"]
33
}

src/compat.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/* eslint-disable @typescript-eslint/camelcase */
2-
/* eslint-disable @typescript-eslint/no-var-requires */
3-
41
/* The API of the compatibility layer and parts of the implementation has been
52
adapted from the original ZeroMQ.js version (up to 5.x) for which the license
63
and copyright notice is reproduced below.

test/.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"extends": "../.eslintrc",
3+
"ignorePatterns": [
4+
"unit/compat/",
5+
"bench/",
6+
"node_modules"
7+
],
38
"rules": {
49
"no-invalid-this": "off",
510
"no-inner-declarations": "off",
@@ -11,6 +16,8 @@
1116
"@typescript-eslint/no-unused-vars": "off",
1217
"@typescript-eslint/explicit-function-return-type": "off",
1318
"no-await-in-loop": "off",
19+
"no-shadow": "off",
20+
"@typescript-eslint/no-shadow": "off",
1421
"require-await": "off",
1522
"import/no-extraneous-dependencies": "off"
1623
}

test/unit/context-process-exit-test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ describe("context process exit", function () {
3333
const {code, is_timeout} = await createProcess(() => {
3434
const socket1 = new zmq.Dealer()
3535
socket1.connect("inproc://foo")
36-
socket1.receive()
36+
socket1.receive().catch(err => {
37+
throw err
38+
})
3739
})
3840

3941
assert.equal(code, -1)
@@ -46,7 +48,9 @@ describe("context process exit", function () {
4648
zmq.context.blocky = true
4749
const socket1 = new zmq.Dealer({linger: 1000})
4850
socket1.connect("tcp://127.0.0.1:4567")
49-
socket1.send(null)
51+
socket1.send(null).catch(err => {
52+
throw err
53+
})
5054
})
5155

5256
if (semver.satisfies(zmq.version, ">= 4.2")) {
@@ -68,7 +72,9 @@ describe("context process exit", function () {
6872
zmq.context.blocky = false
6973
const socket1 = new zmq.Dealer({linger: 1000})
7074
socket1.connect("tcp://127.0.0.1:4567")
71-
socket1.send(null)
75+
socket1.send(null).catch(err => {
76+
throw err
77+
})
7278
})
7379

7480
assert.match(
@@ -83,7 +89,9 @@ describe("context process exit", function () {
8389
zmq.context.blocky = true
8490
const socket1 = new zmq.Dealer({linger: 50})
8591
socket1.connect("tcp://127.0.0.1:4567")
86-
socket1.send(null)
92+
socket1.send(null).catch(err => {
93+
throw err
94+
})
8795
})
8896

8997
assert.equal(stderr.toString(), "")

test/unit/socket-send-receive-test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,16 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
248248
it("should deliver messages coercible to string", async function () {
249249
const messages = [
250250
null,
251-
/* eslint-disable-next-line @typescript-eslint/no-empty-function */
252-
function () {},
251+
function () {
252+
// nothing
253+
},
253254
16.19,
254255
true,
255256
{},
256257
Promise.resolve(),
257258
]
258259
for (const msg of messages) {
259-
await sockA.send(msg as any)
260+
await sockA.send(msg as zmq.MessageLike)
260261
}
261262

262263
const received: string[] = []
@@ -440,10 +441,10 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
440441

441442
const echo = async (sock: zmq.Pair) => {
442443
const msg = await sock.receive()
443-
sock.send(msg)
444+
await sock.send(msg)
444445
}
445446

446-
echo(sockB)
447+
await echo(sockB)
447448

448449
const [final] = await sockA.receive()
449450
final.writeUInt8(0x40, 0)

test/unit/socket-zap-test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ for (const proto of testProtos("tcp", "ipc")) {
88
describe(`socket with ${proto} zap`, function () {
99
let sockA: zmq.Pair
1010
let sockB: zmq.Pair
11-
let handler: ZapHandler
11+
let handler: ZapHandler | undefined
1212

1313
beforeEach(function () {
1414
sockA = new zmq.Pair()
@@ -230,7 +230,9 @@ class ValidatingZapHandler extends ZapHandler {
230230
constructor(details: ZapDetails) {
231231
super()
232232
this.details = details
233-
this.run()
233+
this.run().catch(err => {
234+
throw err
235+
})
234236
}
235237

236238
handle(request: Buffer[]) {
@@ -274,6 +276,8 @@ class CustomZapHandler extends ZapHandler {
274276
constructor(handler: ZapHandler["handle"]) {
275277
super()
276278
this.handle = handler
277-
this.run()
279+
this.run().catch(err => {
280+
throw err
281+
})
278282
}
279283
}

test/unit/typings-compatibility-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ const srcStr = readFile(srcFile, "utf8").then(content => {
5555
const tscTestBasePath = path.resolve(__dirname, "..", "typings-compatibility")
5656
const templateSrcPath = path.resolve(tscTestBasePath, "template")
5757

58-
function addLibs(libs: string[], targetList: string[]): string[] {
59-
if (!targetList) {
60-
targetList = libs
58+
function addLibs(libs: string[], targetList: string[] | undefined): string[] {
59+
if (targetList === undefined) {
60+
return libs
6161
} else {
6262
libs.forEach(l => {
6363
if (!targetList.find(e => e.toLowerCase() === l.toLowerCase())) {
@@ -153,7 +153,7 @@ async function prepareTestPackage(
153153
if (tsVer.requiredLibs) {
154154
tsConfig.compilerOptions.lib = addLibs(
155155
tsVer.requiredLibs,
156-
tsConfig.compilerOptions.lib as string[],
156+
tsConfig.compilerOptions.lib as string[] | undefined,
157157
)
158158
}
159159
return writeJson(path.resolve(tscTargetPath, "tsconfig.json"), tsConfig)

0 commit comments

Comments
 (0)