Skip to content

Commit e4dca0c

Browse files
committed
unicorn eslint
1 parent 8f0b33e commit e4dca0c

File tree

98 files changed

+582
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+582
-364
lines changed

.eslintrc.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,25 @@ module.exports = {
2323
"@typescript-eslint/no-explicit-any": "off",
2424
"@typescript-eslint/no-inferrable-types": "off",
2525
"@typescript-eslint/no-unused-vars": "off",
26-
"unicorn/prefer-node-protocol": "error",
26+
27+
"unicorn/no-unnecessary-polyfills": "off",
28+
"unicorn/prefer-string-replace-all": "off",
29+
"unicorn/import-style": "off",
30+
"unicorn/prefer-module": "off",
31+
"unicorn/prefer-type-error": "off",
32+
"unicorn/prefer-event-target": "off",
33+
"unicorn/no-array-callback-reference": "off",
34+
"unicorn/no-this-assignment": "off",
35+
"unicorn/prefer-object-from-entries": "off",
36+
"unicorn/prefer-ternary": "off",
37+
"unicorn/prefer-code-point": "off",
38+
"unicorn/prefer-switch": "off",
39+
"unicorn/no-typeof-undefined": "off",
40+
"unicorn/no-new-array": "off",
41+
"unicorn/prefer-string-slice": "off",
2742
"unicorn/prevent-abbreviations": "off",
43+
"unicorn/no-negated-condition": "off",
44+
"unicorn/no-for-loop": "off",
2845
"unicorn/filename-case": "off",
2946
"unicorn/no-null": "off",
3047
"unicorn/catch-error-name": "off",
@@ -33,6 +50,13 @@ module.exports = {
3350
"unicorn/explicit-length-check": "off",
3451
"unicorn/numeric-separators-style": "off",
3552
"unicorn/no-await-expression-member": "off",
36-
"unicorn/no-zero-fractions": "off"
53+
"unicorn/no-zero-fractions": "off",
54+
"unicorn/prefer-native-coercion-functions": "off",
55+
"unicorn/no-array-method-this-argument": "off",
56+
"unicorn/no-useless-undefined": "off",
57+
"unicorn/no-array-reduce": "off",
58+
"unicorn/better-regex": "off",
59+
"unicorn/prefer-spread": "off",
60+
"unicorn/consistent-function-scoping": "off",
3761
}
3862
}

src/Auth/Certificate.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ export abstract class Certificate implements ICertificate {
3232
}
3333

3434
switch (options.type) {
35-
case Certificate.PEM:
35+
case Certificate.PEM: {
3636
certificate = this.createPem(options.certificate, options.password, options.ca);
3737
break;
38-
case Certificate.PFX:
39-
38+
}
39+
case Certificate.PFX: {
4040
certificate = this.createPfx(options.certificate, options.password, options.ca);
4141
break;
42-
default:
42+
}
43+
default: {
4344
throwError("InvalidArgumentException", "Unsupported authOptions type: " + options.type);
45+
}
4446
}
4547

4648
return certificate;

src/Documents/Attachments/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class AttachmentResult {
2929
public data: stream.Readable,
3030
public details: AttachmentDetails,
3131
private _response: HttpResponse) {
32+
// empty
3233
}
3334

