Skip to content

Commit ebffbd6

Browse files
committed
fix(lint): fixed problem about lint
1 parent fc045b4 commit ebffbd6

File tree

9 files changed

+88
-66
lines changed

9 files changed

+88
-66
lines changed

src/examples/multi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import * as Redis from '../lib';
4040

4141
await multi.hMGet('h', ['age', 'title']);
4242
await multi.hGetAll('h');
43-
console.log(JSON.stringify(await multi.scan(0), null, 2));
43+
await multi.scan(0);
4444

4545
await multi.incr('a', 123);
4646

@@ -52,4 +52,4 @@ import * as Redis from '../lib';
5252

5353
await cli.close();
5454

55-
})().catch((e) => console.error(e));
55+
})().catch((e) => { console.error(e); });

src/examples/pipeline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ import * as Redis from '../lib';
5050

5151
await cli.close();
5252

53-
})().catch((e) => console.error(e));
53+
})().catch((e) => { console.error(e); });

src/lib/BaseClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export abstract class BaseClient
3939

4040
if (e) {
4141

42-
return callback(e);
42+
callback(e); return;
4343
}
4444

4545
super._onConnected(callback);
@@ -48,21 +48,21 @@ export abstract class BaseClient
4848
return;
4949
}
5050

51-
return super._onConnected(callback);
51+
super._onConnected(callback); return;
5252
}
5353

