Skip to content

Commit 158db3f

Browse files
committed
chore: fixing lint issues
1 parent e1d1079 commit 158db3f

File tree

5 files changed

+83
-52
lines changed

5 files changed

+83
-52
lines changed

packages/shared/sdk-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"build": "npx tsc --noEmit && rollup -c rollup.config.js && npm run make-package-jsons",
3838
"clean": "rimraf dist",
3939
"lint": "npx eslint . --ext .ts",
40-
"lint:fix": "yarn run lint -- --fix",
40+
"lint:fix": "npx eslint . --ext .ts --fix",
4141
"prettier": "prettier --write 'src/*.@(js|ts|tsx|json)'",
4242
"check": "yarn && yarn prettier && yarn lint && tsc && yarn test"
4343
},

packages/shared/sdk-client/src/LDClientImpl.ts

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import { LDIdentifyOptions } from './api/LDIdentifyOptions';
3232
import { createAsyncTaskQueue } from './async/AsyncTaskQueue';
3333
import { Configuration, ConfigurationImpl, LDClientInternalOptions } from './configuration';
3434
import { addAutoEnv } from './context/addAutoEnv';
35+
import {
36+
ActiveContextTracker,
37+
createActiveContextTracker,
38+
} from './context/createActiveContextTracker';
3539
import { ensureKey } from './context/ensureKey';
3640
import { DataManager, DataManagerFactory } from './DataManager';
3741
import createDiagnosticsManager from './diagnostics/createDiagnosticsManager';
@@ -43,13 +47,12 @@ import createEventProcessor from './events/createEventProcessor';
4347
import EventFactory from './events/EventFactory';
4448
import DefaultFlagManager, { FlagManager } from './flag-manager/FlagManager';
4549
import { FlagChangeType } from './flag-manager/FlagUpdater';
50+
import { ItemDescriptor } from './flag-manager/ItemDescriptor';
4651
import HookRunner from './HookRunner';
4752
import { getInspectorHook } from './inspection/getInspectorHook';
4853
import InspectorManager from './inspection/InspectorManager';
4954
import LDEmitter, { EventName } from './LDEmitter';
5055
import { createPluginEnvironmentMetadata } from './plugins/createPluginEnvironmentMetadata';
51-
import { ActiveContextTracker, createActiveContextTracker } from './context/createActiveContextTracker';
52-
import { ItemDescriptor } from './flag-manager/ItemDescriptor';
5356

5457
const { ClientMessages, ErrorKinds } = internal;
5558

@@ -61,7 +64,7 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
6164
private _eventProcessor?: internal.EventProcessor;
6265
readonly logger: LDLogger;
6366

64-
private _activeContextTracker: ActiveContextTracker = createActiveContextTracker()
67+
private _activeContextTracker: ActiveContextTracker = createActiveContextTracker();
6568

6669
private readonly _highTimeoutThreshold: number = 15;
6770

@@ -202,7 +205,9 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
202205
// code. We are returned the unchecked context so that if a consumer identifies with an invalid context
203206
// and then calls getContext, they get back the same context they provided, without any assertion about
204207
// validity.
205-
return this._activeContextTracker.hasContext() ? clone<LDContext>(this._activeContextTracker.getPristineContext()) : undefined;
208+
return this._activeContextTracker.hasContext()
209+
? clone<LDContext>(this._activeContextTracker.getPristineContext())
210+
: undefined;
206211
}
207212

208213
protected getInternalContext(): Context | undefined {
@@ -302,7 +307,7 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
302307
this.emitter.emit('error', context, error);
303308
return Promise.reject(error);
304309
}
305-
this._activeContextTracker.set(context, checkedContext)
310+
this._activeContextTracker.set(context, checkedContext);
306311

