Skip to content

Commit

Permalink
chore: run lint
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 5, 2022
1 parent 42853df commit 1616b85
Show file tree
Hide file tree
Showing 78 changed files with 1,346 additions and 960 deletions.
2 changes: 1 addition & 1 deletion draft.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (require(".").capability.draft) {
} else {
throw new Error(
"ZeroMQ draft features are not enabled in this build. " +
"To enable support, (re)compile this library with --zmq-draft.",
"To enable support, (re)compile this library with --zmq-draft.",
)
}

Expand Down
8 changes: 6 additions & 2 deletions examples/majordomo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ async function request(
}

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

/* Requests are issued in parallel. */
Expand All @@ -65,7 +67,9 @@ async function main() {
request("coffee", "irish coffee"),
])

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

Expand Down
4 changes: 3 additions & 1 deletion examples/queue/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export class Queue {
}

async trySend() {
if (this.sending) return
if (this.sending) {
return
}
this.sending = true

while (this.queue.length) {
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 @@ -39,7 +39,9 @@ export class Processor {
const output: string[] = Array.from({length: input.length})
for await (const [pos, res] of this.output) {
output[parseInt(pos.toString(), 10)] = res.toString()
if (output.every(el => el !== undefined)) break
if (output.every(el => el !== undefined)) {
break
}
}

return output.join("")
Expand Down
4 changes: 3 additions & 1 deletion examples/threaded-worker/threaded-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export class ThreadedWorker {

const listen = async () => {
for await (const [sig] of this.signal) {
if (sig.toString() === "stop") this.stop()
if (sig.toString() === "stop") {
this.stop()
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions script/ci/downlevel-dts.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function getModifiersText(node) {
.getModifiers()
.map(m => m.getText())
.join(" ")
return modifiersText.length > 0 ? modifiersText + " " : ""
return modifiersText.length > 0 ? `${modifiersText} ` : ""
}

function getLeadingComments(node) {
Expand Down Expand Up @@ -174,7 +174,7 @@ function relativeModulePath(fromAbsModulePath, toAbsTargetDir) {
path.join(revertedPath, path.basename(fromAbsModulePath)),
)
if (!/^\./.test(relMod)) {
relMod = "./" + relMod
relMod = `./${relMod}`
}
if (path.sep === "/") {
return relMod
Expand Down
39 changes: 27 additions & 12 deletions script/ci/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,49 @@ const gunzip = require("gunzip-maybe")
const tar = require("tar-fs")

async function download() {
const {repository: {url}, version} = require(path.resolve("./package.json"))
const {
repository: {url},
version,
} = require(path.resolve("./package.json"))

if (process.env.TRAVIS_TAG && process.env.TRAVIS_TAG != `v${version}`) {
throw new Error(`Version mismatch (TRAVIS_TAG=${process.env.TRAVIS_TAG}, version=${version}`)
throw new Error(
`Version mismatch (TRAVIS_TAG=${process.env.TRAVIS_TAG}, version=${version}`,
)
}

const [, user, repo] = url.match(/\/([a-z0-9_.-]+)\/([a-z0-9_.-]+)\.git$/i)
const [, user, repo] = url.match(/\/([\w.-]+)\/([\w.-]+)\.git$/i)

const res = await fetch(`https://api.github.com/repos/${user}/${repo}/releases/tags/v${version}`)
const res = await fetch(
`https://api.github.com/repos/${user}/${repo}/releases/tags/v${version}`,
)

if (!res.ok) {
if (res.status == 404) {
throw new Error(`Github release v${version} not found (${res.status})`)
} else {
const body = await res.text()
throw new Error(`Github release v${version} not accessible (${res.status}): ${body}`)
throw new Error(
`Github release v${version} not accessible (${res.status}): ${body}`,
)
}
}

const {assets} = await res.json()

await Promise.all(assets.map(async ({browser_download_url: url}) => {
console.log(`Downloading prebuilds from ${url}`)
const res = await fetch(url)
return new Promise((resolve, reject) => {
res.body.pipe(gunzip()).pipe(tar.extract(".")).on("error", reject).on("finish", resolve)
})
}))
await Promise.all(
assets.map(async ({browser_download_url: url}) => {
console.log(`Downloading prebuilds from ${url}`)
const res = await fetch(url)
return new Promise((resolve, reject) => {
res.body
.pipe(gunzip())
.pipe(tar.extract("."))
.on("error", reject)
.on("finish", resolve)
})
}),
)
}

download().catch(err => {
Expand Down
54 changes: 37 additions & 17 deletions src/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ class Socket extends EventEmitter {
await this._recv()
}

if (!this._socket.closed) recv()
if (!this._socket.closed) {
recv()
}
})
}

Expand All @@ -286,11 +288,15 @@ class Socket extends EventEmitter {
await this._send()
}

if (!this._socket.closed) send()
if (!this._socket.closed) {
send()
}
})
}

if (type !== "push" && type !== "pub") recv()
if (type !== "push" && type !== "pub") {
recv()
}
send()

this.emit("_flushRecv")
Expand Down Expand Up @@ -337,7 +343,9 @@ class Socket extends EventEmitter {
const [msg, cb] = this._sendQueue.shift()!
try {
await (this._socket as zmq.Writable).send(msg)
if (cb) cb()
if (cb) {
cb()
}
} catch (err) {
if (cb) {
cb(err)
Expand All @@ -354,7 +362,9 @@ class Socket extends EventEmitter {
.then(() => {
process.nextTick(() => {
this.emit("bind", address)
if (cb) cb()
if (cb) {
cb()
}
})
})
.catch(err => {
Expand All @@ -376,7 +386,9 @@ class Socket extends EventEmitter {
.then(() => {
process.nextTick(() => {
this.emit("unbind", address)
if (cb) cb()
if (cb) {
cb()
}
})
})
.catch(err => {
Expand Down Expand Up @@ -408,7 +420,9 @@ class Socket extends EventEmitter {
if ((flags & sendOptions.ZMQ_SNDMORE) === 0) {
this._sendQueue.push([this._msg, cb])
this._msg = []
if (!this._paused) this.emit("_flushSend")
if (!this._paused) {
this.emit("_flushSend")
}
}
return this
}
Expand Down Expand Up @@ -634,7 +648,7 @@ class Socket extends EventEmitter {
this._socket.ipv6 = !value
break
case longOptions.ZMQ_ROUTER_MANDATORY:
;(this._socket as zmq.Router).mandatory = !!value
;(this._socket as zmq.Router).mandatory = Boolean(value)
break
case longOptions.ZMQ_TCP_KEEPALIVE:
this._socket.tcpKeepalive = value
Expand All @@ -652,18 +666,18 @@ class Socket extends EventEmitter {
this._socket.tcpAcceptFilter = value
break
case longOptions.ZMQ_DELAY_ATTACH_ON_CONNECT:
this._socket.immediate = !!value
this._socket.immediate = Boolean(value)
break
case longOptions.ZMQ_XPUB_VERBOSE:
;(this._socket as zmq.XPublisher).verbosity = value ? "allSubs" : null
break
case longOptions.ZMQ_ROUTER_RAW:
throw new Error("ZMQ_ROUTER_RAW is not supported in compatibility mode")
case longOptions.ZMQ_IPV6:
this._socket.ipv6 = !!value
this._socket.ipv6 = Boolean(value)
break
case longOptions.ZMQ_PLAIN_SERVER:
this._socket.plainServer = !!value
this._socket.plainServer = Boolean(value)
break
case longOptions.ZMQ_PLAIN_USERNAME:
this._socket.plainUsername = value
Expand All @@ -672,7 +686,7 @@ class Socket extends EventEmitter {
this._socket.plainPassword = value
break
case longOptions.ZMQ_CURVE_SERVER:
this._socket.curveServer = !!value
this._socket.curveServer = Boolean(value)
break
case longOptions.ZMQ_CURVE_PUBLICKEY:
this._socket.curvePublicKey = value
Expand All @@ -699,7 +713,7 @@ class Socket extends EventEmitter {
this._socket.connectTimeout = value
break
case longOptions.ZMQ_ROUTER_HANDOVER:
;(this._socket as zmq.Router).handover = !!value
;(this._socket as zmq.Router).handover = Boolean(value)
break
default:
throw new Error("Unknown option")
Expand Down Expand Up @@ -821,14 +835,20 @@ class Socket extends EventEmitter {
}

for (const key in shortOptions) {
if (!shortOptions.hasOwnProperty(key)) continue
if (Socket.prototype.hasOwnProperty(key)) continue
if (!shortOptions.hasOwnProperty(key)) {
continue
}
if (Socket.prototype.hasOwnProperty(key)) {
continue
}
Object.defineProperty(Socket.prototype, key, {
get(this: Socket) {
return this.getsockopt(shortOptions[key as keyof typeof shortOptions])
},
set(this: Socket, val: string | Buffer) {
if ("string" === typeof val) val = Buffer.from(val, "utf8")
if ("string" === typeof val) {
val = Buffer.from(val, "utf8")
}
return this.setsockopt(
shortOptions[key as keyof typeof shortOptions],
val,
Expand All @@ -853,7 +873,7 @@ function curveKeypair() {
}

function proxy(frontend: Socket, backend: Socket, capture?: Socket) {
switch (frontend.type + "/" + backend.type) {
switch (`${frontend.type}/${backend.type}`) {
case "push/pull":
case "pull/push":
case "xpub/xsub":
Expand Down
12 changes: 8 additions & 4 deletions src/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface RadioGroupOptions {
group: Buffer | string
}

export interface Radio extends Writable<MessageLike, [RadioGroupOptions]> {}
export type Radio = Writable<MessageLike, [RadioGroupOptions]>
Object.assign(Radio.prototype, {send})

export class Dish extends Socket {
Expand All @@ -50,19 +50,23 @@ export class Dish extends Socket {
the sake of simplicity. */

join(...values: Array<Buffer | string>): void {
for (const value of values) join.call(this, value)
for (const value of values) {
join.call(this, value)
}
}

leave(...values: Array<Buffer | string>): void {
for (const value of values) leave.call(this, value)
for (const value of values) {
leave.call(this, value)
}
}
}

interface DishGroupOptions {
group: Buffer
}

export interface Dish extends Readable<[Message, DishGroupOptions]> {}
export type Dish = Readable<[Message, DishGroupOptions]>
Object.assign(Dish.prototype, {receive})

export class Gather extends Socket {
Expand Down
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type MessageLike =
*/
export interface Writable<
M extends MessageLike | MessageLike[] = MessageLike | MessageLike[],
O extends [...object[]] = []
O extends [...object[]] = [],
> {
/**
* ZMQ_MULTICAST_HOPS
Expand Down Expand Up @@ -1025,7 +1025,7 @@ export class Publisher extends Socket {
}
}

export interface Publisher extends Writable {}
export type Publisher = Writable
Object.assign(Publisher.prototype, {send})

/**
Expand Down Expand Up @@ -1124,7 +1124,7 @@ export class Subscriber extends Socket {
}
}

export interface Subscriber extends Readable {}
export type Subscriber = Readable
Object.assign(Subscriber.prototype, {receive})

/**
Expand Down Expand Up @@ -1636,7 +1636,7 @@ function defineOpt<T, K extends WritableKeys<PrototypeOf<T>>>(
set if the property has been defined as readonly in the interface/class. */
function defineOpt<
T extends {prototype: any},
K extends ReadableKeys<PrototypeOf<T>>
K extends ReadableKeys<PrototypeOf<T>>,
>(
targets: T[],
name: K,
Expand Down Expand Up @@ -1674,7 +1674,9 @@ function defineOpt<
}

for (const target of targets) {
if (target.prototype.hasOwnProperty(name)) continue
if (target.prototype.hasOwnProperty(name)) {
continue
}
Object.defineProperty(target.prototype, name, desc)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export declare class Observer {
*/
export declare class Proxy<
F extends Socket = Socket,
B extends Socket = Socket
B extends Socket = Socket,
> {
/**
* Returns the original front-end socket.
Expand Down Expand Up @@ -646,7 +646,7 @@ export const enum SocketType {

/* https://stackoverflow.com/questions/49579094 */
type IfEquals<X, Y, A, B = never> = (<T>() => T extends X ? 1 : 2) extends <
T
T,
>() => T extends Y ? 1 : 2
? A
: B
Expand Down
Loading

0 comments on commit 1616b85

Please sign in to comment.