5454
this._send('AUTH', [this._password], (err: any): void => {
5555

5656
if (err) {
5757

58-
return callback(err);
58+
callback(err); return;
5959
}
6060

6161
this._send('SELECT', [this._db], (err2: any): void => {
6262

6363
if (err2) {
6464

65-
return callback(err2);
65+
callback(err2); return;
6666
}
6767

6868
super._onConnected(callback);

src/lib/CommandClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export class CommandClient
2525
extends BaseClient
2626
implements C.ICommandClientBase {
2727

28-
private _createDecoder: C.TDecoderFactory;
28+
private readonly _createDecoder: C.TDecoderFactory;
2929

30-
private _createEncoder: C.TEncoderFactory;
30+
private readonly _createEncoder: C.TEncoderFactory;
3131

3232
public constructor(opts: C.IClientOptions) {
3333

src/lib/Decoder.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class DecodeContext {
7171
*/
7272
public status: EDecodeStatus;
7373

74-
public data: Record<string, any>;
74+
public data: {
75+
length: number;
76+
};
7577

7678
public value: any;
7779

@@ -84,7 +86,7 @@ class DecodeContext {
8486
pos: number = 0
8587
) {
8688

87-
this.data = {};
89+
this.data = {} as any;
8890
this.status = status;
8991
this.pos = pos;
9092
}
@@ -330,9 +332,9 @@ export class Decoder
330332

331333
private _pop(end: number): void {
332334

333-
let context = this._ctx;
335+
const context = this._ctx;
334336

335-
this._ctx = this._contextStack.pop() as DecodeContext;
337+
this._ctx = this._contextStack.pop()!;
336338

337339
if (this._ctx.status === EDecodeStatus.READING_LIST) {
338340

src/lib/Encoder.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class Encoder implements A.IEncoder {
2626

2727
protected _getStringEncodedLength(val: string | Buffer): number {
2828

29-
let l = Buffer.byteLength(val);
29+
const l = Buffer.byteLength(val);
3030

3131
return 5 + l + l.toString().length;
3232
}
@@ -65,8 +65,6 @@ export class Encoder implements A.IEncoder {
6565

6666
public encodeCommand(cmd: string | Buffer, values?: Array<string | Buffer | number>): Buffer {
6767

68-
let ret: Buffer;
69-
7068
let length: number = 3;
7169

7270
if (values) {
@@ -81,7 +79,7 @@ export class Encoder implements A.IEncoder {
8179

8280
length += (1 + values.length).toString().length;
8381

84-
for (let el of values) {
82+
for (const el of values) {
8583

8684
length += this._getStringEncodedLength(el as string);
8785
}
@@ -93,7 +91,7 @@ export class Encoder implements A.IEncoder {
9391

9492
length += this._getStringEncodedLength(cmd);
9593

96-
ret = Buffer.allocUnsafe(length);
94+
const ret = Buffer.allocUnsafe(length);
9795

9896
let pos: number = 0;
9997

@@ -112,7 +110,7 @@ export class Encoder implements A.IEncoder {
112110

113111
if (values) {
114112

115-
for (let el of values) {
113+
for (const el of values) {
116114

117115
pos = this._writeString(
118116
ret,
@@ -127,7 +125,7 @@ export class Encoder implements A.IEncoder {
127125

128126
public encodeString(data: string | Buffer): Buffer {
129127

130-
let ret = Buffer.allocUnsafe(this._getStringEncodedLength(data));
128+
const ret = Buffer.allocUnsafe(this._getStringEncodedLength(data));
131129

132130
this._writeString(ret, data, 0);
133131

@@ -136,17 +134,16 @@ export class Encoder implements A.IEncoder {
136134

137135
public encodeMessage(data: string | Buffer): Buffer {
138136

139-
// @ts-ignore
140137
if (data.indexOf(PROTO_DELIMITER_VALUE) > -1) {
141138

142139
throw new E.E_PROTOCOL_ERROR({
143140
'message': 'CRLF is forbidden in MESSAGE.'
144141
});
145142
}
146143

147-
let length = Buffer.byteLength(data);
144+
const length = Buffer.byteLength(data);
148145

149-
let ret = Buffer.allocUnsafe(length + 3);
146+
const ret = Buffer.allocUnsafe(length + 3);
150147

151148
ret[0] = 43;
152149

@@ -173,9 +170,9 @@ export class Encoder implements A.IEncoder {
173170
});
174171
}
175172

176-
let length = Buffer.byteLength(data);
173+
const length = Buffer.byteLength(data);
177174

178-
let ret = Buffer.allocUnsafe(length + 3);
175+
const ret = Buffer.allocUnsafe(length + 3);
179176

180177
ret[0] = 45;
181178

@@ -195,11 +192,11 @@ export class Encoder implements A.IEncoder {
195192

196193
public encodeInteger(val: number): Buffer {
197194

198-
let data = val.toString();
195+
const data = val.toString();
199196

200-
let len = Buffer.byteLength(data);
197+
const len = Buffer.byteLength(data);
201198

202-
let ret = Buffer.allocUnsafe(3 + len);
199+
const ret = Buffer.allocUnsafe(3 + len);
203200

204201
ret[0] = 58;
205202

@@ -212,12 +209,12 @@ export class Encoder implements A.IEncoder {
212209

213210
public encodeList(data: A.ListItem[]): Buffer {
214211

215-
let ret: Buffer[] = [
212+
const ret: Buffer[] = [
216213
Buffer.from(`*${data.length}`),
217214
PROTO_DELIMITER
218215
];
219216

220-
for (let item of data) {
217+
for (const item of data) {
221218

222219
switch (item[0]) {
223220
case A.EDataType.FAILURE:
@@ -235,6 +232,9 @@ export class Encoder implements A.IEncoder {
235232
case A.EDataType.LIST:
236233
ret.push(this.encodeList(item[1]));
237234
break;
235+
case A.EDataType.NULL:
236+
ret.push(this.encodeNull());
237+
break;
238238
}
239239
}
240240

src/lib/ProtocolClient.ts

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,28 @@ interface IPendingQueueItem extends IQueueItem {
3636
function wrapPromise<TR = any, TW = any>(
3737
process: (cb: C.ICallbackA<TR, TW>) => void,
3838
callback?: C.ICallbackA<TR, TW>,
39-
): Promise<any> | void {
39+
): Promise<any> | undefined {
4040

4141
if (callback) {
4242

4343
process(callback);
44+
return undefined;
4445
}
4546
else {
4647

4748
return new Promise(
48-
(resolve, reject) => process(
49-
(e: any, r?: any) => e ? reject(e) : resolve(r)
50-
)
49+
(resolve, reject) => {
50+
process(
51+
(e: any, r?: any) => {
52+
if (e) {
53+
reject(e);
54+
}
55+
else {
56+
resolve(r);
57+
}
58+
}
59+
);
60+
}
5161
);
5262
}
5363
}
@@ -68,15 +78,15 @@ export class ProtocolClient
6878

6979
private _sendingQueue: IQueueItem[] = [];
7080

71-
private _decoder: C.IDecoder;
81+
private readonly _decoder: C.IDecoder;
7282

73-
private _encoder: C.IEncoder;
83+
private readonly _encoder: C.IEncoder;
7484

7585
private _ready: boolean = false;
7686

77-
private _subscribeMode: boolean;
87+
private readonly _subscribeMode: boolean;
7888

79-
private _pipelineMode: boolean;
89+
private readonly _pipelineMode: boolean;
8090

8191
public readonly host: string;
8292

@@ -112,7 +122,7 @@ export class ProtocolClient
112122

113123
this._decoder.on('data', (type, data): void => {
114124

115-
const it = this._executingQueue.shift() as IQueueItem;
125+
const it = this._executingQueue.shift()!;
116126

117127
switch (type) {
118128
case C.EDataType.FAILURE:
@@ -201,7 +211,7 @@ export class ProtocolClient
201211

202212
this._decoder.on('data', (type, data): void => {
203213

204-
const cb = this._executingQueue.shift() as IQueueItem;
214+
const cb = this._executingQueue.shift()!;
205215

206216
switch (type) {
207217
case C.EDataType.FAILURE:
@@ -269,15 +279,25 @@ export class ProtocolClient
269279

270280
this._pendingQueue = [];
271281

272-
for (let x of queue) {
282+
for (const x of queue) {
273283

274284
if (this._socket.writable) {
275285

276286
this._sendingQueue.push(x);
277287

278288
this._socket.write(
279289
x.data,
280-
(e) => e ? callback(e) : this._executingQueue.push(this._sendingQueue.shift() as any)
290+
(e) => {
291+
292+
if (e) {
293+
294+
callback(e);
295+
}
296+
else {
297+
298+
this._executingQueue.push(this._sendingQueue.shift() as any);
299+
}
300+
}
281301
);
282302
}
283303
}
@@ -310,7 +330,7 @@ export class ProtocolClient
310330

311331
this._status = C.EClientStatus.CONNECTING;
312332

313-
// @ts-ignore
333+
// @ts-expect-error
314334
this._socket.__uuid = ++this._uuidCounter;
315335

316336
this._timeoutLocked = false;
@@ -325,7 +345,7 @@ export class ProtocolClient
325345

326346
this._socket.on('connect', () => {
327347

328-
// @ts-ignore
348+
// @ts-expect-error
329349
if (this._socket.__uuid !== this._uuidCounter) {
330350

331351
return;
@@ -357,7 +377,7 @@ export class ProtocolClient
357377
})
358378
.on('error', (e: any) => {
359379

360-
// @ts-ignore
380+
// @ts-expect-error
361381
if (this._socket.__uuid !== this._uuidCounter) {
362382

363383
return;
@@ -367,7 +387,7 @@ export class ProtocolClient
367387
})
368388
.on('close', () => {
369389

370-
// @ts-ignore
390+
// @ts-expect-error
371391
if (this._socket.__uuid !== this._uuidCounter) {
372392

373393
return;
@@ -380,7 +400,7 @@ export class ProtocolClient
380400
return;
381401
}
382402

383-
for (let x of this._sendingQueue) {
403+
for (const x of this._sendingQueue) {
384404

385405
try {
386406

@@ -392,7 +412,7 @@ export class ProtocolClient
392412
}
393413
}
394414

395-
for (let x of this._executingQueue) {
415+
for (const x of this._executingQueue) {
396416

397417
try {
398418

@@ -522,7 +542,7 @@ export class ProtocolClient
522542
!this._socket?.writable
523543
) {
524544

525-
this._pendingQueue.push({data, callback, count: 1, result: []});
545+
this._pendingQueue.push({ data, callback, count: 1, result: [] });
526546
}
527547
else {
528548

@@ -562,7 +582,7 @@ export class ProtocolClient
562582
!this._socket?.writable
563583
) {
564584

565-
this._pendingQueue.push({data, callback, count: cmds.length, result: []});
585+
this._pendingQueue.push({ data, callback, count: cmds.length, result: [] });
566586
}
567587
else {
568588

0 commit comments

Comments
 (0)