From f25bccb80cdfe2427857578565d896295986f655 Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 20 Jul 2018 16:26:39 +0300 Subject: [PATCH] Add no-floating-promises options to tslint in order to ensure all promises are properly handled --- lib/helpers/livesync-command-helper.ts | 2 +- lib/nativescript-cli.ts | 2 ++ lib/services/analytics/analytics-service.ts | 2 +- lib/services/android-project-service.ts | 4 +--- lib/services/ios-project-service.ts | 5 +---- lib/services/livesync/livesync-service.ts | 2 ++ lib/services/plugins-service.ts | 6 +++--- test/services/ios-log-parser-service.ts | 10 +++++----- tslint.json | 1 + 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/helpers/livesync-command-helper.ts b/lib/helpers/livesync-command-helper.ts index 3be1c0bfa0..a0a971fa49 100644 --- a/lib/helpers/livesync-command-helper.ts +++ b/lib/helpers/livesync-command-helper.ts @@ -162,7 +162,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper { await this.$platformService.deployPlatform(deployPlatformInfo); await this.$platformService.startApplication(currentPlatform, runPlatformOptions, { appId: this.$projectData.projectId, projectName: this.$projectData.projectName }); - this.$platformService.trackProjectType(this.$projectData); + await this.$platformService.trackProjectType(this.$projectData); } } } diff --git a/lib/nativescript-cli.ts b/lib/nativescript-cli.ts index d38c172ad2..bbac0422f8 100644 --- a/lib/nativescript-cli.ts +++ b/lib/nativescript-cli.ts @@ -8,6 +8,7 @@ installUncaughtExceptionListener(process.exit.bind(process, ErrorCodes.UNCAUGHT) import { settlePromises } from "./common/helpers"; +/* tslint:disable:no-floating-promises */ (async () => { const config: Config.IConfig = $injector.resolve("$config"); const err: IErrors = $injector.resolve("$errors"); @@ -42,3 +43,4 @@ import { settlePromises } from "./common/helpers"; $injector.dispose(); })(); +/* tslint:enable:no-floating-promises */ diff --git a/lib/services/analytics/analytics-service.ts b/lib/services/analytics/analytics-service.ts index b3d02505a7..ecce5da08e 100644 --- a/lib/services/analytics/analytics-service.ts +++ b/lib/services/analytics/analytics-service.ts @@ -44,7 +44,7 @@ export class AnalyticsService extends AnalyticsServiceBase { } public async trackAcceptFeatureUsage(settings: { acceptTrackFeatureUsage: boolean }): Promise { - this.sendMessageToBroker({ + await this.sendMessageToBroker({ type: TrackingTypes.AcceptTrackFeatureUsage, acceptTrackFeatureUsage: settings.acceptTrackFeatureUsage }); diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index 6a71bdfb8b..66a0222140 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -126,9 +126,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject this.$androidToolsInfo.validateTargetSdk({ showWarningsAsErrors: true }); } - public async validatePlugins(): Promise { - Promise.resolve(); - } + public async validatePlugins(): Promise { /* */ } public async createProject(frameworkDir: string, frameworkVersion: string, projectData: IProjectData, config: ICreateProjectOptions): Promise { if (semver.lt(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) { diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index d48ffa805c..b6b9d429fd 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -380,7 +380,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ this.$errors.failWithoutHelp(`${pluginData.name} has Podfile and you don't have Cocoapods installed or it is not configured correctly. Please verify Cocoapods can work on your machine.`); } } - Promise.resolve(); } private async buildForDevice(projectRoot: string, args: string[], buildConfig: IBuildConfig, projectData: IProjectData): Promise { @@ -1032,9 +1031,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f } } - public async prebuildNativePlugin(options: IBuildOptions): Promise { - Promise.resolve(); - } + public async prebuildNativePlugin(options: IBuildOptions): Promise { /** */ } public async checkIfPluginsNeedBuild(projectData: IProjectData): Promise> { return []; diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index b7916eb699..889d9e20d6 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -685,7 +685,9 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi this.$processService.attachToProcessExitSignals(this, () => { _.keys(this.liveSyncProcessesInfo).forEach(projectDir => { // Do not await here, we are in process exit's handler. + /* tslint:disable:no-floating-promises */ this.stopLiveSync(projectDir); + /* tslint:enable:no-floating-promises */ }); }); } diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index 01220cec8f..68cd5d7c5f 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -58,7 +58,7 @@ export class PluginsService implements IPluginsService { this.isPluginDataValidForPlatform(pluginData, platform, projectData); }; - this.executeForAllInstalledPlatforms(action, projectData); + await this.executeForAllInstalledPlatforms(action, projectData); try { await this.$pluginVariablesService.savePluginVariablesInProjectFile(pluginData, projectData); @@ -85,7 +85,7 @@ export class PluginsService implements IPluginsService { }; this.$pluginVariablesService.removePluginVariablesFromProjectFile(pluginName.toLowerCase(), projectData); - this.executeForAllInstalledPlatforms(removePluginNativeCodeAction, projectData); + await this.executeForAllInstalledPlatforms(removePluginNativeCodeAction, projectData); await this.executeNpmCommand(PluginsService.UNINSTALL_COMMAND_NAME, pluginName, projectData); @@ -97,7 +97,7 @@ export class PluginsService implements IPluginsService { showMessage = false; }; - this.executeForAllInstalledPlatforms(action, projectData); + await this.executeForAllInstalledPlatforms(action, projectData); if (showMessage) { this.$logger.out(`Successfully removed plugin ${pluginName}`); diff --git a/test/services/ios-log-parser-service.ts b/test/services/ios-log-parser-service.ts index df124a8bc8..326ad5ae9a 100644 --- a/test/services/ios-log-parser-service.ts +++ b/test/services/ios-log-parser-service.ts @@ -88,7 +88,7 @@ describe("iOSLogParserService", () => { const emittedMessagesCount = 1; const promise = attachOnDebuggerFoundEvent(emittedMessagesCount); - iOSLogParserService.startParsingLog(device, mockProjectNameObj); + await iOSLogParserService.startParsingLog(device, mockProjectNameObj); emitDeviceLog("test message"); emitDeviceLog(getDebuggerPortMessage(18181)); @@ -101,7 +101,7 @@ describe("iOSLogParserService", () => { const emittedMessagesCount = 5; const promise = attachOnDebuggerFoundEvent(emittedMessagesCount); - iOSLogParserService.startParsingLog(device, mockProjectNameObj); + await iOSLogParserService.startParsingLog(device, mockProjectNameObj); emitDeviceLog(getDebuggerPortMessage(18181)); emitDeviceLog(getDebuggerPortMessage(18181)); emitDeviceLog(getDebuggerPortMessage(18181)); @@ -121,7 +121,7 @@ describe("iOSLogParserService", () => { const emittedMessagesCount = 5; const promise = attachOnDebuggerFoundEvent(emittedMessagesCount); - iOSLogParserService.startParsingLog(device, mockProjectNameObj); + await iOSLogParserService.startParsingLog(device, mockProjectNameObj); emitDeviceLog(getDebuggerPortMessage(45898)); emitDeviceLog(getDebuggerPortMessage(1809)); emitDeviceLog(getDebuggerPortMessage(65072)); @@ -137,12 +137,12 @@ describe("iOSLogParserService", () => { assert.deepEqual(data[3], { port: 12345, deviceId: deviceId, appId: appId }); assert.deepEqual(data[4], { port: 18181, deviceId: deviceId, appId: appId }); }); - it(`should not receive ${DEBUGGER_PORT_FOUND_EVENT_NAME} event when debugger port message is not emitted`, () => { + it(`should not receive ${DEBUGGER_PORT_FOUND_EVENT_NAME} event when debugger port message is not emitted`, async () => { let isDebuggedPortFound = false; iOSLogParserService.on(DEBUGGER_PORT_FOUND_EVENT_NAME, (data: IIOSDebuggerPortData) => isDebuggedPortFound = true); - iOSLogParserService.startParsingLog(device, mockProjectNameObj); + await iOSLogParserService.startParsingLog(device, mockProjectNameObj); emitDeviceLog("some test message"); emitDeviceLog("another test message"); diff --git a/tslint.json b/tslint.json index 908fdf9f32..58b40a119b 100644 --- a/tslint.json +++ b/tslint.json @@ -35,6 +35,7 @@ "check-open-brace", "check-whitespace" ], + "no-floating-promises": true, "quotemark": [ false, "double"