Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lint): part 1 of reenabling no-floating-promises #3600

Merged
merged 8 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/DetailsView/details-view-initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ import { AssessmentInstanceTableHandler } from './handlers/assessment-instance-t
import { DetailsViewToggleClickHandlerFactory } from './handlers/details-view-toggle-click-handler-factory';
import { MasterCheckBoxConfigProvider } from './handlers/master-checkbox-config-provider';
import { PreviewFeatureFlagsHandler } from './handlers/preview-feature-flags-handler';
import { Logger } from 'common/logging/logger';

declare const window: AutoChecker & Window;

Expand Down Expand Up @@ -486,7 +487,11 @@ if (tabId != null) {
window.A11YSelfValidator = a11ySelfValidator;
},
() => {
const renderer = createNullifiedRenderer(document, ReactDOM.render);
const renderer = createNullifiedRenderer(
document,
ReactDOM.render,
createDefaultLogger(),
);
renderer.render();
},
);
Expand All @@ -495,9 +500,10 @@ if (tabId != null) {
function createNullifiedRenderer(
doc: Document,
render: typeof ReactDOM.render,
logger: Logger,
): NoContentAvailableViewRenderer {
// using an instance of an actual store (instead of a StoreProxy) so we can get the default state.
const store = new UserConfigurationStore(null, new UserConfigurationActions(), null);
const store = new UserConfigurationStore(null, new UserConfigurationActions(), null, logger);
const storesHub = new BaseClientStoresHub<ThemeInnerState>([store]);

const deps: NoContentAvailableViewDeps = {
Expand Down
4 changes: 4 additions & 0 deletions src/background/background-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ConsoleTelemetryClient } from 'background/telemetry/console-telemetry-c
import { DebugToolsTelemetryClient } from 'background/telemetry/debug-tools-telemetry-client';
import { createToolData } from 'common/application-properties-provider';
import { BrowserAdapterFactory } from 'common/browser-adapters/browser-adapter-factory';
import { WindowUtils } from 'common/window-utils';
import { UAParser } from 'ua-parser-js';
import { AxeInfo } from '../common/axe-info';
import { VisualizationConfigurationFactory } from '../common/configs/visualization-configuration-factory';
Expand Down Expand Up @@ -57,6 +58,8 @@ async function initialize(): Promise<void> {
deprecatedStorageDataKeys,
);

const windowUtils = new WindowUtils();

const urlValidator = new UrlValidator(browserAdapter);
const indexedDBInstance: IndexedDBAPI = new IndexedDBUtil(getIndexedDBStore());
const indexedDBDataKeysToFetch = [
Expand Down Expand Up @@ -186,6 +189,7 @@ async function initialize(): Promise<void> {
promiseFactory,
logger,
usageLogger,
windowUtils,
);

const targetPageController = new TargetPageController(
Expand Down
1 change: 1 addition & 0 deletions src/background/global-context-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class GlobalContextFactory {
indexedDBInstance,
persistedData,
storageAdapter,
logger,
);

const featureFlagsController = new FeatureFlagsController(
Expand Down
45 changes: 18 additions & 27 deletions src/background/injector-controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { InspectMode } from 'background/inspect-modes';
import { Logger } from 'common/logging/logger';
import { Messages } from '../common/messages';
import { WindowUtils } from '../common/window-utils';
import { ContentScriptInjector } from './injector/content-script-injector';
Expand All @@ -10,31 +11,19 @@ import { TabStore } from './stores/tab-store';
import { VisualizationStore } from './stores/visualization-store';

export class InjectorController {
private injector: ContentScriptInjector;
private visualizationStore: VisualizationStore;
private inspectStore: InspectStore;
private interpreter: Interpreter;
private tabStore: TabStore;
private windowUtils: WindowUtils;
private static readonly injectionStartedWaitTime = 10;

private oldInspectType = InspectMode.off;

constructor(
injector: ContentScriptInjector,
visualizationStore: VisualizationStore,
interpreter: Interpreter,
tabStore: TabStore,
inspectStore: InspectStore,
windowUtils?: WindowUtils,
) {
this.injector = injector;
this.visualizationStore = visualizationStore;
this.tabStore = tabStore;
this.inspectStore = inspectStore;
this.interpreter = interpreter;
this.windowUtils = windowUtils || new WindowUtils();
}
private readonly injector: ContentScriptInjector,
private readonly visualizationStore: VisualizationStore,
private readonly interpreter: Interpreter,
private readonly tabStore: TabStore,
private readonly inspectStore: InspectStore,
private readonly windowUtils: WindowUtils,
private readonly logger: Logger,
) {}

public initialize(): void {
this.visualizationStore.addChangedListener(this.inject);
Expand All @@ -59,13 +48,15 @@ export class InjectorController {
});
}, InjectorController.injectionStartedWaitTime);

// tslint:disable-next-line:no-floating-promises - grandfathered
this.injector.injectScripts(tabId).then(() => {
this.interpreter.interpret({
messageType: Messages.Visualizations.State.InjectionCompleted,
tabId: tabId,
});
});
this.injector
.injectScripts(tabId)
.then(() => {
this.interpreter.interpret({
messageType: Messages.Visualizations.State.InjectionCompleted,
tabId: tabId,
});
})
.catch(this.logger.error);
}

this.oldInspectType = inspectStoreState.inspectMode;
Expand Down
35 changes: 10 additions & 25 deletions src/background/stores/assessment-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AssessmentsProvider } from 'assessments/types/assessments-provider';
import { IndexedDBDataKeys } from 'background/IndexedDBDataKeys';
import { BrowserAdapter } from 'common/browser-adapters/browser-adapter';
import { IndexedDBAPI } from 'common/indexedDB/indexedDB';
import { Logger } from 'common/logging/logger';
import { StoreNames } from 'common/stores/store-names';
import { DetailsViewPivotType } from 'common/types/details-view-pivot-type';
import { ManualTestStatus } from 'common/types/manual-test-status';
Expand Down Expand Up @@ -46,33 +47,18 @@ import { AssessmentDataRemover } from './../assessment-data-remover';
import { BaseStoreImpl } from './base-store-impl';

export class AssessmentStore extends BaseStoreImpl<AssessmentStoreData> {
private assessmentActions: AssessmentActions;
private assessmentDataConverter: AssessmentDataConverter;
private assessmentDataRemover: AssessmentDataRemover;
private assessmentsProvider: AssessmentsProvider;
private idbInstance: IndexedDBAPI;
private browserAdapter: BrowserAdapter;
private persistedData: AssessmentStoreData;

constructor(
browserAdapter: BrowserAdapter,
assessmentActions: AssessmentActions,
assessmentDataConverter: AssessmentDataConverter,
assessmentDataRemover: AssessmentDataRemover,
assessmentsProvider: AssessmentsProvider,
idbInstance: IndexedDBAPI,
persistedData: AssessmentStoreData,
private readonly browserAdapter: BrowserAdapter,
private readonly assessmentActions: AssessmentActions,
private readonly assessmentDataConverter: AssessmentDataConverter,
private readonly assessmentDataRemover: AssessmentDataRemover,
private readonly assessmentsProvider: AssessmentsProvider,
private readonly idbInstance: IndexedDBAPI,
private readonly persistedData: AssessmentStoreData,
private readonly initialAssessmentStoreDataGenerator: InitialAssessmentStoreDataGenerator,
private readonly logger: Logger,
) {
super(StoreNames.AssessmentStore);

this.browserAdapter = browserAdapter;
this.assessmentActions = assessmentActions;
this.assessmentDataConverter = assessmentDataConverter;
this.assessmentsProvider = assessmentsProvider;
this.assessmentDataRemover = assessmentDataRemover;
this.idbInstance = idbInstance;
this.persistedData = persistedData;
}

public generateDefaultState(persistedData: AssessmentStoreData = null): AssessmentStoreData {
Expand All @@ -99,8 +85,7 @@ export class AssessmentStore extends BaseStoreImpl<AssessmentStoreData> {
protected emitChanged(): void {
const assessmentStoreData = this.getState();

// tslint:disable-next-line:no-floating-promises - grandfathered-in pre-existing violation
this.persistAssessmentData(assessmentStoreData);
this.persistAssessmentData(assessmentStoreData).catch(this.logger.error);

super.emitChanged();
}
Expand Down
4 changes: 4 additions & 0 deletions src/background/stores/global/global-store-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { PermissionsStateStore } from 'background/stores/global/permissions-state-store';
import { FeatureFlagDefaultsHelper } from 'common/feature-flag-defaults-helper';
import { getAllFeatureFlagDetails } from 'common/feature-flags';
import { Logger } from 'common/logging/logger';
import { BaseStore } from '../../../common/base-store';
import { BrowserAdapter } from '../../../common/browser-adapters/browser-adapter';
import { StorageAdapter } from '../../../common/browser-adapters/storage-adapter';
Expand Down Expand Up @@ -43,6 +44,7 @@ export class GlobalStoreHub implements StoreHub {
indexedDbInstance: IndexedDBAPI,
persistedData: PersistedData,
storageAdapter: StorageAdapter,
logger: Logger,
) {
this.commandStore = new CommandStore(globalActionHub.commandActions, telemetryEventHandler);
this.featureFlagStore = new FeatureFlagStore(
Expand All @@ -66,11 +68,13 @@ export class GlobalStoreHub implements StoreHub {
indexedDbInstance,
persistedData.assessmentStoreData,
new InitialAssessmentStoreDataGenerator(assessmentsProvider.all()),
logger,
);
this.userConfigurationStore = new UserConfigurationStore(
persistedData.userConfigurationData,
globalActionHub.userConfigurationActions,
indexedDbInstance,
logger,
);
this.permissionsStateStore = new PermissionsStateStore(
globalActionHub.permissionsStateActions,
Expand Down
8 changes: 6 additions & 2 deletions src/background/stores/global/user-configuration-store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Logger } from 'common/logging/logger';
import { cloneDeep, isPlainObject } from 'lodash';
import { IndexedDBAPI } from '../../../common/indexedDB/indexedDB';
import { StoreNames } from '../../../common/stores/store-names';
Expand Down Expand Up @@ -33,6 +34,7 @@ export class UserConfigurationStore extends BaseStoreImpl<UserConfigurationStore
private readonly persistedState: UserConfigurationStoreData,
private readonly userConfigActions: UserConfigurationActions,
private readonly indexDbApi: IndexedDBAPI,
private readonly logger: Logger,
) {
super(StoreNames.UserConfigurationStore);
}
Expand Down Expand Up @@ -133,8 +135,10 @@ export class UserConfigurationStore extends BaseStoreImpl<UserConfigurationStore
};

private saveAndEmitChanged(): void {
// tslint:disable-next-line:no-floating-promises - grandfathered-in pre-existing violation
this.indexDbApi.setItem(IndexedDBDataKeys.userConfiguration, this.state);
this.indexDbApi
.setItem(IndexedDBDataKeys.userConfiguration, this.state)
.catch(this.logger.error);

this.emitChanged();
}
}
4 changes: 4 additions & 0 deletions src/background/tab-context-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Logger } from 'common/logging/logger';
import { NotificationCreator } from 'common/notification-creator';
import { PromiseFactory } from 'common/promises/promise-factory';
import { StateDispatcher } from 'common/state-dispatcher';
import { WindowUtils } from 'common/window-utils';
import { ActionCreator } from './actions/action-creator';
import { ActionHub } from './actions/action-hub';
import { CardSelectionActionCreator } from './actions/card-selection-action-creator';
Expand Down Expand Up @@ -39,6 +40,7 @@ export class TabContextFactory {
private readonly promiseFactory: PromiseFactory,
private readonly logger: Logger,
private readonly usageLogger: UsageLogger,
private readonly windowUtils: WindowUtils,
) {}

public createTabContext(
Expand Down Expand Up @@ -139,6 +141,8 @@ export class TabContextFactory {
interpreter,
storeHub.tabStore,
storeHub.inspectStore,
this.windowUtils,
this.logger,
);

shortcutsPageActionCreator.registerCallbacks();
Expand Down
14 changes: 7 additions & 7 deletions src/electron/views/renderer-initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,11 @@ const indexedDBDataKeysToFetch = [
IndexedDBDataKeys.unifiedFeatureFlags,
];

// tslint:disable-next-line:no-floating-promises - top-level entry points are intentionally floating promises
getPersistedData(indexedDBInstance, indexedDBDataKeysToFetch).then(
(persistedData: Partial<PersistedData>) => {
const installationData: InstallationData = persistedData.installationData;
const logger = createDefaultLogger();

const logger = createDefaultLogger();
getPersistedData(indexedDBInstance, indexedDBDataKeysToFetch)
.then((persistedData: Partial<PersistedData>) => {
const installationData: InstallationData = persistedData.installationData;

const applicationTelemetryDataFactory = getApplicationTelemetryDataFactory(
installationData,
Expand All @@ -203,6 +202,7 @@ getPersistedData(indexedDBInstance, indexedDBDataKeysToFetch).then(
persistedData.userConfigurationData,
userConfigActions,
indexedDBInstance,
logger,
);
userConfigurationStore.initialize();

Expand Down Expand Up @@ -561,5 +561,5 @@ getPersistedData(indexedDBInstance, indexedDBDataKeysToFetch).then(
sendAppInitializedTelemetryEvent(telemetryEventHandler, platformInfo);

ipcRendererShim.initializeWindow();
},
);
})
.catch(logger.error);
Loading