Skip to content

Commit

Permalink
unicorn eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
ml054 committed Apr 6, 2024
1 parent 8f0b33e commit 40e61d2
Show file tree
Hide file tree
Showing 98 changed files with 579 additions and 363 deletions.
28 changes: 26 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,25 @@ module.exports = {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unused-vars": "off",
"unicorn/prefer-node-protocol": "error",

"unicorn/no-unnecessary-polyfills": "off",
"unicorn/prefer-string-replace-all": "off",
"unicorn/import-style": "off",
"unicorn/prefer-module": "off",
"unicorn/prefer-type-error": "off",
"unicorn/prefer-event-target": "off",
"unicorn/no-array-callback-reference": "off",
"unicorn/no-this-assignment": "off",
"unicorn/prefer-object-from-entries": "off",
"unicorn/prefer-ternary": "off",
"unicorn/prefer-code-point": "off",
"unicorn/prefer-switch": "off",
"unicorn/no-typeof-undefined": "off",
"unicorn/no-new-array": "off",
"unicorn/prefer-string-slice": "off",
"unicorn/prevent-abbreviations": "off",
"unicorn/no-negated-condition": "off",
"unicorn/no-for-loop": "off",
"unicorn/filename-case": "off",
"unicorn/no-null": "off",
"unicorn/catch-error-name": "off",
Expand All @@ -33,6 +50,13 @@ module.exports = {
"unicorn/explicit-length-check": "off",
"unicorn/numeric-separators-style": "off",
"unicorn/no-await-expression-member": "off",
"unicorn/no-zero-fractions": "off"
"unicorn/no-zero-fractions": "off",
"unicorn/prefer-native-coercion-functions": "off",
"unicorn/no-array-method-this-argument": "off",
"unicorn/no-useless-undefined": "off",
"unicorn/no-array-reduce": "off",
"unicorn/better-regex": "off",
"unicorn/prefer-spread": "off",
"unicorn/consistent-function-scoping": "off",
}
}
10 changes: 6 additions & 4 deletions src/Auth/Certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ export abstract class Certificate implements ICertificate {
}

switch (options.type) {
case Certificate.PEM:
case Certificate.PEM: {
certificate = this.createPem(options.certificate, options.password, options.ca);
break;
case Certificate.PFX:

}
case Certificate.PFX: {
certificate = this.createPfx(options.certificate, options.password, options.ca);
break;
default:
}
default: {
throwError("InvalidArgumentException", "Unsupported authOptions type: " + options.type);
}
}

return certificate;
Expand Down
1 change: 1 addition & 0 deletions src/Documents/Attachments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class AttachmentResult {
public data: stream.Readable,
public details: AttachmentDetails,
private _response: HttpResponse) {
// empty
}