3435
public dispose() {

src/Documents/BulkInsertOperation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class BulkInsertOperation {
111111
}
112112

113113
private async sendHeartBeat(): Promise<void> {
114-
if (new Date().getTime() - this._lastWriteToStream.getTime() < this._heartbeatCheckInterval) {
114+
if (Date.now() - this._lastWriteToStream.getTime() < this._heartbeatCheckInterval) {
115115
return;
116116
}
117117

@@ -133,10 +133,10 @@ export class BulkInsertOperation {
133133
private static _checkServerVersion(serverVersion: string): boolean {
134134
if (serverVersion) {
135135
const versionParsed = serverVersion.split(".");
136-
const major = parseInt(versionParsed[0], 10);
137-
const minor = versionParsed.length > 1 ? parseInt(versionParsed[1]) : 0;
138-
const build = versionParsed.length> 2 ? parseInt(versionParsed[2]) : 0;
139-
if (isNaN(major) || isNaN(minor)) {
136+
const major = Number.parseInt(versionParsed[0], 10);
137+
const minor = versionParsed.length > 1 ? Number.parseInt(versionParsed[1]) : 0;
138+
const build = versionParsed.length> 2 ? Number.parseInt(versionParsed[2]) : 0;
139+
if (Number.isNaN(major) || Number.isNaN(minor)) {
140140
return false;
141141
}
142142

@@ -169,7 +169,7 @@ export class BulkInsertOperation {
169169
let errorFromServer: Error;
170170
try {
171171
errorFromServer = await this._getExceptionFromOperation();
172-
} catch (ee) {
172+
} catch {
173173
// server is probably down, will propagate the original exception
174174
}
175175

src/Documents/Changes/ChangesObservable.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class ChangesObservable<T, TConnectionState extends IChangesConnectionSta
2323
public on(event: "error", handler: (error: Error) => void): this;
2424
public on(event: "data" | "error", handler: ((value: T) => void) | ((error: Error) => void)): this {
2525
switch (event) {
26-
case "data":
26+
case "data": {
2727
// since allow multiple subscriptions on single object we cant register it multiple times
2828
// to avoid duplicates in notification
2929
if (!this._sendHandler) {
@@ -35,7 +35,8 @@ export class ChangesObservable<T, TConnectionState extends IChangesConnectionSta
3535
this._subscribers.add(handler as (value: T) => void);
3636
this._connectionState.inc();
3737
break;
38-
case "error":
38+
}
39+
case "error": {
3940
if (!this._errorHandler) {
4041
// register shared error handler
4142
this._errorHandler = (ex: Error) => this.error(ex);
@@ -44,6 +45,7 @@ export class ChangesObservable<T, TConnectionState extends IChangesConnectionSta
4445

4546
this._errorSubscribers.add(handler as (error: Error) => void);
4647
break;
48+
}
4749
}
4850

4951
return this;
@@ -60,7 +62,7 @@ export class ChangesObservable<T, TConnectionState extends IChangesConnectionSta
6062
public off(event: "data" | "error", handler: ((value: T) => void) | ((error: Error) => void)): this {
6163

6264
switch (event) {
63-
case "data":
65+
case "data": {
6466
if (this._subscribers.delete(handler as (value: T) => void)) {
6567
this._connectionState.dec();
6668
}
@@ -72,13 +74,15 @@ export class ChangesObservable<T, TConnectionState extends IChangesConnectionSta
7274
}
7375

7476
break;
75-
case "error":
77+
}
78+
case "error": {
7679
this._errorSubscribers.delete(handler as (error: Error) => void);
7780
if (!this._errorSubscribers.size) {
7881
this._connectionState.removeOnError(this._errorHandler);
7982
this._errorHandler = undefined;
8083
}
8184
break;
85+
}
8286
}
8387

8488
return this;
@@ -94,11 +98,13 @@ export class ChangesObservable<T, TConnectionState extends IChangesConnectionSta
9498
return;
9599
}
96100

97-
this._subscribers.forEach(x => x(msg));
101+
for (const x of this._subscribers) x(msg);
98102
}
99103

100104
public error(e: Error): void {
101-
this._errorSubscribers.forEach(x => x(e));
105+
for (const x of this._errorSubscribers) {
106+
x(e);
107+
}
102108
}
103109

104110
public ensureSubscribedNow(): Promise<void> {

src/Documents/Changes/DatabaseChanges.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class DatabaseChanges implements IDatabaseChanges {
252252
if (this.connected) {
253253
await this._send(unwatchCommand, value, values);
254254
}
255-
} catch (e) {
255+
} catch {
256256
// if we are not connected then we unsubscribed already
257257
// because connections drops with all subscriptions
258258
}
@@ -476,24 +476,42 @@ export class DatabaseChanges implements IDatabaseChanges {
476476

477477
private _notifySubscribers(type: string, value: any): void {
478478
switch (type) {
479-
case "AggressiveCacheChange":
480-
this._counters.forEach(state => state.send("AggressiveCache", AggressiveCacheChange.INSTANCE));
479+
case "AggressiveCacheChange": {
480+
for (const state of this._counters.values()) {
481+
state.send("AggressiveCache", AggressiveCacheChange.INSTANCE);
482+
}
481483
break;
482-
case "DocumentChange":
483-
this._counters.forEach(state => state.send("Document", value));
484+
}
485+
case "DocumentChange": {
486+
for (const state of this._counters.values()) {
487+
state.send("Document", value);
488+
}
484489
break;
485-
case "CounterChange":
486-
this._counters.forEach(state => state.send("Counter", value));
490+
}
491+
case "CounterChange": {
492+
for (const state of this._counters.values()) {
493+
state.send("Counter", value);
494+
}
487495
break;
488-
case "TimeSeriesChange":
489-
this._counters.forEach(state => state.send("TimeSeries", value));
496+
}
497+
case "TimeSeriesChange": {
498+
for (const state of this._counters.values()) {
499+
state.send("TimeSeries", value);
500+
}
490501
break;
491-
case "IndexChange":
492-
this._counters.forEach(state => state.send("Index", value));
502+
}
503+
case "IndexChange": {
504+
for (const state of this._counters.values()) {
505+
state.send("Index", value);
506+
}
493507
break;
494-
case "OperationStatusChange":
495-
this._counters.forEach(state => state.send("Operation", value));
508+
}
509+
case "OperationStatusChange": {
510+
for (const state of this._counters.values()) {
511+
state.send("Operation", value);
512+
}
496513
break;
514+
}
497515
case "TopologyChange": {
498516
const topologyChange = value as TopologyChange;
499517
const requestExecutor = this._requestExecutor;
@@ -513,8 +531,9 @@ export class DatabaseChanges implements IDatabaseChanges {
513531
}
514532
break;
515533
}
516-
default:
534+
default: {
517535
throwError("NotSupportedException");
536+
}
518537
}
519538
}
520539

src/Documents/Commands/Batches/SingleNodeBatchCommand.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,6 @@ export class SingleNodeBatchCommand extends RavenCommand<BatchCommandResult> imp
194194

195195
// eslint-disable-next-line @typescript-eslint/no-empty-function
196196
public dispose(): void {
197+
// empty
197198
}
198199
}

src/Documents/Commands/GetDocumentsCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ export class GetDocumentsCommand extends RavenCommand<GetDocumentsResult> {
283283

284284
let newUri = request.uri;
285285
if (isGet) {
286-
uniqueIds.forEach(x => {
286+
for (const x of uniqueIds) {
287287
newUri += `&id=${encodeURIComponent(x || "")}`;
288-
});
288+
}
289289

290290
return { method: "GET", uri: newUri };
291291
} else {

src/Documents/Commands/MultiGet/GetResponse.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ export class GetResponse {
9090
case StatusCodes.NonAuthoritativeInformation:
9191
case StatusCodes.NoContent:
9292
case StatusCodes.NotModified:
93-
case StatusCodes.NotFound:
93+
case StatusCodes.NotFound: {
9494
return false;
95-
default:
95+
}
96+
default: {
9697
return true;
98+
}
9799
}
98100
}
99101
}

src/Documents/Commands/QueryCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ export class QueryCommand extends RavenCommand<QueryResult> {
145145
mapped.durationInMs = timings.DurationInMs;
146146
mapped.timings = timings.Timings ? {} : undefined;
147147
if (timings.Timings) {
148-
Object.keys(timings.Timings).forEach(time => {
148+
for (const time of Object.keys(timings.Timings)) {
149149
mapped.timings[StringUtil.uncapitalize(time)] = QueryCommand._mapTimingsToLocalObject(timings.Timings[time]);
150-
});
150+
}
151151
}
152152
return mapped;
153153
}

0 commit comments

Comments
 (0)