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.

0 commit comments

Comments
 (0)