Skip to content

Commit

Permalink
applied eslit --fix
Browse files Browse the repository at this point in the history
This commit is large since eslit --fix was run to auto fix most issues.
Some that did not have auto fixes were done manually.

Some changes were not made as they were too risky to change so instead
some in-line comments were used to suppress them. This was preferred
over globally turning off the rule, as keeping it on means new code has
to follow the rule.
  • Loading branch information
jkasten2 committed Aug 25, 2023
1 parent 6b927bd commit 92e5d2a
Show file tree
Hide file tree
Showing 76 changed files with 240 additions and 208 deletions.
2 changes: 1 addition & 1 deletion __test__/support/environment/TestEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getDummyIdentityOSModel, getDummyPushSubscriptionOSModel } from "../hel
import MainHelper from "../../../src/shared/helpers/MainHelper";
import { DUMMY_ONESIGNAL_ID, DUMMY_PUSH_TOKEN } from "../constants";

declare var global: any;
declare let global: any;

export interface TestEnvironmentConfig {
userConfig?: AppUserConfig;
Expand Down
2 changes: 1 addition & 1 deletion __test__/support/utils/Random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class Random {
* @param characterSet A string of characters to allow. Each character of the random string will
* be one character of this set chosen at random.
*/
public static getRandomString(length: number, characterSet: string = "abcdefghijklmnopqrstuvwxyz0123456789") {
public static getRandomString(length: number, characterSet = "abcdefghijklmnopqrstuvwxyz0123456789") {
return this.getRandomArray(length, characterSet.length, 0)
.map(n => characterSet[n])
.join('');
Expand Down
11 changes: 7 additions & 4 deletions src/core/CoreModuleDirector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class CoreModuleDirector {

/* O P E R A T I O N S */

public add(modelName: ModelName, model: OSModel<SupportedModel>, propagate: boolean = true): void {
public add(modelName: ModelName, model: OSModel<SupportedModel>, propagate = true): void {
logMethodCall("CoreModuleDirector.add", { modelName, model });
const modelStores = this.getModelStores();
modelStores[modelName].add(model, propagate);
Expand Down Expand Up @@ -225,15 +225,18 @@ export class CoreModuleDirector {
{
logMethodCall("CoreModuleDirector.getSubscriptionOfTypeWithToken", { type, token });
switch (type) {
case ModelName.EmailSubscriptions:
case ModelName.EmailSubscriptions: {
const emailSubscriptions = this.getEmailSubscriptionModels();
return Object.values(emailSubscriptions).find(subscription => subscription.data.token === token);
case ModelName.SmsSubscriptions:
}
case ModelName.SmsSubscriptions: {
const smsSubscriptions = this.getSmsSubscriptionModels();
return Object.values(smsSubscriptions).find(subscription => subscription.data.token === token);
case ModelName.PushSubscriptions:
}
case ModelName.PushSubscriptions: {
const pushSubscriptions = this.getAllPushSubscriptionModels();
return Object.values(pushSubscriptions).find(subscription => subscription.data.token === token);
}
default:
return undefined;
}
Expand Down
2 changes: 0 additions & 2 deletions src/core/Subscribable.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export default class Subscribable<MessageType> {
protected subscribers = new Set<(msg: MessageType) => void>();

constructor() {}

/**
* Subscribe to the message stream.
* @param {(msg:MessageType)=>void} callback
Expand Down
3 changes: 2 additions & 1 deletion src/core/caching/ModelCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { logMethodCall } from "../../shared/utils/utils";

export default class ModelCache {
private _mutexPromise: Promise<void> = Promise.resolve();
private _mutexLocked: boolean = false;
private _mutexLocked = false;

/**
* Add an entire model to the cache
Expand Down Expand Up @@ -45,6 +45,7 @@ export default class ModelCache {
}

this._mutexLocked = true;
// eslint-disable-next-line no-async-promise-executor
this._mutexPromise = new Promise(async (resolve, reject) => {
logMethodCall("ModelCache.update", { modelName, modelId, key, value });
const model = await this.get(modelName, modelId);
Expand Down
2 changes: 1 addition & 1 deletion src/core/modelRepo/OSModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class OSModel<Model> extends Subscribable<ModelStoreChange<Model>> {
* We use this method to update the model data.
* Results in a broadcasted update event.
*/
public set(property: StringKeys<Model>, newValue: any, propagate: boolean = true): void {
public set(property: StringKeys<Model>, newValue: any, propagate = true): void {
logMethodCall("set", { property, newValue });
let oldValue;

Expand Down
2 changes: 2 additions & 0 deletions src/core/operationRepo/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Operation<Model> {
this.payload = deltas ? this.getPayload(deltas) : undefined;
this.model = deltas ? deltas[deltas.length-1].model : undefined;
this.timestamp = Date.now();
// eslint-disable-next-line no-async-promise-executor
this.jwtTokenAvailable = new Promise<void>(async resolve => {
this.jwtToken = await Database.getJWTToken();
resolve();
Expand Down Expand Up @@ -49,6 +50,7 @@ export class Operation<Model> {
* 3. Delta 2: { a: { c: 3 } }
* 4. Result: { a: { b: 2, c: 3 } }
*/
// eslint-disable-next-line no-prototype-builtins
const hasExistingProperty = result.hasOwnProperty(delta.property);
const newValueIsPureObject = isPureObject(delta.newValue);
const oldValueIsPureObject = isPureObject(delta.oldValue);
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/typePredicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function isModelDelta<Model>(delta: CoreDelta<Model>): delta is ModelDelt
return (delta as ModelDelta<Model>).model !== undefined && (delta as PropertyDelta<Model>).property === undefined;
}

export function isPureObject(obj: any): obj is Object {
export function isPureObject(obj: any): obj is Record<string, unknown> {
return obj !== null && typeof obj === "object" && obj?.constructor === Object;
}

Expand Down
4 changes: 4 additions & 0 deletions src/entries/pageSdkInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ function onesignalSdkInit() {
// TODO: We might be able to remove this down the line but reasons to keep for now:
// * Number of internal SDK code expects window.OneSignal
// * Keep JS console usage easier for debugging / testing.
// eslint-disable-next-line @typescript-eslint/no-var-requires
(<any>window).OneSignal = require('../onesignal/OneSignal').default;

// TODO: Could we do an import as a different name then assign it instead?
// We need to use "require" here has as import would clobber OneSignalDeferred and we
const existingOneSignalDeferred = (<any>window).OneSignalDeferred;
// eslint-disable-next-line @typescript-eslint/no-var-requires
(<any>window).OneSignalDeferred = require('../onesignal/OneSignalDeferred').default;
ReplayCallsOnOneSignal.processOneSignalDeferredArray(existingOneSignalDeferred);
}
Expand Down
10 changes: 5 additions & 5 deletions src/page/bell/ActiveAnimatedElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export default class ActiveAnimatedElement extends AnimatedElement {
if (this.targetTransitionEvents.length == 0) {
return resolve(this);
} else {
var timerId = setTimeout(() => {
const timerId = setTimeout(() => {
Log.debug(`Element did not completely activate (state: ${this.state}, activeState: ${this.activeState}).`);
}, this.transitionCheckTimeout);
once(this.element, 'transitionend', (event: Event, destroyListenerFn: Function) => {
once(this.element, 'transitionend', (event: Event, destroyListenerFn: () => void) => {
if (event.target === this.element &&
contains(this.targetTransitionEvents, (event as any).propertyName)) {
clearTimeout(timerId);
Expand Down Expand Up @@ -99,15 +99,15 @@ export default class ActiveAnimatedElement extends AnimatedElement {
if (this.inactiveClass)
addCssClass(element, this.inactiveClass);
}

if (this.shown) {
if (this.targetTransitionEvents.length == 0) {
return resolve(this);
} else {
var timerId = setTimeout(() => {
const timerId = setTimeout(() => {
Log.debug(`Element did not completely inactivate (state: ${this.state}, activeState: ${this.activeState}).`);
}, this.transitionCheckTimeout);
once(this.element, 'transitionend', (event: Event, destroyListenerFn: Function) => {
once(this.element, 'transitionend', (event: Event, destroyListenerFn: () => void) => {
if (event.target === this.element &&
contains(this.targetTransitionEvents, (event as any).propertyName)) {
clearTimeout(timerId);
Expand Down
8 changes: 4 additions & 4 deletions src/page/bell/AnimatedElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export default class AnimatedElement {
if (this.targetTransitionEvents.length == 0) {
return resolve(this);
} else {
var timerId = setTimeout(() => {
const timerId = setTimeout(() => {
Log.debug(`Element did not completely show (state: ${this.state}).`);
}, this.transitionCheckTimeout);
once(this.element, 'transitionend', (event: Event, destroyListenerFn: Function) => {
once(this.element, 'transitionend', (event: Event, destroyListenerFn: () => void) => {
if (event.target === this.element &&
contains(this.targetTransitionEvents, (event as any).propertyName)) {
clearTimeout(timerId);
Expand Down Expand Up @@ -89,8 +89,8 @@ export default class AnimatedElement {
if (this.targetTransitionEvents.length == 0) {
return resolve(this);
} else {
once(this.element, 'transitionend', (event: Event, destroyListenerFn: Function) => {
var timerId = setTimeout(() => {
once(this.element, 'transitionend', (event: Event, destroyListenerFn: () => void) => {
const timerId = setTimeout(() => {
Log.debug(`Element did not completely hide (state: ${this.state}).`);
}, this.transitionCheckTimeout);
if (event.target === this.element &&
Expand Down
26 changes: 13 additions & 13 deletions src/page/bell/Bell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ type BellState = 'uninitialized' | 'subscribed' | 'unsubscribed' | 'blocked';
export default class Bell {
public options: AppUserConfigNotifyButton;
public state: BellState = Bell.STATES.UNINITIALIZED;
public _ignoreSubscriptionState: boolean = false;
public hovering: boolean = false;
public initialized: boolean = false;
public _ignoreSubscriptionState = false;
public hovering = false;
public initialized = false;
public _launcher: Launcher | undefined;
public _button: any;
public _badge: any;
Expand All @@ -37,7 +37,7 @@ export default class Bell {

private DEFAULT_SIZE: BellSize = "medium";
private DEFAULT_POSITION: BellPosition = "bottom-right";
private DEFAULT_THEME: string = "default";
private DEFAULT_THEME = "default";

static get EVENTS() {
return {
Expand Down Expand Up @@ -105,17 +105,17 @@ export default class Bell {
if (!this.dialog.shown) {
this.dialog.show()
.then(() => {
once(document, 'click', (e: Event, destroyEventListener: Function) => {
once(document, 'click', (e: Event, destroyEventListener: () => void) => {
const wasDialogClicked = this.dialog.element.contains(e.target);
if (wasDialogClicked) {
} else {
destroyEventListener();
if (this.dialog.shown) {
this.dialog.hide()
.then(() => {
this.launcher.inactivateIfWasInactive();
});
}
return;
}
destroyEventListener();
if (this.dialog.shown) {
this.dialog.hide()
.then(() => {
this.launcher.inactivateIfWasInactive();
});
}
}, true);
});
Expand Down
2 changes: 1 addition & 1 deletion src/page/bell/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class Button extends ActiveAnimatedElement {
return;
}

var optedOut = LimitStore.getLast('subscription.optedOut');
const optedOut = LimitStore.getLast('subscription.optedOut');
if (this.bell.unsubscribed) {
if (optedOut) {
// The user is manually opted out, but still "really" subscribed
Expand Down
2 changes: 1 addition & 1 deletion src/page/bell/Dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class Dialog extends AnimatedElement {
}
let contents = 'Nothing to show.';

var footer = '';
let footer = '';
if (this.bell.options.showCredit) {
footer = `<div class="divider"></div><div class="kickback">Powered by <a href="https://onesignal.com" class="kickback" target="_blank">OneSignal</a></div>`;
}
Expand Down
4 changes: 2 additions & 2 deletions src/page/bell/Launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export default class Launcher extends ActiveAnimatedElement {
if (this.targetTransitionEvents.length == 0) {
return resolve(this);
} else {
var timerId = setTimeout(() => {
const timerId = setTimeout(() => {
Log.debug(`Launcher did not completely resize (state: ${this.state}, activeState: ${this.activeState}).`);
}, this.transitionCheckTimeout);
once(this.element, 'transitionend', (event: Event, destroyListenerFn: Function) => {
once(this.element, 'transitionend', (event: Event, destroyListenerFn: () => void) => {
if (event.target === this.element &&
contains(this.targetTransitionEvents, (event as any).propertyName)) {
clearTimeout(timerId);
Expand Down
1 change: 1 addition & 0 deletions src/page/helpers/AuthHashOptionsValidatorHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class AuthHashOptionsValidatorHelper {
return undefined;
}

// eslint-disable-next-line no-prototype-builtins
const validKeys = keys.filter(key => options.hasOwnProperty(key));
if (validKeys.length > 1) {
Log.error("More than one key provided, please only provide one!", validKeys);
Expand Down
12 changes: 4 additions & 8 deletions src/page/managers/AltOriginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { EnvironmentKind } from '../../shared/models/EnvironmentKind';

export default class AltOriginManager {

constructor() {

}

/*
* This loads all possible iframes that a site could be subscribed to
* (os.tc & onesignal.com) then checks to see we are subscribed to any.
Expand Down Expand Up @@ -82,7 +78,7 @@ export default class AltOriginManager {

/**
* Only used for sites using a OneSignal subdomain (AKA HTTP setup).
*
*
* Returns the array of possible URL in which the push subscription and
* IndexedDb site data will be stored.
*
Expand All @@ -94,7 +90,7 @@ export default class AltOriginManager {
* subdomain.os.tc, we have to load both in certain scenarios to determine
* which the user is subscribed to; hence, this method returns an array of
* possible URLs.
*
*
* Order of URL is in priority order of one should be used.
*/
static getCanonicalSubscriptionUrls(config: AppConfig,
Expand Down Expand Up @@ -125,8 +121,8 @@ export default class AltOriginManager {
static getWildcardLegacySubscriptionDomain(buildEnv: EnvironmentKind): string {
const apiUrl = SdkEnvironment.getOneSignalApiUrl(buildEnv);

// Prod and Dev support domains like *.onesignal.com and *.localhost
let envSubdomainParts: number = 2;
// Prod and Dev support domains like *.onesignal.com and *.localhost
let envSubdomainParts = 2;
if (buildEnv === EnvironmentKind.Staging) {
// Allow up to 3 parts so *.staging.onesignal.com works.
envSubdomainParts = 3;
Expand Down
2 changes: 2 additions & 0 deletions src/page/managers/LegacyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export default class LegacyManager {

static postmams(oneSignal) {
const postmamMessageFunc = function message(this: any) {
// eslint-disable-next-line prefer-spread, prefer-rest-params
this.messenger.message.apply(this.messenger, arguments);
};

const postmamPostMessageFunc = function postMessage(this: any) {
// eslint-disable-next-line prefer-spread, prefer-rest-params
this.messenger.postMessage.apply(this.messenger, arguments);
};

Expand Down
6 changes: 4 additions & 2 deletions src/page/managers/PromptsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,20 @@ export class PromptsManager {
}

switch (type) {
case DelayedPromptType.Native:
case DelayedPromptType.Native: {
const nativePromptOptions = promptOptions.native;
return {
enabled: nativePromptOptions?.enabled,
autoPrompt: nativePromptOptions?.autoPrompt,
timeDelay: nativePromptOptions?.timeDelay,
pageViews: nativePromptOptions?.pageViews
};
}
case DelayedPromptType.Push:
case DelayedPromptType.Category:
case DelayedPromptType.Email:
case DelayedPromptType.Sms:
case DelayedPromptType.SmsAndEmail:
case DelayedPromptType.SmsAndEmail: {
const { userConfig } = this.context.appConfig;
const options = PromptsHelper
.getFirstSlidedownPromptOptionsWithType(userConfig.promptOptions?.slidedown?.prompts || [], type);
Expand All @@ -307,6 +308,7 @@ export class PromptsManager {
timeDelay: options?.delay?.timeDelay,
pageViews: options?.delay?.pageViews
};
}
default:
return defaultOptions;
}
Expand Down
2 changes: 1 addition & 1 deletion src/page/managers/slidedownManager/SlidedownManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class SlidedownManager {

const slidedownType = options.slidedownPromptOptions?.type;

let isSlidedownPushDependent: boolean = false;
let isSlidedownPushDependent = false;

if (!!slidedownType) {
isSlidedownPushDependent = PromptsHelper.isSlidedownPushDependent(slidedownType);
Expand Down
2 changes: 1 addition & 1 deletion src/page/models/MessengerMessageEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export interface MessengerMessageEvent {
command: string;
data: any;
source: string;
reply: Function;
reply: (param: unknown) => void;
}
5 changes: 3 additions & 2 deletions src/page/modules/frames/ProxyFrameHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default class ProxyFrameHost implements Disposable {
// Promise to track whether the frame has finished loading
private loadPromise: {
promise: Promise<void>,
resolver: Function,
rejector: Function
resolver: (value?: unknown) => void,
rejector: (reason?: unknown) => void
};

/**
Expand Down Expand Up @@ -216,6 +216,7 @@ export default class ProxyFrameHost implements Disposable {
* Shortcut method to messenger.message().
*/
message(..._) {
// eslint-disable-next-line prefer-spread, prefer-rest-params
this.messenger.message.apply(this.messenger, arguments);
}
}
Loading

0 comments on commit 92e5d2a

Please sign in to comment.