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

fix: enable eslint @typescript-eslint/no-floating-promises rule #245

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,28 @@
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"ignorePatterns": [
"node_modules/**",
"**/dist/**",
"builtin/**"
"builtin/**",
"__mocks__",
"coverage",
"rollup.config.js",
"vitest.config.js",
"vite.config.js"
],
"rules": {
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-floating-promises": ["error", {"ignoreVoid": false}],

/**
* Having a semicolon helps the optimizer interpret your code correctly.
Expand Down
2 changes: 1 addition & 1 deletion src/crc-console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ async function openConsole(): Promise<void> {
const result = await commander.consoleUrl();
const url = result.ClusterConfig.WebConsoleURL;
if (url) {
extensionApi.env.openExternal(extensionApi.Uri.parse(url));
await extensionApi.env.openExternal(extensionApi.Uri.parse(url));
}
}
2 changes: 1 addition & 1 deletion src/crc-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function setUpCrc(logger: extensionApi.Logger, askForPreset = false
setupBar.text = 'All done.';
} catch (err) {
console.error(err);
extensionApi.window.showErrorMessage(`${productName} configuration failed:\n${err}`);
await extensionApi.window.showErrorMessage(`${productName} configuration failed:\n${err}`);
return false;
} finally {
setupBar.hide();
Expand Down
10 changes: 6 additions & 4 deletions src/crc-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ export async function startCrc(
crcStatus.setSetupRunning(false);
}
}
crcLogProvider.startSendingLogs(logger);
await crcLogProvider.startSendingLogs(logger);
const result = await commander.start();
if (result.Status === 'Running') {
provider.updateStatus('started');
return true;
} else {
provider.updateStatus('error');
extensionApi.window.showErrorMessage(`Error during starting ${productName}: ${result.Status}`);
await extensionApi.window.showErrorMessage(`Error during starting ${productName}: ${result.Status}`);
}
} catch (err) {
if (typeof err.message === 'string') {
Expand All @@ -84,7 +84,7 @@ export async function startCrc(
return true;
}
}
extensionApi.window.showErrorMessage(`${productName} start error: ${err}`);
await extensionApi.window.showErrorMessage(`${productName} start error: ${err}`);
console.error(err);
provider.updateStatus('stopped');
}
Expand Down Expand Up @@ -137,7 +137,9 @@ async function askAndStorePullSecret(logger: extensionApi.Logger): Promise<boole
}
} catch (err) {
// not valid json
extensionApi.window.showErrorMessage(`Start failed, pull secret is not valid. Please start again:\n '${err}'`);
await extensionApi.window.showErrorMessage(
`Start failed, pull secret is not valid. Please start again:\n '${err}'`,
);
return false;
}
try {
Expand Down
24 changes: 12 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function _activate(extensionContext: extensionApi.ExtensionContext): Promi
if (crcVersion) {
// if daemon running we could sync preferences
if (hasDaemonRunning) {
syncPreferences(provider, extensionContext, telemetryLogger);
await syncPreferences(provider, extensionContext, telemetryLogger);
}

// if no need to setup we could add commands
Expand All @@ -135,7 +135,7 @@ async function _activate(extensionContext: extensionApi.ExtensionContext): Promi

// no need to setup and crc has cluster
if (!isNeedSetup() && crcStatus.status.CrcStatus !== 'No Cluster') {
presetChanged(provider, extensionContext, telemetryLogger);
await presetChanged(provider, extensionContext, telemetryLogger);
} else {
// else get preset from cli as setup is not finished and daemon may not running
const preset = await getPreset();
Expand All @@ -162,8 +162,8 @@ async function _activate(extensionContext: extensionApi.ExtensionContext): Promi
registerProviderConnectionFactory(provider, extensionContext, telemetryLogger);
await connectToCrc();
addCommands(telemetryLogger);
syncPreferences(provider, extensionContext, telemetryLogger);
presetChanged(provider, extensionContext, telemetryLogger);
await syncPreferences(provider, extensionContext, telemetryLogger);
await presetChanged(provider, extensionContext, telemetryLogger);
});
},
});
Expand All @@ -176,7 +176,7 @@ async function _activate(extensionContext: extensionApi.ExtensionContext): Promi

extensionContext.subscriptions.push(
presetChangedEvent(() => {
presetChanged(provider, extensionContext, telemetryLogger);
presetChanged(provider, extensionContext, telemetryLogger).catch(e => console.error(String(e)));
}),
);

Expand Down Expand Up @@ -259,7 +259,7 @@ async function createCrcVm(
const hasStarted = await startCrc(provider, logger, telemetryLogger);
if (!connectionDisposable && hasStarted) {
addCommands(telemetryLogger);
presetChanged(provider, extensionContext, telemetryLogger);
await presetChanged(provider, extensionContext, telemetryLogger);
}

if (connectionFactoryDisposable) {
Expand All @@ -277,9 +277,9 @@ async function initializeCrc(
if (hasSetupFinished) {
await needSetup();
await connectToCrc();
presetChanged(provider, extensionContext, telemetryLogger);
await presetChanged(provider, extensionContext, telemetryLogger);
addCommands(telemetryLogger);
syncPreferences(provider, extensionContext, telemetryLogger);
await syncPreferences(provider, extensionContext, telemetryLogger);
}
return hasSetupFinished;
}
Expand All @@ -292,7 +292,7 @@ function addCommands(telemetryLogger: extensionApi.TelemetryLogger): void {

commandManager.addCommand(CRC_PUSH_IMAGE_TO_CLUSTER, image => {
telemetryLogger.logUsage('pushImage');
pushImageToCrcCluster(image);
return pushImageToCrcCluster(image);
});
}

Expand Down Expand Up @@ -333,12 +333,12 @@ export function deactivate(): void {
crcStatus.stopStatusUpdate();
}

async function registerOpenShiftLocalCluster(
function registerOpenShiftLocalCluster(
name,
provider: extensionApi.Provider,
extensionContext: extensionApi.ExtensionContext,
telemetryLogger: extensionApi.TelemetryLogger,
): Promise<void> {
): void {
const status = () => crcStatus.getConnectionStatus();
const apiURL = 'https://api.crc.testing:6443';
const kubernetesProviderConnection: extensionApi.KubernetesProviderConnection = {
Expand Down Expand Up @@ -419,7 +419,7 @@ async function presetChanged(

if (preset === 'podman') {
// do nothing
extensionApi.window.showInformationMessage(
await extensionApi.window.showInformationMessage(
'Currently we do not support the Podman preset of OpenShift Local. Please use preference to change this:\n\nSettings > Preferences > Red Hat OpenShift Local > Preset',
'OK',
);
Expand Down
4 changes: 2 additions & 2 deletions src/image-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ export async function pushImageToCrcCluster(image: ImageInfo): Promise<void> {
if (result.exitCode !== 0) {
throw new Error(result.stdErr);
}
extensionApi.window.showInformationMessage(`Image ${image.name} pushed to ${productName} cluster`, 'OK');
await extensionApi.window.showInformationMessage(`Image ${image.name} pushed to ${productName} cluster`, 'OK');
} catch (error) {
const errorMessage = error instanceof Error ? error.message : '' + error;
progress.report({
message: `Error while pushing image ${image.name} to ${productName} cluster: ${errorMessage}`,
});
} finally {
fs.promises.rm(filename);
await fs.promises.rm(filename);
}
},
);
Expand Down
20 changes: 10 additions & 10 deletions src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ export async function syncPreferences(
context.subscriptions.push(
extensionApi.configuration.onDidChangeConfiguration(e => {
if (!isRefreshing) {
configChanged(e, provider, telemetryLogger);
configChanged(e, provider, telemetryLogger).catch(e => console.log(String(e)));
}
}),
);

syncProxy(context);
await syncProxy(context);
} catch (err) {
console.error('Cannot sync preferences: ', err);
}
Expand All @@ -106,22 +106,22 @@ export async function syncPreferences(
async function syncProxy(context: extensionApi.ExtensionContext): Promise<void> {
// sync proxy settings
if (extensionApi.proxy.isEnabled()) {
handleProxyChange(extensionApi.proxy.getProxySettings());
await handleProxyChange(extensionApi.proxy.getProxySettings());
}

context.subscriptions.push(
extensionApi.proxy.onDidStateChange(e => {
if (e) {
handleProxyChange(extensionApi.proxy.getProxySettings());
handleProxyChange(extensionApi.proxy.getProxySettings()).catch(e => console.error(String(e)));
} else {
handleProxyChange();
handleProxyChange().catch(e => console.error(String(e)));
}
}),
);

context.subscriptions.push(
extensionApi.proxy.onDidUpdateProxy(e => {
handleProxyChange(e);
handleProxyChange(e).catch(err => console.error(String(err)));
}),
);
}
Expand All @@ -147,7 +147,7 @@ async function handleProxyChange(proxy?: extensionApi.ProxySettings): Promise<vo
}
} catch (err) {
console.error(err);
extensionApi.window.showErrorMessage(`Could not update ${productName} proxy configuration: ${err}`);
await extensionApi.window.showErrorMessage(`Could not update ${productName} proxy configuration: ${err}`);
}
}

Expand Down Expand Up @@ -175,15 +175,15 @@ async function configChanged(
if (element.validation) {
const validationResult = element.validation(newValue, currentConfig.preset);
if (validationResult) {
extensionApi.window.showErrorMessage(validationResult);
extConfig.update(key, currentConfig[element.name]);
await extensionApi.window.showErrorMessage(validationResult);
await extConfig.update(key, currentConfig[element.name]);
continue;
}
}
if (initialCrcConfig[element.name] !== currentConfig[element.name]) {
if (await useCrcSettingValue(element.label, newValue + '', currentConfig[element.name] + '')) {
initialCrcConfig[element.name] = currentConfig[element.name];
extConfig.update(key, currentConfig[element.name]);
await extConfig.update(key, currentConfig[element.name]);
continue;
}
}
Expand Down
Loading