307312
this._eventProcessor?.sendEvent(
308313
this._eventFactoryDefault.identifyEvent(checkedContext),
@@ -376,7 +381,12 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
376381

377382
this._eventProcessor?.sendEvent(
378383
this._config.trackEventModifier(
379-
this._eventFactoryDefault.customEvent(key, this._activeContextTracker.getContext()!, data, metricValue),
384+
this._eventFactoryDefault.customEvent(
385+
key,
386+
this._activeContextTracker.getContext()!,
387+
data,
388+
metricValue,
389+
),
380390
),
381391
);
382392

@@ -401,9 +411,11 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
401411

402412
// NOTE: we will be changing this behavior soon once we have a tracker on the
403413
// client initialization state.
404-
const hasContext = this._activeContextTracker.hasContext()
414+
const hasContext = this._activeContextTracker.hasContext();
405415
if (!hasContext) {
406-
this.logger?.warn('Flag evaluation called before client is fully initialized, data from this evaulation could be stale.')
416+
this.logger?.warn(
417+
'Flag evaluation called before client is fully initialized, data from this evaulation could be stale.',
418+
);
407419
}
408420

409421
const evalContext = this._activeContextTracker.getContext()!;
@@ -416,9 +428,11 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
416428
);
417429

418430
this.emitter.emit('error', this._activeContextTracker.getPristineContext(), error);
419-
hasContext && this._eventProcessor?.sendEvent(
420-
this._eventFactoryDefault.unknownFlagEvent(flagKey, defVal, evalContext),
421-
);
431+
if (hasContext) {
432+
this._eventProcessor?.sendEvent(
433+
this._eventFactoryDefault.unknownFlagEvent(flagKey, defVal, evalContext),
434+
);
435+
}
422436
return createErrorEvaluationDetail(ErrorKinds.FlagNotFound, defaultValue);
423437
}
424438

@@ -427,16 +441,18 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
427441
if (typeChecker) {
428442
const [matched, type] = typeChecker(value);
429443
if (!matched) {
430-
hasContext && this._eventProcessor?.sendEvent(
431-
eventFactory.evalEventClient(
432-
flagKey,
433-
defaultValue, // track default value on type errors
434-
defaultValue,
435-
foundItem.flag,
436-
evalContext,
437-
reason,
438-
),
439-
);
444+
if (hasContext) {
445+
this._eventProcessor?.sendEvent(
446+
eventFactory.evalEventClient(
447+
flagKey,
448+
defaultValue, // track default value on type errors
449+
defaultValue,
450+
foundItem.flag,
451+
evalContext,
452+
reason,
453+
),
454+
);
455+
}
440456
const error = new LDClientError(
441457
`Wrong type "${type}" for feature flag "${flagKey}"; returning default value`,
442458
);
@@ -454,16 +470,18 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
454470
prerequisites?.forEach((prereqKey) => {
455471
this._variationInternal(prereqKey, undefined, this._eventFactoryDefault);
456472
});
457-
hasContext && this._eventProcessor?.sendEvent(
458-
eventFactory.evalEventClient(
459-
flagKey,
460-
value,
461-
defaultValue,
462-
foundItem.flag,
463-
evalContext,
464-
reason,
465-
),
466-
);
473+
if (hasContext) {
474+
this._eventProcessor?.sendEvent(
475+
eventFactory.evalEventClient(
476+
flagKey,
477+
value,
478+
defaultValue,
479+
foundItem.flag,
480+
evalContext,
481+
reason,
482+
),
483+
);
484+
}
467485
return successDetail;
468486
}
469487

@@ -477,8 +495,11 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
477495
return value;
478496
}
479497
variationDetail(flagKey: string, defaultValue?: LDFlagValue): LDEvaluationDetail {
480-
return this._hookRunner.withEvaluation(flagKey, this._activeContextTracker.getPristineContext(), defaultValue, () =>
481-
this._variationInternal(flagKey, defaultValue, this._eventFactoryWithReasons),
498+
return this._hookRunner.withEvaluation(
499+
flagKey,
500+
this._activeContextTracker.getPristineContext(),
501+
defaultValue,
502+
() => this._variationInternal(flagKey, defaultValue, this._eventFactoryWithReasons),
482503
);
483504
}
484505

@@ -488,8 +509,11 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
488509
eventFactory: EventFactory,
489510
typeChecker: (value: unknown) => [boolean, string],
490511
): LDEvaluationDetailTyped<T> {
491-
return this._hookRunner.withEvaluation(key, this._activeContextTracker.getPristineContext(), defaultValue, () =>
492-
this._variationInternal(key, defaultValue, eventFactory, typeChecker),
512+
return this._hookRunner.withEvaluation(
513+
key,
514+
this._activeContextTracker.getPristineContext(),
515+
defaultValue,
516+
() => this._variationInternal(key, defaultValue, eventFactory, typeChecker),
493517
);
494518
}
495519

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Context, LDContext } from "@launchdarkly/js-sdk-common"
1+
import { Context, LDContext } from '@launchdarkly/js-sdk-common';
22

