Skip to content

Commit 8146e01

Browse files
hensomphilwocoeuvre
authored
Fix "no-floating-promises" violations (#228)
* Fix "no-floating-promises" violations This change adds support for the "no-floating-promises" lint check. Adding this check required the commandline tslint to explicitly specify the project, which is required to enable type checking. Without this change, simply adding the lint check would result in the following warning: - Warning: The 'no-floating-promises' rule requires type information. I also fixed all existing violations in the codebase. * Fix other "no-floating-promises" violations Co-authored-by: Philipp Wollermann <philwo@google.com> Co-authored-by: Chi Wang <chiwang@google.com>
1 parent c917029 commit 8146e01

File tree

6 files changed

+22
-16
lines changed

6 files changed

+22
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@
357357
}
358358
},
359359
"scripts": {
360-
"check-lint": "tslint -t stylish 'src/**/*.ts' --exclude 'src/**/*.d.ts'",
360+
"check-lint": "tslint --project tsconfig.json -t stylish 'src/**/*.ts' --exclude 'src/**/*.d.ts'",
361361
"compile": "./scripts/build.sh",
362362
"vscode:prepublish": "./scripts/build.sh",
363363
"watch": "./scripts/build.sh -watch"

src/buildifier/buildifier_availability.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function checkBuildifierIsAvailable() {
5454
}
5555
}
5656
// If we didn't get valid JSON back, we don't have a compatible version.
57+
// tslint:disable-next-line:no-floating-promises
5758
showBuildifierDownloadPrompt(
5859
"Buildifier is too old (0.25.1 or higher is needed)",
5960
);

src/buildifier/buildifier_diagnostics_manager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class BuildifierDiagnosticsManager implements vscode.Disposable {
4646
clearTimeout(didChangeTextTimer);
4747
}
4848
didChangeTextTimer = setTimeout(() => {
49+
// tslint:disable-next-line:no-floating-promises
4950
this.updateDiagnostics(e.document);
5051
didChangeTextTimer = null;
5152
}, DIAGNOSTICS_ON_TYPE_DELAY_MILLIS);
@@ -55,12 +56,14 @@ export class BuildifierDiagnosticsManager implements vscode.Disposable {
5556
if (!e) {
5657
return;
5758
}
59+
// tslint:disable-next-line:no-floating-promises
5860
this.updateDiagnostics(e.document);
5961
});
6062

6163
// If there is an active window at the time the manager is created, make
6264
// sure its diagnostics are computed.
6365
if (vscode.window.activeTextEditor) {
66+
// tslint:disable-next-line:no-floating-promises
6467
this.updateDiagnostics(vscode.window.activeTextEditor.document);
6568
}
6669
}

src/debug-adapter/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class BazelDebugSession extends DebugSession {
265265
setBreakpoints: skylark_debugging.SetBreakpointsRequest.create({
266266
breakpoint: bazelBreakpoints,
267267
}),
268-
});
268+
}).catch((err) => this.debugLog("Error setting breakpoint: " + err));
269269
this.sendResponse(response);
270270
}
271271

@@ -485,7 +485,7 @@ class BazelDebugSession extends DebugSession {
485485
stepping,
486486
threadId,
487487
}),
488-
});
488+
}).catch((err) => this.debugLog("Error continuing execution: " + err));
489489
}
490490

