Skip to content

Commit

Permalink
[FIX] new linter warnings from deno 1.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Apr 26, 2022
1 parent 1273bf9 commit 63e01ba
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 116 deletions.
3 changes: 1 addition & 2 deletions nats-base-client/bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 The NATS Authors
* Copyright 2020-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -217,7 +217,6 @@ export class Bench {
if (this.req) {
const d = deferred<void>();
jobs.push(d);
// deno-lint-ignore no-unused-vars
const sub = this.nc.subscribe(
this.subject,
{
Expand Down
4 changes: 2 additions & 2 deletions nats-base-client/codec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 The NATS Authors
* Copyright 2020-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -33,7 +33,7 @@ export function StringCodec(): Codec<string> {
}

export function JSONCodec<T = unknown>(
reviver?: (this: any, key: string, value: any) => any,
reviver?: (this: unknown, key: string, value: unknown) => unknown,
): Codec<T> {
return {
encode(d: T): Uint8Array {
Expand Down
3 changes: 1 addition & 2 deletions nats-base-client/jsclient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The NATS Authors
* Copyright 2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -32,7 +32,6 @@ import {
JetStreamSubscriptionOptions,
JsHeaders,
JsMsg,
KvCodecs,
Msg,
NatsConnection,
PubAck,
Expand Down
3 changes: 1 addition & 2 deletions nats-base-client/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import {
} from "./jsclient.ts";
import { millis, nanos } from "./jsutil.ts";
import { QueuedIterator, QueuedIteratorImpl } from "./queued_iterator.ts";
import { deferred } from "./util.ts";
import { headers, MsgHdrs } from "./headers.ts";
import { consumerOpts } from "./mod.ts";
import { compare, parseSemVer } from "./semver.ts";
Expand Down Expand Up @@ -325,7 +324,7 @@ export class Bucket implements KV, KvRemove {
};
}

jmToEntry(k: string, jm: JsMsg): KvEntry {
jmToEntry(_k: string, jm: JsMsg): KvEntry {
const key = this.decodeKey(jm.subject.substring(this.prefixLen));
return {
bucket: this.bucket,
Expand Down
2 changes: 1 addition & 1 deletion nats-base-client/nats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class NatsConnectionImpl implements NatsConnection {
try {
await adm.getAccountInfo();
} catch (err) {
let ne = err as NatsError;
const ne = err as NatsError;
if (ne.code === ErrorCode.NoResponders) {
ne.code = ErrorCode.JetStreamNotEnabled;
}
Expand Down
4 changes: 2 additions & 2 deletions nats-base-client/servers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2021 The NATS Authors
* Copyright 2018-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -137,7 +137,7 @@ export class ServerImpl implements Server {
// resolve the hostname to ips
const ips = await opts.fn(this.hostname);

for (let ip of ips) {
for (const ip of ips) {
// letting URL handle the details of representing IPV6 ip with a port, etc
// careful to make sure the protocol doesn't line with standard ports or they
// get swallowed
Expand Down
5 changes: 3 additions & 2 deletions tests/auth_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Deno.test("auth - sub no permissions keeps connection", async () => {

const cbErr = deferred<Error | null>();
const sub = nc.subscribe("bar", {
callback: (err, msg) => {
callback: (err, _msg) => {
cbErr.resolve(err);
},
});
Expand Down Expand Up @@ -158,7 +158,8 @@ Deno.test("auth - sub iterator no permissions keeps connection", async () => {
const iterErr = deferred<Error | null>();
const sub = nc.subscribe("bar");
(async () => {
for await (const m of sub) {
for await (const _m of sub) {
// ignored
}
})().catch((err) => {
iterErr.resolve(err);
Expand Down
3 changes: 2 additions & 1 deletion tests/codec_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The NATS Authors
* Copyright 2020-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -29,6 +29,7 @@ Deno.test("codec - json", () => {
});

Deno.test("codec - json w/ reviver", () => {
// deno-lint-ignore no-explicit-any
const sc = JSONCodec((k: string, v: any) => k === "time" ? new Date(v) : v);
const o = { time: new Date() };
const d = sc.encode(o);
Expand Down
3 changes: 1 addition & 2 deletions tests/helpers/check.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 The NATS Authors
* Copyright 2020-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -29,7 +29,6 @@ export function check(
});

const task = new Promise((done) => {
// deno-lint-ignore no-unused-vars
const i = setInterval(async () => {
try {
const v = await fn();
Expand Down
6 changes: 3 additions & 3 deletions tests/helpers/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 The NATS Authors
* Copyright 2020-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -65,12 +65,12 @@ try {
);
});

await waitForStop();
waitForStop();
} catch (err) {
console.error(err);
}

async function waitForStop(): Promise<void> {
function waitForStop(): void {
console.log("control+c to terminate");
Deno.addSignalListener("SIGTERM", () => {
Deno.exit();
Expand Down
91 changes: 8 additions & 83 deletions tests/jetstream_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The NATS Authors
* Copyright 2021-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -34,7 +34,6 @@ import {
Empty,
ErrorCode,
headers,
JetStreamPullSubscription,
JsHeaders,
JsMsg,
JsMsgCallback,
Expand All @@ -46,7 +45,6 @@ import {
QueuedIterator,
RetentionPolicy,
StorageType,
StreamConfig,
StringCodec,
} from "../nats-base-client/internal_mod.ts";
import {
Expand All @@ -70,7 +68,6 @@ import {
isFlowControlMsg,
isHeartbeatMsg,
} from "../nats-base-client/jsutil.ts";
import * as log from "https://deno.land/std@0.136.0/log/mod.ts";

function callbackConsume(debug = false): JsMsgCallback {
return (err: NatsError | null, jm: JsMsg | null) => {
Expand Down Expand Up @@ -633,6 +630,8 @@ Deno.test("jetstream - fetch some messages", async () => {
}
})();
assertEquals(sub.getProcessed(), 2);

await nc.flush();
let ci = await jsm.consumers.info(stream, "me");
assertEquals(ci.num_pending, 1);
assertEquals(ci.delivered.stream_seq, 2);
Expand Down Expand Up @@ -2177,7 +2176,6 @@ Deno.test("jetstream - pull sub - multiple consumers", async () => {
})().then();

const done = deferred<void>();
// deno-lint-ignore no-unused-vars
const interval = setInterval(() => {
if (countA + countB < 100) {
subA.pull({ expires: 500, batch: 25 });
Expand Down Expand Up @@ -2839,8 +2837,8 @@ Deno.test("jetstream - bind", async () => {
undefined,
);

const internal = nc.subscribe("$JS.API.CONSUMER.DURABLE.CREATE.>", {
callback: (err, msg) => {
nc.subscribe("$JS.API.CONSUMER.DURABLE.CREATE.>", {
callback: (_err, _msg) => {
// this will count
},
});
Expand Down Expand Up @@ -2919,7 +2917,7 @@ Deno.test("jetstream - test events stream", async () => {
subjects: ["events.>"],
});

const sub = await js.subscribe("events.>", {
await js.subscribe("events.>", {
stream: "events",
config: {
ack_policy: AckPolicy.Explicit,
Expand All @@ -2928,7 +2926,7 @@ Deno.test("jetstream - test events stream", async () => {
durable_name: "me",
filter_subject: "events.>",
},
callbackFn: (err: NatsError | null, msg: JsMsg | null) => {
callbackFn: (_err: NatsError | null, msg: JsMsg | null) => {
msg?.ack();
},
});
Expand Down Expand Up @@ -2973,7 +2971,7 @@ Deno.test("jetstream - pull next", async () => {
await js.publish(subj);

const jsm = await nc.jetstreamManager();
let si = await jsm.streams.info(stream);
const si = await jsm.streams.info(stream);
assertEquals(si.state.messages, 2);

let inbox = "";
Expand Down Expand Up @@ -3012,76 +3010,3 @@ Deno.test("jetstream - pull next", async () => {

await cleanup(ns, nc);
});

// Deno.test("what happens", async () => {
// const nc = await connect({ port: 6543 });
// const jsm = await nc.jetstreamManager();
// const stream = "stream";
// const durable = "dur";
//
// await jsm.streams.info(stream)
// .catch(async (err) => {
// await jsm.streams.add({
// name: stream,
// retention: RetentionPolicy.Limits,
// storage: StorageType.File,
// num_replicas: 3,
// subjects: ["foo"],
// } as StreamConfig);
//
// console.log(`created stream`);
// });
//
// await jsm.consumers.info(stream, durable)
// .catch(async (err) => {
// await jsm.consumers.add(stream, {
// ack_policy: AckPolicy.Explicit,
// deliver_policy: DeliverPolicy.All,
// durable_name: durable,
// });
// console.log(`created consumer`);
// });
//
// const js = nc.jetstream();
//
// let sub: JetStreamPullSubscription;
// let inbox = "";
//
// const pullOpts = { batch: 1, expires: 5 * 1000 };
// const opts = consumerOpts();
// opts.bind(stream, durable);
// opts.manualAck();
// opts.callback((err, msg) => {
// if (err) {
// switch (err.code) {
// case ErrorCode.JetStream404NoMessages:
// case ErrorCode.JetStream408RequestTimeout:
// case ErrorCode.JetStream409MaxAckPendingExceeded:
// console.log(`js error [${err.code}] - re-pulling`);
// sub.pull(pullOpts);
// break;
// default:
// // this is a real error
// log.error(`error from ${durable}: ${err.message}\n${err.stack}`);
// // this will make the service stop
// sub.unsubscribe();
// }
// return;
// }
// console.log(msg ? msg.subject : "null msg");
// if (msg) {
// msg.next(inbox, pullOpts);
// }
// });
//
// sub = await js.pullSubscribe("foo", opts);
// inbox = sub.getSubject();
//
// sub.pull(pullOpts);
//
// sub.closed.then((err) => {
// console.log("sub closed");
// });
//
// await nc.closed();
// });
6 changes: 3 additions & 3 deletions tests/jsm_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The NATS Authors
* Copyright 2021-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -131,7 +131,7 @@ Deno.test("jsm - update stream name is internally added", async () => {
const { ns, nc } = await setup(jetstreamServerConf({}, true));
const jsm = await nc.jetstreamManager();
const name = nuid.next();
let ci = await jsm.streams.add({
const ci = await jsm.streams.add({
name: name,
subjects: [`${name}.>`],
});
Expand Down Expand Up @@ -927,7 +927,7 @@ Deno.test("jsm - cross account consumers", async () => {

Deno.test("jsm - jetstream error info", async () => {
const { ns, nc } = await setup(jetstreamServerConf({}, true));
let jsm = await nc.jetstreamManager();
const jsm = await nc.jetstreamManager();
try {
await jsm.streams.add({
name: "a",
Expand Down
Loading

0 comments on commit 63e01ba

Please sign in to comment.