Skip to content

Commit a90f0de

Browse files
imatlopezluin
authored andcommitted
style: fix eslint args and fixed new lint errors (#911)
1 parent 98ebeec commit a90f0de

20 files changed

+65
-53
lines changed

.eslintrc.yml

+19-9
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@ env:
1313
node: true
1414
es6: true
1515

16+
rules:
17+
no-console: 0
18+
"@typescript-eslint/no-var-requires": 0
19+
"@typescript-eslint/explicit-function-return-type": 0
20+
"@typescript-eslint/no-explicit-any": 0
21+
"@typescript-eslint/explicit-member-accessibility": 0
22+
"@typescript-eslint/no-parameter-properties": 0
23+
"@typescript-eslint/no-use-before-define": 0
24+
"@typescript-eslint/array-type":
25+
- error
26+
- array-simple
27+
"@typescript-eslint/no-unused-vars":
28+
- warn
29+
- args: none
30+
"@typescript-eslint/interface-name-prefix":
31+
- error
32+
- "always"
33+
1634
overrides:
17-
- files: ["test/**/*"]
35+
- files: ["{test,benchmarks}/**/*"]
1836
env:
1937
mocha: true
20-
21-
- files: ["{benchmarks,examples}/**/*"]
22-
rules:
23-
no-console: 0
24-
25-
- files: ["examples/**/*"]
26-
rules:
27-
"@typescript-eslint/no-var-requires": 0

benchmarks/single_node.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* global suite set bench after */
12
import { execSync } from "child_process";
23
import Redis from "../lib/redis";
34

lib/DataHandler.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import SubscriptionSet from "./SubscriptionSet";
88

99
const debug = Debug("dataHandler");
1010

11-
type ReplyData = string | Buffer | number | (string | Buffer | number)[];
11+
type ReplyData = string | Buffer | number | Array<string | Buffer | number>;
1212

1313
export interface IDataHandlerOptions {
1414
stringNumbers: boolean;
@@ -69,7 +69,7 @@ export default class DataHandler {
6969
return;
7070
}
7171

72-
(<any>err).command = {
72+
(err as any).command = {
7373
name: item.command.name,
7474
args: item.command.args
7575
};
@@ -228,10 +228,10 @@ export default class DataHandler {
228228

229229
function fillSubCommand(command: ICommand, count: number) {
230230
// TODO: use WeakMap here
231-
if (typeof (<any>command).remainReplies === "undefined") {
232-
(<any>command).remainReplies = command.args.length;
231+
if (typeof (command as any).remainReplies === "undefined") {
232+
(command as any).remainReplies = command.args.length;
233233
}
234-
if (--(<any>command).remainReplies === 0) {
234+
if (--(command as any).remainReplies === 0) {
235235
command.resolve(count);
236236
return true;
237237
}

lib/SubscriptionSet.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { CommandNameFlags } from "./command";
1+
import { ICommandNameFlags } from "./command";
22

3-
type AddSet = CommandNameFlags["ENTER_SUBSCRIBER_MODE"][number];
4-
type DelSet = CommandNameFlags["EXIT_SUBSCRIBER_MODE"][number];
3+
type AddSet = ICommandNameFlags["ENTER_SUBSCRIBER_MODE"][number];
4+
type DelSet = ICommandNameFlags["EXIT_SUBSCRIBER_MODE"][number];
55

66
/**
77
* Tiny class to simplify dealing with subscription set

lib/cluster/ClusterOptions.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export type DNSLookupFunction = (
99
family: number
1010
) => void
1111
) => void;
12-
export type NatMap = { [key: string]: { host: string; port: number } };
12+
export interface INatMap {
13+
[key: string]: { host: string; port: number };
14+
}
1315

1416
/**
1517
* Options for Cluster constructor
@@ -127,7 +129,7 @@ export interface IClusterOptions {
127129
* @default require('dns').lookup
128130
*/
129131
dnsLookup?: DNSLookupFunction;
130-
natMap?: NatMap;
132+
natMap?: INatMap;
131133
}
132134

133135
export const DEFAULT_CLUSTER_OPTIONS: IClusterOptions = {

lib/cluster/ClusterSubscriber.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import ConnectionPool from "./ConnectionPool";
33
import { getNodeKey } from "./util";
44
import { sample, noop, Debug } from "../utils";
55
import Redis from "../redis";
6-
import { IRedisOptions } from "../redis/RedisOptions";
76

87
const debug = Debug("cluster:subscriber");
98

lib/cluster/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Cluster extends EventEmitter {
5353
private options: IClusterOptions;
5454
private startupNodes: Array<string | number | object>;
5555
private connectionPool: ConnectionPool;
56-
private slots: Array<NodeKey[]> = [];
56+
private slots: NodeKey[][] = [];
5757
private manuallyClosing: boolean;
5858
private retryAttempts: number = 0;
5959
private delayQueue: DelayQueue = new DelayQueue();
@@ -542,6 +542,7 @@ class Cluster extends EventEmitter {
542542
const ttl = {};
543543
const _this = this;
544544
if (!node && !command.__is_reject_overwritten) {
545+
// eslint-disable-next-line @typescript-eslint/camelcase
545546
command.__is_reject_overwritten = true;
546547
const reject = command.reject;
547548
command.reject = function(err) {

lib/cluster/util.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { parseURL } from "../utils";
22
import { isIP } from "net";
3-
import { DNSLookupFunction } from "./ClusterOptions";
43

54
export type NodeKey = string;
65
export type NodeRole = "master" | "slave" | "all";

lib/command.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ interface ICommandOptions {
2626

2727
type ArgumentTransformer = (args: any[]) => any[];
2828
type ReplyTransformer = (reply: any) => any;
29-
type FlagMap = { [flag: string]: { [command: string]: true } };
29+
interface IFlagMap {
30+
[flag: string]: { [command: string]: true };
31+
}
3032

31-
export type CommandNameFlags = {
33+
export interface ICommandNameFlags {
3234
// Commands that can be processed when client is in the subscriber mode
3335
VALID_IN_SUBSCRIBER_MODE: [
3436
"subscribe",
@@ -46,7 +48,7 @@ export type CommandNameFlags = {
4648
EXIT_SUBSCRIBER_MODE: ["unsubscribe", "punsubscribe"];
4749
// Commands that will make client disconnect from server TODO shutdown?
4850
WILL_DISCONNECT: ["quit"];
49-
};
51+
}
5052

5153
/**
5254
* Command instance
@@ -75,7 +77,7 @@ export type CommandNameFlags = {
7577
*/
7678
export default class Command implements ICommand {
7779
public static FLAGS: {
78-
[key in keyof CommandNameFlags]: CommandNameFlags[key];
80+
[key in keyof ICommandNameFlags]: ICommandNameFlags[key];
7981
} = {
8082
VALID_IN_SUBSCRIBER_MODE: [
8183
"subscribe",
@@ -91,9 +93,9 @@ export default class Command implements ICommand {
9193
WILL_DISCONNECT: ["quit"]
9294
};
9395

94-
private static flagMap?: FlagMap;
96+
private static flagMap?: IFlagMap;
9597

96-
private static getFlagMap(): FlagMap {
98+
private static getFlagMap(): IFlagMap {
9799
if (!this.flagMap) {
98100
this.flagMap = Object.keys(Command.FLAGS).reduce((map, flagName) => {
99101
map[flagName] = {};
@@ -113,10 +115,10 @@ export default class Command implements ICommand {
113115
* @param {string} commandName
114116
* @return {boolean}
115117
*/
116-
public static checkFlag<T extends keyof CommandNameFlags>(
118+
public static checkFlag<T extends keyof ICommandNameFlags>(
117119
flagName: T,
118120
commandName: string
119-
): commandName is CommandNameFlags[T][number] {
121+
): commandName is ICommandNameFlags[T][number] {
120122
return !!this.getFlagMap()[flagName][commandName];
121123
}
122124

lib/commander.ts

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ commands.forEach(function(commandName) {
6868

6969
Commander.prototype.call = generateFunction("utf8");
7070
Commander.prototype.callBuffer = generateFunction(null);
71+
// eslint-disable-next-line @typescript-eslint/camelcase
7172
Commander.prototype.send_command = Commander.prototype.call;
7273

7374
/**

lib/connectors/SentinelConnector/SentinelIterator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class SentinelIterator
1414
implements Iterator<Partial<ISentinelAddress>> {
1515
private cursor: number = 0;
1616

17-
constructor(private sentinels: Partial<ISentinelAddress>[]) {}
17+
constructor(private sentinels: Array<Partial<ISentinelAddress>>) {}
1818

1919
next() {
2020
const done = this.cursor >= this.sentinels.length;

lib/connectors/SentinelConnector/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createConnection } from "net";
2-
import { NatMap } from "../../cluster/ClusterOptions";
2+
import { INatMap } from "../../cluster/ClusterOptions";
33
import {
44
CONNECTION_CLOSED_ERROR_MSG,
55
packObject,
@@ -27,7 +27,7 @@ interface IAddressFromResponse {
2727
}
2828

2929
type PreferredSlaves =
30-
| ((slaves: Array<IAddressFromResponse>) => IAddressFromResponse | null)
30+
| ((slaves: IAddressFromResponse[]) => IAddressFromResponse | null)
3131
| Array<{ port: string; ip: string; prio?: number }>
3232
| { port: string; ip: string; prio?: number };
3333

@@ -37,13 +37,13 @@ export interface ISentinelConnectionOptions extends ITcpConnectionOptions {
3737
role: "master" | "slave";
3838
name: string;
3939
sentinelPassword?: string;
40-
sentinels: Partial<ISentinelAddress>[];
40+
sentinels: Array<Partial<ISentinelAddress>>;
4141
sentinelRetryStrategy?: (retryAttempts: number) => number;
4242
preferredSlaves?: PreferredSlaves;
4343
connectTimeout?: number;
4444
enableTLSForSentinelMode?: boolean;
4545
sentinelTLS?: SecureContextOptions;
46-
natMap?: NatMap;
46+
natMap?: INatMap;
4747
updateSentinels?: boolean;
4848
}
4949

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"test": "TS_NODE_LOG_ERROR=true NODE_ENV=test mocha test/**/*.ts",
1111
"test:cov": "TS_NODE_LOG_ERROR=true NODE_ENV=test node ./node_modules/istanbul/lib/cli.js cover --preserve-comments ./node_modules/mocha/bin/_mocha -- -r ts-node/register -R spec --exit test/**/*.ts",
12-
"lint": "eslint .",
12+
"lint": "eslint --ext .js,.ts .",
1313
"format": "prettier --write \"{,!(node_modules)/**/}*.{js,ts}\"",
1414
"format-check": "prettier --check \"{,!(node_modules)/**/}*.{js,ts}\"",
1515
"build": "rm -rf built && tsc",

test/functional/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("auth", function() {
4343
});
4444

4545
it('should not emit "error" when the server doesn\'t need auth', function(done) {
46-
var server = new MockServer(17379, function(argv) {
46+
new MockServer(17379, function(argv) {
4747
if (argv[0] === "auth" && argv[1] === "pass") {
4848
return new Error("ERR Client sent AUTH, but no password is set");
4949
}

test/functional/cluster/transaction.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import calculateSlot from "cluster-key-slot";
22
import MockServer from "../../helpers/mock_server";
33
import { expect } from "chai";
44
import { Cluster } from "../../../lib";
5-
import * as sinon from "sinon";
65

76
describe("cluster:transaction", function() {
87
it("should auto redirect commands on MOVED", function(done) {
@@ -139,7 +138,7 @@ describe("cluster:transaction", function() {
139138
};
140139

141140
process.on("unhandledRejection", err => {
142-
wrapDone(new Error("got unhandledRejection: " + (<Error>err).message));
141+
wrapDone(new Error("got unhandledRejection: " + (err as Error).message));
143142
});
144143
cluster
145144
.multi()

test/functional/fatal_error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import MockServer from "../helpers/mock_server";
55
describe("fatal_error", function() {
66
it("should handle fatal error of parser", function(done) {
77
var recovered = false;
8-
const server = new MockServer(30000, argv => {
8+
new MockServer(30000, argv => {
99
if (recovered) {
1010
return;
1111
}

test/functional/scan_stream.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ describe("*scanStream", function() {
229229
return [String(cursor + 1), [serverKeys[cursor]]];
230230
}
231231
};
232-
var node1 = new MockServer(30001, argvHandler);
233-
var node2 = new MockServer(30002, argvHandler);
234-
var node3 = new MockServer(30003, argvHandler);
232+
new MockServer(30001, argvHandler);
233+
new MockServer(30002, argvHandler);
234+
new MockServer(30003, argvHandler);
235235

236236
var cluster = new Cluster([{ host: "127.0.0.1", port: "30001" }]);
237237

test/functional/sentinel.ts

-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ describe("sentinel", function() {
364364
role: "slave",
365365
// for code coverage (sorting, etc), use multiple valid values that resolve to prio 1
366366
preferredSlaves: [
367-
,
368367
{ ip: "127.0.0.1", port: "11111", prio: 100 },
369368
{ ip: "127.0.0.1", port: "17381", prio: 1 },
370369
{ ip: "127.0.0.1", port: "22222", prio: 100 },

test/unit/debug.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import real_debug = require("debug");
1+
import rDebug = require("debug");
22
import * as sinon from "sinon";
33
import { expect } from "chai";
44
import debug, {
@@ -8,7 +8,7 @@ import debug, {
88

99
describe("utils/debug", function() {
1010
afterEach(function() {
11-
real_debug.enable(process.env.DEBUG || "");
11+
rDebug.enable(process.env.DEBUG || "");
1212
});
1313

1414
describe(".exports.getStringValue", function() {
@@ -37,9 +37,9 @@ describe("utils/debug", function() {
3737
});
3838

3939
it("should output to console if DEBUG is set", function() {
40-
var dbg_ns = "ioredis:debugtest";
40+
var dbgNS = "ioredis:debugtest";
4141

42-
real_debug.enable(dbg_ns);
42+
rDebug.enable(dbgNS);
4343

4444
var logspy = sinon.spy();
4545
var fn = debug("debugtest");
@@ -50,7 +50,7 @@ describe("utils/debug", function() {
5050
// @ts-ignore
5151
expect(fn.enabled).to.equal(true);
5252
// @ts-ignore
53-
expect(fn.namespace).to.equal(dbg_ns);
53+
expect(fn.namespace).to.equal(dbgNS);
5454

5555
var data = [],
5656
i = 0;
@@ -67,14 +67,14 @@ describe("utils/debug", function() {
6767

6868
var args = logspy.getCall(0).args;
6969

70-
var wanted_arglen =
70+
var wantedArglen =
7171
30 + // " ... <REDACTED full-length="">"
7272
MAX_ARGUMENT_LENGTH + // max-length of redacted string
7373
datastr.length.toString().length; // length of string of string length (inception much?)
7474

7575
expect(args.length).to.be.above(1);
7676
expect(args[1]).to.be.a("string");
77-
expect(args[1].length).to.equal(wanted_arglen);
77+
expect(args[1].length).to.equal(wantedArglen);
7878
});
7979
});
8080
});

test/unit/utils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { nodeKeyToRedisOptions } from "../../lib/cluster/util";
2-
import { Cluster } from "../../lib";
31
import * as sinon from "sinon";
42
import { expect } from "chai";
53
import * as utils from "../../lib/utils";
@@ -251,6 +249,7 @@ describe("utils", function() {
251249
it("shuffles the array", () => {
252250
const arr = [1, 2, 3, 4];
253251
const copy = arr.slice(0);
252+
// eslint-disable-next-line no-constant-condition
254253
while (true) {
255254
utils.shuffle(copy);
256255
for (let i = 0; i < copy.length; i++) {

0 commit comments

Comments
 (0)