491491
/**

src/extension/extension.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export function activate(context: vscode.ExtensionContext) {
5050
const buildifierDiagnostics = new BuildifierDiagnosticsManager();
5151
const completionItemProvider = new BazelCompletionItemProvider();
5252

53+
// tslint:disable-next-line:no-floating-promises
5354
completionItemProvider.refresh();
5455

5556
context.subscriptions.push(
@@ -82,6 +83,7 @@ export function activate(context: vscode.ExtensionContext) {
8283
),
8384
vscode.commands.registerCommand("bazel.clean", bazelClean),
8485
vscode.commands.registerCommand("bazel.refreshBazelBuildTargets", () => {
86+
// tslint:disable-next-line:no-floating-promises
8587
completionItemProvider.refresh();
8688
workspaceTreeProvider.refresh();
8789
}),
@@ -155,7 +157,7 @@ async function bazelBuildTarget(adapter: IBazelCommandAdapter | undefined) {
155157
// If the result was undefined, the user cancelled the quick pick, so don't
156158
// try again.
157159
if (quickPick) {
158-
bazelBuildTarget(quickPick);
160+
await bazelBuildTarget(quickPick);
159161
}
160162
return;
161163
}
@@ -186,13 +188,12 @@ async function bazelBuildTargetWithDebugging(
186188
// If the result was undefined, the user cancelled the quick pick, so don't
187189
// try again.
188190
if (quickPick) {
189-
bazelBuildTargetWithDebugging(quickPick);
191+
await bazelBuildTargetWithDebugging(quickPick);
190192
}
191193
return;
192194
}
193-
const bazelConfigCmdLine = vscode.workspace.getConfiguration(
194-
"bazel.commandLine",
195-
);
195+
const bazelConfigCmdLine =
196+
vscode.workspace.getConfiguration("bazel.commandLine");
196197
const startupOptions = bazelConfigCmdLine.get<string[]>("startupOptions");
197198
const commandArgs = bazelConfigCmdLine.get<string[]>("commandArgs");
198199

@@ -221,7 +222,7 @@ async function bazelBuildTargetWithDebugging(
221222
* which the command's arguments will be determined.
222223
*/
223224
async function bazelbuildAll(adapter: IBazelCommandAdapter | undefined) {
224-
buildPackage(":all", adapter);
225+
await buildPackage(":all", adapter);
225226
}
226227

227228
/**
@@ -233,7 +234,7 @@ async function bazelbuildAll(adapter: IBazelCommandAdapter | undefined) {
233234
async function bazelbuildAllRecursive(
234235
adapter: IBazelCommandAdapter | undefined,
235236
) {
236-
buildPackage("/...", adapter);
237+
await buildPackage("/...", adapter);
237238
}
238239

239240
async function buildPackage(
@@ -253,7 +254,7 @@ async function buildPackage(
253254
// If the result was undefined, the user cancelled the quick pick, so don't
254255
// try again.
255256
if (quickPick) {
256-
buildPackage(suffix, quickPick);
257+
await buildPackage(suffix, quickPick);
257258
}
258259
return;
259260
}
@@ -287,7 +288,7 @@ async function bazelTestTarget(adapter: IBazelCommandAdapter | undefined) {
287288
// If the result was undefined, the user cancelled the quick pick, so don't
288289
// try again.
289290
if (quickPick) {
290-
bazelTestTarget(quickPick);
291+
await bazelTestTarget(quickPick);
291292
}
292293
return;
293294
}
@@ -303,7 +304,7 @@ async function bazelTestTarget(adapter: IBazelCommandAdapter | undefined) {
303304
* which the command's arguments will be determined.
304305
*/
305306
async function bazelTestAll(adapter: IBazelCommandAdapter | undefined) {
306-
testPackage(":all", adapter);
307+
await testPackage(":all", adapter);
307308
}
308309

309310
/**
@@ -315,7 +316,7 @@ async function bazelTestAll(adapter: IBazelCommandAdapter | undefined) {
315316
async function bazelTestAllRecursive(
316317
adapter: IBazelCommandAdapter | undefined,
317318
) {
318-
testPackage("/...", adapter);
319+
await testPackage("/...", adapter);
319320
}
320321

321322
async function testPackage(
@@ -335,7 +336,7 @@ async function testPackage(
335336
// If the result was undefined, the user cancelled the quick pick, so don't
336337
// try again.
337338
if (quickPick) {
338-
testPackage(suffix, quickPick);
339+
await testPackage(suffix, quickPick);
339340
}
340341
return;
341342
}

tslint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"limit": 80,
1212
"ignore-pattern": "^import |^export {(.*?)}"
1313
}
14-
]
14+
],
15+
"no-floating-promises": true
1516
},
1617
"rulesDirectory": []
1718
}

0 commit comments

Comments
 (0)