33
/**
44
* ActiveContextTracker is an internal class that helps tracks the current active context
55
* used by the client.
66
*/
77
export interface ActiveContextTracker {
8-
_pristineContext?: LDContext
9-
_context?: Context
8+
_pristineContext?: LDContext;
9+
_context?: Context;
1010

1111
/**
1212
* Set the active context and pristine context. This will only be called when the passed in context
@@ -15,46 +15,46 @@ export interface ActiveContextTracker {
1515
* @param pristineContext - The pristine context, which is the context as it was passed in to the SDK.
1616
* @param context - The active context, which is the context as it was checked and validated.
1717
*/
18-
set(pristineContext: LDContext, context: Context): void
18+
set(pristineContext: LDContext, context: Context): void;
1919

2020
/**
2121
* Get the active context.
2222
*
2323
* @returns The active context or undefined if it has not been set.
2424
*/
25-
getContext(): Context | undefined
25+
getContext(): Context | undefined;
2626

2727
/**
2828
* Get the pristine context.
2929
*
3030
* @returns The pristine context or undefined if it has not been set.
3131
*/
32-
getPristineContext(): LDContext | undefined
32+
getPristineContext(): LDContext | undefined;
3333

3434
/**
3535
* Create a new identification promise. To allow other parts of the SDK to track the identification process.
36-
*
36+
*
3737
* TODO(self): this is a very generic method so maybe it doesn't belong here?
3838
*/
3939
newIdentificationPromise(): {
4040
identifyPromise: Promise<void>;
4141
identifyResolve: () => void;
4242
identifyReject: (err: Error) => void;
43-
}
43+
};
4444

4545
/**
4646
* Check if the active context is set. Regardless of whether it is valid or not.
4747
*
4848
* @returns True if the active context is set, false otherwise.
4949
*/
50-
hasContext(): boolean
50+
hasContext(): boolean;
5151

5252
/**
5353
* Check if the active context is valid.
5454
*
5555
* @returns True if the active context is valid, false otherwise.
5656
*/
57-
hasValidContext(): boolean
57+
hasValidContext(): boolean;
5858
}
5959

6060
export function createActiveContextTracker(): ActiveContextTracker {
@@ -65,8 +65,12 @@ export function createActiveContextTracker(): ActiveContextTracker {
6565
this._pristineContext = pristineContext;
6666
this._context = context;
6767
},
68-
getContext() { return this._context; },
69-
getPristineContext() { return this._pristineContext; },
68+
getContext() {
69+
return this._context;
70+
},
71+
getPristineContext() {
72+
return this._pristineContext;
73+
},
7074
newIdentificationPromise() {
7175
let res: () => void;
7276
let rej: (err: Error) => void;
@@ -78,7 +82,11 @@ export function createActiveContextTracker(): ActiveContextTracker {
7882

7983
return { identifyPromise: basePromise, identifyResolve: res!, identifyReject: rej! };
8084
},
81-
hasContext() { return this._context !== undefined; },
82-
hasValidContext() { return this.hasContext() && this._context!.valid; },
85+
hasContext() {
86+
return this._context !== undefined;
87+
},
88+
hasValidContext() {
89+
return this.hasContext() && this._context!.valid;
90+
},
8391
};
8492
}

packages/shared/sdk-client/src/flag-manager/FlagManager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export interface FlagManager {
4040
*/
4141
loadCached(context: Context): Promise<boolean>;
4242

43-
4443
/**
4544
* Updates in-memory storage with the specified flags without a context
4645
* or persistent storage. Flags set in this way are considered emphemeral and

packages/shared/sdk-client/src/flag-manager/FlagUpdater.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class FlagUpdater {
4242
}
4343

4444
init(context: Context, newFlags: { [key: string]: ItemDescriptor }) {
45-
this._activeContext = context
45+
this._activeContext = context;
4646
const oldFlags = this._flagStore.getAll();
4747
this._flagStore.init(newFlags);
4848
const changed = calculateChangedKeys(oldFlags, newFlags);

0 commit comments

Comments
 (0)