Skip to content

Commit d6bb81d

Browse files
authored
Enable no-floating-promises lint (#1876)
* Bump eslint to v7.5.0 * Enable no-floating-promise rule * Fix no-floating-promises violations
1 parent 1bb9fe0 commit d6bb81d

File tree

13 files changed

+188
-104
lines changed

13 files changed

+188
-104
lines changed

vscode/.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
}
1818
},
1919
"rules": {
20+
"@typescript-eslint/no-floating-promises": "error",
2021
"consistent-return": "off",
2122
"no-warning-comments": "off",
2223
"no-console": "warn",

vscode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@
514514
"@types/node": "20.x",
515515
"@types/sinon": "^17.0.3",
516516
"@types/vscode": "^1.68.0",
517-
"@typescript-eslint/eslint-plugin": "^5.62.0",
518-
"@typescript-eslint/parser": "^5.62.0",
517+
"@typescript-eslint/eslint-plugin": "^7.5.0",
518+
"@typescript-eslint/parser": "^7.5.0",
519519
"@vscode/test-electron": "^2.3.9",
520520
"@vscode/vsce": "^2.24.0",
521521
"esbuild": "^0.20.2",

vscode/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,15 @@ export default class Client extends LanguageClient implements ClientInterface {
263263
`${benchmarkId}.end`,
264264
);
265265
telemetryData.requestTime = bench.duration;
266-
this.telemetry.sendEvent(telemetryData);
266+
await this.telemetry.sendEvent(telemetryData);
267267

268268
// If there has been an error, we must throw it again. Otherwise we can return the result
269269
if (errorResult) {
270270
if (
271271
this.baseFolder === "ruby-lsp" ||
272272
this.baseFolder === "ruby-lsp-rails"
273273
) {
274-
vscode.window.showErrorMessage(
274+
await vscode.window.showErrorMessage(
275275
`Ruby LSP error ${errorResult.data.errorClass}: ${errorResult.data.errorMessage}\n\n
276276
${errorResult.data.backtrace}`,
277277
);

vscode/src/dependenciesTree.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,25 @@ export class DependenciesTree
8787
}
8888
}
8989

90-
private refresh(): void {
91-
this.fetchDependencies();
90+
private async refresh(): Promise<void> {
91+
await this.fetchDependencies();
9292
this._onDidChangeTreeData.fire(undefined);
9393
}
9494

95-
private workspaceDidChange(workspace: WorkspaceInterface | undefined): void {
95+
private async workspaceDidChange(
96+
workspace: WorkspaceInterface | undefined,
97+
): Promise<void> {
9698
if (!workspace || workspace === this.currentWorkspace) {
9799
return;
98100
}
99101

100102
this.currentWorkspace = workspace;
101-
this.refresh();
103+
return this.refresh();
102104
}
103105

104-
private activeEditorDidChange(editor: vscode.TextEditor | undefined): void {
106+
private async activeEditorDidChange(
107+
editor: vscode.TextEditor | undefined,
108+
): Promise<void> {
105109
const uri = editor?.document.uri;
106110

107111
if (!uri) {
@@ -113,25 +117,25 @@ export class DependenciesTree
113117
this.currentVisibleItem = new GemFilePath(uri);
114118

115119
if (this.treeView.visible) {
116-
this.revealElement(this.currentVisibleItem);
120+
await this.revealElement(this.currentVisibleItem);
117121
}
118122
}
119123

120-
private treeVisibilityDidChange(
124+
private async treeVisibilityDidChange(
121125
event: vscode.TreeViewVisibilityChangeEvent,
122-
): void {
126+
): Promise<void> {
123127
if (this.currentVisibleItem && event.visible) {
124-
this.revealElement(this.currentVisibleItem);
128+
await this.revealElement(this.currentVisibleItem);
125129
}
126130
}
127131

128-
private revealElement(element: BundlerTreeNode): void {
132+
private async revealElement(element: BundlerTreeNode): Promise<void> {
129133
const autoReveal: boolean | undefined = vscode.workspace
130134
.getConfiguration("explorer")
131135
.get("autoReveal");
132136

133137
if (autoReveal) {
134-
this.treeView.reveal(element, {
138+
await this.treeView.reveal(element, {
135139
select: true,
136140
focus: false,
137141
expand: true,

vscode/src/ruby/mise.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,7 @@ import { VersionManager, ActivationResult } from "./versionManager";
1212
// Learn more: https://github.com/jdx/mise
1313
export class Mise extends VersionManager {
1414
async activate(): Promise<ActivationResult> {
15-
const miseUri = vscode.Uri.joinPath(
16-
vscode.Uri.file(os.homedir()),
17-
".local",
18-
"bin",
19-
"mise",
20-
);
21-
22-
try {
23-
vscode.workspace.fs.stat(miseUri);
24-
} catch (error: any) {
25-
throw new Error(
26-
`The Ruby LSP version manager is configured to be Mise, but ${miseUri.fsPath} does not exist`,
27-
);
28-
}
15+
const miseUri = await this.findMiseUri();
2916

3017
const activationScript =
3118
"STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)";
@@ -45,4 +32,23 @@ export class Mise extends VersionManager {
4532
version: parsedResult.version,
4633
};
4734
}
35+
36+
async findMiseUri(): Promise<vscode.Uri> {
37+
const miseUri = vscode.Uri.joinPath(
38+
vscode.Uri.file(os.homedir()),
39+
".local",
40+
"bin",
41+
"mise",
42+
);
43+
44+
try {
45+
await vscode.workspace.fs.stat(miseUri);
46+
} catch (error: any) {
47+
// Couldn't find it
48+
}
49+
50+
throw new Error(
51+
`The Ruby LSP version manager is configured to be Mise, but ${miseUri.fsPath} does not exist`,
52+
);
53+
}
4854
}

vscode/src/ruby/shadowenv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { VersionManager, ActivationResult } from "./versionManager";
1212
export class Shadowenv extends VersionManager {
1313
async activate(): Promise<ActivationResult> {
1414
try {
15-
vscode.workspace.fs.stat(
15+
await vscode.workspace.fs.stat(
1616
vscode.Uri.joinPath(this.bundleUri, ".shadowenv.d"),
1717
);
1818
} catch (error: any) {

vscode/src/rubyLsp.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class RubyLsp {
7979
// Activate the extension. This method should perform all actions necessary to start the extension, such as booting
8080
// all language servers for each existing workspace
8181
async activate() {
82+
await vscode.commands.executeCommand("testing.clearTestResults");
8283
await this.telemetry.sendConfigurationEvents();
8384

8485
const firstWorkspace = vscode.workspace.workspaceFolders?.[0];
@@ -140,15 +141,15 @@ export class RubyLsp {
140141
);
141142

142143
if (answer === "See the multi-root workspace docs") {
143-
vscode.env.openExternal(
144+
await vscode.env.openExternal(
144145
vscode.Uri.parse(
145146
"https://github.com/Shopify/ruby-lsp/blob/main/vscode/README.md?tab=readme-ov-file#multi-root-workspaces",
146147
),
147148
);
148149
}
149150

150151
if (answer === "Don't show again") {
151-
this.context.globalState.update(
152+
await this.context.globalState.update(
152153
"rubyLsp.disableMultirootLockfileWarning",
153154
true,
154155
);
@@ -168,8 +169,12 @@ export class RubyLsp {
168169

169170
// If we successfully activated a workspace, then we can start showing the dependencies tree view. This is necessary
170171
// so that we can avoid showing it on non Ruby projects
171-
vscode.commands.executeCommand("setContext", "rubyLsp.activated", true);
172-
this.showFormatOnSaveModeWarning(workspace);
172+
await vscode.commands.executeCommand(
173+
"setContext",
174+
"rubyLsp.activated",
175+
true,
176+
);
177+
await this.showFormatOnSaveModeWarning(workspace);
173178
}
174179

175180
// Registers all extension commands. Commands can only be registered once, so this happens in the constructor. For
@@ -198,7 +203,7 @@ export class RubyLsp {
198203
this.showSyntaxTree.bind(this),
199204
),
200205
vscode.commands.registerCommand(Command.FormatterHelp, () => {
201-
vscode.env.openExternal(
206+
return vscode.env.openExternal(
202207
vscode.Uri.parse(
203208
"https://github.com/Shopify/ruby-lsp/blob/main/vscode/README.md#formatting",
204209
),
@@ -287,14 +292,19 @@ export class RubyLsp {
287292
});
288293

289294
if (manager !== undefined) {
290-
configuration.update("rubyVersionManager", manager, true, true);
295+
await configuration.update(
296+
"rubyVersionManager",
297+
manager,
298+
true,
299+
true,
300+
);
291301
}
292302
},
293303
),
294304
vscode.commands.registerCommand(
295305
Command.RunTest,
296306
(_path, name, _command) => {
297-
this.testController.runOnClick(name);
307+
return this.testController.runOnClick(name);
298308
},
299309
),
300310
vscode.commands.registerCommand(
@@ -382,7 +392,9 @@ export class RubyLsp {
382392
const document = activeEditor.document;
383393

384394
if (document.languageId !== "ruby") {
385-
vscode.window.showErrorMessage("Show syntax tree: not a Ruby file");
395+
await vscode.window.showErrorMessage(
396+
"Show syntax tree: not a Ruby file",
397+
);
386398
return;
387399
}
388400

vscode/src/telemetry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class Telemetry {
5656

5757
async sendEvent(event: TelemetryEvent) {
5858
if (await this.initialize()) {
59-
this.api!.sendEvent(event);
59+
return this.api!.sendEvent(event);
6060
}
6161
}
6262

@@ -102,7 +102,7 @@ export class Telemetry {
102102

103103
await Promise.all(promises);
104104

105-
this.context.globalState.update(
105+
await this.context.globalState.update(
106106
"rubyLsp.lastConfigurationTelemetry",
107107
Date.now(),
108108
);

vscode/src/test/runTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ async function main() {
2121
}
2222
}
2323

24+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
2425
main();

vscode/src/test/suite/ruby/mise.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ suite("Mise", () => {
3838
version: "3.0.0",
3939
}),
4040
});
41+
const findStub = sinon
42+
.stub(mise, "findMiseUri")
43+
.resolves(
44+
vscode.Uri.joinPath(
45+
vscode.Uri.file(os.homedir()),
46+
".local",
47+
"bin",
48+
"mise",
49+
),
50+
);
4151

4252
const { env, version, yjit } = await mise.activate();
4353

@@ -53,5 +63,6 @@ suite("Mise", () => {
5363
assert.deepStrictEqual(env.ANY, "true");
5464

5565
execStub.restore();
66+
findStub.restore();
5667
});
5768
});

vscode/src/testController.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,22 @@ export class TestController {
4141
this.testRunProfile = this.testController.createRunProfile(
4242
"Run",
4343
vscode.TestRunProfileKind.Run,
44-
(request, token) => {
45-
this.runHandler(request, token);
44+
async (request, token) => {
45+
await this.runHandler(request, token);
4646
},
4747
true,
4848
);
4949

5050
this.testDebugProfile = this.testController.createRunProfile(
5151
"Debug",
5252
vscode.TestRunProfileKind.Debug,
53-
(request, token) => {
54-
this.debugHandler(request, token);
53+
async (request, token) => {
54+
await this.debugHandler(request, token);
5555
},
5656
false,
5757
this.debugTag,
5858
);
5959

60-
vscode.commands.executeCommand("testing.clearTestResults");
6160
vscode.window.onDidCloseTerminal((terminal: vscode.Terminal): void => {
6261
if (terminal === this.terminal) this.terminal = undefined;
6362
});
@@ -164,25 +163,24 @@ export class TestController {
164163
}
165164
}
166165

167-
runOnClick(testId: string) {
166+
async runOnClick(testId: string) {
168167
const test = this.findTestById(testId);
169168

170169
if (!test) return;
171170

172-
vscode.commands.executeCommand("vscode.revealTestInExplorer", test);
171+
await vscode.commands.executeCommand("vscode.revealTestInExplorer", test);
173172
let tokenSource: vscode.CancellationTokenSource | null =
174173
new vscode.CancellationTokenSource();
175174

176-
tokenSource.token.onCancellationRequested(() => {
175+
tokenSource.token.onCancellationRequested(async () => {
177176
tokenSource?.dispose();
178177
tokenSource = null;
179178

180-
vscode.window.showInformationMessage("Cancelled the progress");
179+
await vscode.window.showInformationMessage("Cancelled the progress");
181180
});
182181

183182
const testRun = new vscode.TestRunRequest([test], [], this.testRunProfile);
184-
185-
this.testRunProfile.runHandler(testRun, tokenSource.token);
183+
return this.testRunProfile.runHandler(testRun, tokenSource.token);
186184
}
187185

188186
debugTest(_path: string, _name: string, command?: string) {

vscode/src/workspace.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class Workspace implements WorkspaceInterface {
6767
} catch (error: any) {
6868
this.error = true;
6969

70-
vscode.window.showErrorMessage(
70+
await vscode.window.showErrorMessage(
7171
`Directory ${this.workspaceFolder.uri.fsPath} is not writable. The Ruby LSP server needs to be able to create a
7272
.ruby-lsp directory to function appropriately. Consider switching to a directory for which VS Code has write
7373
permissions`,
@@ -80,7 +80,7 @@ export class Workspace implements WorkspaceInterface {
8080
await this.installOrUpdateServer();
8181
} catch (error: any) {
8282
this.error = true;
83-
vscode.window.showErrorMessage(
83+
await vscode.window.showErrorMessage(
8484
`Failed to setup the bundle: ${error.message}. \
8585
See [Troubleshooting](https://github.com/Shopify/ruby-lsp/blob/main/TROUBLESHOOTING.md) for help`,
8686
);
@@ -199,7 +199,10 @@ export class Workspace implements WorkspaceInterface {
199199
env: this.ruby.env,
200200
});
201201

202-
this.context.workspaceState.update("rubyLsp.lastGemUpdate", Date.now());
202+
await this.context.workspaceState.update(
203+
"rubyLsp.lastGemUpdate",
204+
Date.now(),
205+
);
203206
return;
204207
}
205208

@@ -213,7 +216,10 @@ export class Workspace implements WorkspaceInterface {
213216
cwd: this.workspaceFolder.uri.fsPath,
214217
env: this.ruby.env,
215218
});
216-
this.context.workspaceState.update("rubyLsp.lastGemUpdate", Date.now());
219+
await this.context.workspaceState.update(
220+
"rubyLsp.lastGemUpdate",
221+
Date.now(),
222+
);
217223
} catch (error) {
218224
// If we fail to update the global installation of `ruby-lsp`, we don't want to prevent the server from starting
219225
this.outputChannel.error(

0 commit comments

Comments
 (0)