Skip to content

Commit

Permalink
fix: fix various linting warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 17, 2024
1 parent 11dc0f8 commit c2c9f90
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 51 deletions.
23 changes: 18 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
{
"plugins": ["prettier"],
"extends": ["plugin:prettier/recommended", "eslint-config-atomic"],
"plugins": [
"prettier"
],
"extends": [
"eslint-config-atomic"
],
"rules": {
"@typescript-eslint/quotes": ["error", "double"],
"require-await": "off"
"@typescript-eslint/quotes": [
"error",
"double"
],
"require-await": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-await-in-loop": "off",
"class-methods-use-this": "off"
},
"ignorePatterns": [
"node_modules/",
Expand All @@ -15,6 +26,8 @@
"script/*.js",
"script/*.d.ts",
"docs/",
"docs-raw/"
"docs-raw/",
"test/unit/compat/",
"test/bench/"
]
}
12 changes: 7 additions & 5 deletions examples/majordomo/broker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Broker {
await this.socket.bind(this.address)

const loop = async () => {
for await (const [sender, blank, header, ...rest] of this.socket) {
for await (const [sender, _blank, header, ...rest] of this.socket) {
switch (header.toString()) {
case Header.Client:
this.handleClient(sender, ...rest)

Check warning on line 24 in examples/majordomo/broker.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04, 18, x64, x64, x64, false)

Unsafe argument of type `Router` assigned to a parameter of type `Buffer`

Check warning on line 24 in examples/majordomo/broker.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04, 18, x64, x64, x64, false)

Unsafe spread of an `any` type
Expand All @@ -32,7 +32,7 @@ export class Broker {
}
}

loop()
return loop()
}

async stop() {
Expand All @@ -56,8 +56,10 @@ export class Broker {
}

case Message.Reply: {
const [client, blank, ...rep] = rest
this.dispatchReply(worker, client, ...rep)
const [client, _blank, ...rep] = rest
this.dispatchReply(worker, client, ...rep).catch(err => {
console.error(err)
})
break
}

Expand Down Expand Up @@ -85,7 +87,7 @@ export class Broker {

dispatchReply(worker: Buffer, client: Buffer, ...rep: Buffer[]) {
const service = this.getWorkerService(worker)
this.getService(service).dispatchReply(worker, client, ...rep)
return this.getService(service).dispatchReply(worker, client, ...rep)
}

deregister(worker: Buffer) {
Expand Down
14 changes: 8 additions & 6 deletions examples/majordomo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {Broker} from "./broker"
import {Worker} from "./worker"

async function sleep(msec: number) {
return new Promise(resolve => setTimeout(resolve, msec))
return new Promise(resolve => {
setTimeout(resolve, msec)
})
}

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

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

async function main() {
for (const worker of workers) {
worker.start()
await worker.start()
}
broker.start()
await broker.start()

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

for (const worker of workers) {
worker.stop()
await worker.stop()
}
broker.stop()
await broker.stop()
}

main().catch(err => {
Expand Down
14 changes: 9 additions & 5 deletions examples/majordomo/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Service {

dispatchRequest(client: Buffer, ...req: Buffer[]) {
this.requests.push([client, req])
this.dispatchPending()
return this.dispatchPending()
}

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

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

this.dispatchPending()
return this.dispatchPending()
}

async dispatchPending() {
while (this.workers.size && this.requests.length) {
const [key, worker] = this.workers.entries().next().value!
const [key, worker] = this.workers.entries().next().value as [
string,
Buffer,
]
this.workers.delete(key)
const [client, req] = this.requests.shift()!

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

// eslint-disable-next-line no-await-in-loop
await this.socket.send([
worker,
null,
Expand All @@ -59,14 +63,14 @@ export class Service {
`registered worker ${worker.toString("hex")} for '${this.name}'`,
)
this.workers.set(worker.toString("hex"), worker)
this.dispatchPending()
return this.dispatchPending()
}

deregister(worker: Buffer) {
console.log(
`deregistered worker ${worker.toString("hex")} for '${this.name}'`,
)
this.workers.delete(worker.toString("hex"))
this.dispatchPending()
return this.dispatchPending()
}
}
12 changes: 9 additions & 3 deletions examples/majordomo/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ export class Worker {
await this.socket.send([null, Header.Worker, Message.Ready, this.service])

const loop = async () => {
for await (const [blank1, header, type, client, blank2, ...req] of this
.socket) {
for await (const [
_blank1,
_header,
_type,
client,
_blank2,
...req
] of this.socket) {
const rep = await this.process(...req)

Check warning on line 27 in examples/majordomo/worker.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04, 18, x64, x64, x64, false)

Unsafe spread of an `any` type
try {
await this.socket.send([
Expand All @@ -34,7 +40,7 @@ export class Worker {
}
}

loop()
return loop()
}

async stop() {
Expand Down
4 changes: 3 additions & 1 deletion examples/threaded-worker/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export class Processor {
this.input.bind("inproc://input"),
this.output.bind("inproc://output"),
this.signal.bind("inproc://signal"),
new Promise(resolve => setTimeout(resolve, 100)),
new Promise(resolve => {
setTimeout(resolve, 100)
}),
])

this.exit = Promise.all([ThreadedWorker.spawn(this.threads)])
Expand Down
6 changes: 4 additions & 2 deletions examples/threaded-worker/threaded-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ export class ThreadedWorker {
const listen = async () => {
for await (const [sig] of this.signal) {
if (sig.toString() === "stop") {
this.stop()
await this.stop()
}
}
}

listen()
listen().catch(err => {
throw err
})
}

async stop() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"format": "prettier --write .",
"test.electron.renderer": "run-s build && electron-mocha --renderer",
"lint.clang-format": "clang-format -i -style=file ./src/*.cc ./src/*.h ./src/util/*.h",
"lint-test.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/",
"lint-test.eslint": "eslint ./**/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/",
"lint.eslint": "pnpm run lint-test.eslint --fix",
"lint": "run-p lint.eslint lint.clang-format",
"lint-test": "run-s lint-test.eslint",
Expand Down
2 changes: 1 addition & 1 deletion src/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["../.eslintrc", "eslint-config-atomic/strict"]
"extends": ["../.eslintrc"]
}
3 changes: 0 additions & 3 deletions src/compat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable @typescript-eslint/no-var-requires */

/* The API of the compatibility layer and parts of the implementation has been
adapted from the original ZeroMQ.js version (up to 5.x) for which the license
and copyright notice is reproduced below.
Expand Down
7 changes: 7 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": "../.eslintrc",
"ignorePatterns": [
"unit/compat/",
"bench/",
"node_modules"
],
"rules": {
"no-invalid-this": "off",
"no-inner-declarations": "off",
Expand All @@ -11,6 +16,8 @@
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"no-await-in-loop": "off",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "off",
"require-await": "off",
"import/no-extraneous-dependencies": "off"
}
Expand Down
16 changes: 12 additions & 4 deletions test/unit/context-process-exit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ describe("context process exit", function () {
const {code, is_timeout} = await createProcess(() => {
const socket1 = new zmq.Dealer()
socket1.connect("inproc://foo")
socket1.receive()
socket1.receive().catch(err => {
throw err
})
})

assert.equal(code, -1)
Expand All @@ -46,7 +48,9 @@ describe("context process exit", function () {
zmq.context.blocky = true
const socket1 = new zmq.Dealer({linger: 1000})
socket1.connect("tcp://127.0.0.1:4567")
socket1.send(null)
socket1.send(null).catch(err => {
throw err
})
})

if (semver.satisfies(zmq.version, ">= 4.2")) {
Expand All @@ -68,7 +72,9 @@ describe("context process exit", function () {
zmq.context.blocky = false
const socket1 = new zmq.Dealer({linger: 1000})
socket1.connect("tcp://127.0.0.1:4567")
socket1.send(null)
socket1.send(null).catch(err => {
throw err
})
})

assert.match(
Expand All @@ -83,7 +89,9 @@ describe("context process exit", function () {
zmq.context.blocky = true
const socket1 = new zmq.Dealer({linger: 50})
socket1.connect("tcp://127.0.0.1:4567")
socket1.send(null)
socket1.send(null).catch(err => {
throw err
})
})

assert.equal(stderr.toString(), "")
Expand Down
11 changes: 6 additions & 5 deletions test/unit/socket-send-receive-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,16 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
it("should deliver messages coercible to string", async function () {
const messages = [
null,
/* eslint-disable-next-line @typescript-eslint/no-empty-function */
function () {},
function () {
// nothing
},
16.19,
true,
{},
Promise.resolve(),
]
for (const msg of messages) {
await sockA.send(msg as any)
await sockA.send(msg as zmq.MessageLike)
}

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

const echo = async (sock: zmq.Pair) => {
const msg = await sock.receive()
sock.send(msg)
await sock.send(msg)
}

echo(sockB)
await echo(sockB)

const [final] = await sockA.receive()
final.writeUInt8(0x40, 0)
Expand Down
10 changes: 7 additions & 3 deletions test/unit/socket-zap-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ for (const proto of testProtos("tcp", "ipc")) {
describe(`socket with ${proto} zap`, function () {
let sockA: zmq.Pair
let sockB: zmq.Pair
let handler: ZapHandler
let handler: ZapHandler | undefined

beforeEach(function () {
sockA = new zmq.Pair()
Expand Down Expand Up @@ -230,7 +230,9 @@ class ValidatingZapHandler extends ZapHandler {
constructor(details: ZapDetails) {
super()
this.details = details
this.run()
this.run().catch(err => {
throw err
})
}

handle(request: Buffer[]) {
Expand Down Expand Up @@ -274,6 +276,8 @@ class CustomZapHandler extends ZapHandler {
constructor(handler: ZapHandler["handle"]) {
super()
this.handle = handler
this.run()
this.run().catch(err => {
throw err
})
}
}
8 changes: 4 additions & 4 deletions test/unit/typings-compatibility-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ const srcStr = readFile(srcFile, "utf8").then(content => {
const tscTestBasePath = path.resolve(__dirname, "..", "typings-compatibility")
const templateSrcPath = path.resolve(tscTestBasePath, "template")

function addLibs(libs: string[], targetList: string[]): string[] {
if (!targetList) {
targetList = libs
function addLibs(libs: string[], targetList: string[] | undefined): string[] {
if (targetList === undefined) {
return libs
} else {
libs.forEach(l => {
if (!targetList.find(e => e.toLowerCase() === l.toLowerCase())) {
Expand Down Expand Up @@ -153,7 +153,7 @@ async function prepareTestPackage(
if (tsVer.requiredLibs) {
tsConfig.compilerOptions.lib = addLibs(
tsVer.requiredLibs,
tsConfig.compilerOptions.lib as string[],
tsConfig.compilerOptions.lib as string[] | undefined,
)
}
return writeJson(path.resolve(tscTargetPath, "tsconfig.json"), tsConfig)
Expand Down
Loading

0 comments on commit c2c9f90

Please sign in to comment.