public dispose() {
Expand Down
12 changes: 6 additions & 6 deletions src/Documents/BulkInsertOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class BulkInsertOperation {
}

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

Expand All @@ -133,10 +133,10 @@ export class BulkInsertOperation {
private static _checkServerVersion(serverVersion: string): boolean {
if (serverVersion) {
const versionParsed = serverVersion.split(".");
const major = parseInt(versionParsed[0], 10);
const minor = versionParsed.length > 1 ? parseInt(versionParsed[1]) : 0;
const build = versionParsed.length> 2 ? parseInt(versionParsed[2]) : 0;
if (isNaN(major) || isNaN(minor)) {
const major = Number.parseInt(versionParsed[0], 10);
const minor = versionParsed.length > 1 ? Number.parseInt(versionParsed[1]) : 0;
const build = versionParsed.length> 2 ? Number.parseInt(versionParsed[2]) : 0;
if (Number.isNaN(major) || Number.isNaN(minor)) {
return false;
}

Expand Down Expand Up @@ -169,7 +169,7 @@ export class BulkInsertOperation {
let errorFromServer: Error;
try {
errorFromServer = await this._getExceptionFromOperation();
} catch (ee) {
} catch {
// server is probably down, will propagate the original exception
}

Expand Down
18 changes: 12 additions & 6 deletions src/Documents/Changes/ChangesObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ChangesObservable<T, TConnectionState extends IChangesConnectionSta
public on(event: "error", handler: (error: Error) => void): this;
public on(event: "data" | "error", handler: ((value: T) => void) | ((error: Error) => void)): this {
switch (event) {
case "data":
case "data": {
// since allow multiple subscriptions on single object we cant register it multiple times
// to avoid duplicates in notification
if (!this._sendHandler) {
Expand All @@ -35,7 +35,8 @@ export class ChangesObservable<T, TConnectionState extends IChangesConnectionSta
this._subscribers.add(handler as (value: T) => void);
this._connectionState.inc();
break;
case "error":
}
case "error": {
if (!this._errorHandler) {
// register shared error handler
this._errorHandler = (ex: Error) => this.error(ex);
Expand All @@ -44,6 +45,7 @@ export class ChangesObservable<T, TConnectionState extends IChangesConnectionSta

this._errorSubscribers.add(handler as (error: Error) => void);
break;
}
}

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

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

break;
case "error":
}
case "error": {
this._errorSubscribers.delete(handler as (error: Error) => void);
if (!this._errorSubscribers.size) {
this._connectionState.removeOnError(this._errorHandler);
this._errorHandler = undefined;
}
break;
}
}

return this;
Expand All @@ -94,11 +98,13 @@ export class ChangesObservable<T, TConnectionState extends IChangesConnectionSta
return;
}

this._subscribers.forEach(x => x(msg));
for (const x of this._subscribers) x(msg);
}

public error(e: Error): void {
this._errorSubscribers.forEach(x => x(e));
for (const x of this._errorSubscribers) {
x(e);
}
}

public ensureSubscribedNow(): Promise<void> {
Expand Down
47 changes: 33 additions & 14 deletions src/Documents/Changes/DatabaseChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class DatabaseChanges implements IDatabaseChanges {
if (this.connected) {
await this._send(unwatchCommand, value, values);
}
} catch (e) {
} catch {
// if we are not connected then we unsubscribed already
// because connections drops with all subscriptions
}
Expand Down Expand Up @@ -476,24 +476,42 @@ export class DatabaseChanges implements IDatabaseChanges {

private _notifySubscribers(type: string, value: any): void {
switch (type) {
case "AggressiveCacheChange":
this._counters.forEach(state => state.send("AggressiveCache", AggressiveCacheChange.INSTANCE));
case "AggressiveCacheChange": {
for (const state of this._counters.values()) {
state.send("AggressiveCache", AggressiveCacheChange.INSTANCE);
}
break;
case "DocumentChange":
this._counters.forEach(state => state.send("Document", value));
}
case "DocumentChange": {
for (const state of this._counters.values()) {
state.send("Document", value);
}
break;
case "CounterChange":
this._counters.forEach(state => state.send("Counter", value));
}
case "CounterChange": {
for (const state of this._counters.values()) {
state.send("Counter", value);
}
break;
case "TimeSeriesChange":
this._counters.forEach(state => state.send("TimeSeries", value));
}
case "TimeSeriesChange": {
for (const state of this._counters.values()) {
state.send("TimeSeries", value);
}
break;
case "IndexChange":
this._counters.forEach(state => state.send("Index", value));
}
case "IndexChange": {
for (const state of this._counters.values()) {
state.send("Index", value);
}
break;
case "OperationStatusChange":
this._counters.forEach(state => state.send("Operation", value));
}
case "OperationStatusChange": {
for (const state of this._counters.values()) {
state.send("Operation", value);
}
break;
}
case "TopologyChange": {
const topologyChange = value as TopologyChange;
const requestExecutor = this._requestExecutor;
Expand All @@ -513,8 +531,9 @@ export class DatabaseChanges implements IDatabaseChanges {
}
break;
}
default:
default: {
throwError("NotSupportedException");
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Documents/Commands/Batches/SingleNodeBatchCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,6 @@ export class SingleNodeBatchCommand extends RavenCommand<BatchCommandResult> imp

// eslint-disable-next-line @typescript-eslint/no-empty-function
public dispose(): void {
// empty
}
}
4 changes: 2 additions & 2 deletions src/Documents/Commands/GetDocumentsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ export class GetDocumentsCommand extends RavenCommand<GetDocumentsResult> {

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

return { method: "GET", uri: newUri };
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/Documents/Commands/MultiGet/GetResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ export class GetResponse {
case StatusCodes.NonAuthoritativeInformation:
case StatusCodes.NoContent:
case StatusCodes.NotModified:
case StatusCodes.NotFound:
case StatusCodes.NotFound: {
return false;
default:
}
default: {
return true;
}
}
}
}
4 changes: 2 additions & 2 deletions src/Documents/Commands/QueryCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ export class QueryCommand extends RavenCommand<QueryResult> {
mapped.durationInMs = timings.DurationInMs;
mapped.timings = timings.Timings ? {} : undefined;
if (timings.Timings) {
Object.keys(timings.Timings).forEach(time => {
for (const time of Object.keys(timings.Timings)) {
mapped.timings[StringUtil.uncapitalize(time)] = QueryCommand._mapTimingsToLocalObject(timings.Timings[time]);
});
}
}
return mapped;
}
Expand Down
8 changes: 5 additions & 3 deletions src/Documents/DocumentStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export class DocumentStore extends DocumentStoreBase {
value.Value.Dispose();
}*/
this._databaseChanges.forEach(change => change.dispose());
for (const change of this._databaseChanges.values()) {
change.dispose();
}

/* TODO
// try to wait until all the async disposables are completed
Expand Down Expand Up @@ -151,13 +153,13 @@ export class DocumentStore extends DocumentStoreBase {
})
.then(() => {
this._log.info(`Disposing request executors ${this._requestExecutors.size}`);
this._requestExecutors.forEach((executor, db) => {
for (const [db, executor] of this._requestExecutors.entries()) {
try {
executor.dispose();
} catch (err) {
this._log.warn(err, `Error disposing request executor.`);
}
});
}
})
.finally(() => this.emit("executorsDisposed"));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Documents/DocumentStoreBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export abstract class DocumentStoreBase
): void;
public removeSessionListener(eventName: any, eventHandler: (eventArgs: any) => void): void {
const toRemove = this._eventHandlers
.filter(x => x[0] === eventName && x[1] === eventHandler)[0];
.find(x => x[0] === eventName && x[1] === eventHandler);
if (toRemove) {
this._eventHandlers.splice(this._eventHandlers.indexOf(toRemove), 1);
}
Expand All @@ -329,7 +329,7 @@ export abstract class DocumentStoreBase
public registerEvents(requestExecutor: RequestExecutor): void;
public registerEvents(session: DocumentSession): void;
public registerEvents(requestExecutorOrSession: RequestExecutor | DocumentSession): void {
this._eventHandlers.forEach(([eventName, eventHandler]) => {
for (const [eventName, eventHandler] of this._eventHandlers) {
if (eventName === "failedRequest"
|| eventName === "topologyUpdated"
|| eventName === "beforeRequest"
Expand All @@ -338,7 +338,7 @@ export abstract class DocumentStoreBase
} else {
(requestExecutorOrSession as DocumentSession).on(eventName, eventHandler);
}
});
}
}

public abstract maintenance: MaintenanceOperationExecutor;
Expand Down
2 changes: 1 addition & 1 deletion src/Documents/Identity/GenerateEntityIdOnTheClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class GenerateEntityIdOnTheClient {
}
resultCallback(null);
return false;
} catch (e) {
} catch {
throwError("InvalidOperationException", "Error trying to get ID from instance.");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Documents/Identity/HiloIdGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class HiloIdGenerator {
if (range !== this._range) {
continue;
}
} catch (e) {
} catch {
// previous task was faulted, we will try to replace it
}

Expand All @@ -91,7 +91,7 @@ export class HiloIdGenerator {
try {
// failed to replace, let's wait on the previous task
await this._nextRangeTask.getValue();
} catch (e) {
} catch {
// previous task was faulted, we will try again
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Documents/Identity/MultiTypeHiLoIdGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class MultiTypeHiLoIdGenerator {
: this._conventions.getCollectionNameForEntity(entity);

if (!typeTagName) {
return Promise.resolve(null);
return null;
}

const tag = await this._conventions.transformClassCollectionNameToDocumentIdPrefix(typeTagName);
Expand Down
6 changes: 3 additions & 3 deletions src/Documents/Indexes/AbstractIndexDefinitionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export abstract class AbstractIndexDefinitionBuilder<TIndexDefinition extends In
indexDefinition.patternForOutputReduceToCollectionReferences = this.patternForOutputReduceToCollectionReferences;
indexDefinition.patternReferencesCollectionName = this.patternReferencesCollectionName;

const suggestions: { [suggestionOption: string]: boolean } = Array.from(this.suggestionsOptions)
.reduce((result, item) =>
Object.assign(result, { [item]: true }), {});
const suggestions: { [suggestionOption: string]: boolean } = Object.fromEntries(Array.from(this.suggestionsOptions)
.map(( item) =>
[item, true]));

this._applyValues(indexDefinition, this.indexesStrings,
(options, value) => options.indexing = value);
Expand Down
Loading

0 comments on commit 40e61d2

Please sign in to comment.