Change over to "always" for return await

This commit is contained in:
Caleb Owens 2024-04-16 20:11:53 +01:00
parent 78a7d44b45
commit dac89e41a9
39 changed files with 98 additions and 87 deletions

View File

@ -60,7 +60,7 @@ module.exports = {
}
],
'no-return-await': 'off', // Required to be off for @typescript-eslint/return-await
'@typescript-eslint/return-await': ['error', 'in-try-catch'],
'@typescript-eslint/return-await': ['error', 'always'],
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/await-thenable': 'error'
},

View File

@ -95,40 +95,43 @@ export class AIService {
) {}
async getModelKind() {
return this.gitConfig.getWithDefault<ModelKind>(GitAIConfigKey.ModelProvider, ModelKind.OpenAI);
return await this.gitConfig.getWithDefault<ModelKind>(
GitAIConfigKey.ModelProvider,
ModelKind.OpenAI
);
}
async getOpenAIKeyOption() {
return this.gitConfig.getWithDefault<KeyOption>(
return await this.gitConfig.getWithDefault<KeyOption>(
GitAIConfigKey.OpenAIKeyOption,
KeyOption.ButlerAPI
);
}
async getOpenAIKey() {
return this.gitConfig.get(GitAIConfigKey.OpenAIKey);
return await this.gitConfig.get(GitAIConfigKey.OpenAIKey);
}
async getOpenAIModleName() {
return this.gitConfig.getWithDefault<OpenAIModelName>(
return await this.gitConfig.getWithDefault<OpenAIModelName>(
GitAIConfigKey.OpenAIModelName,
OpenAIModelName.GPT35Turbo
);
}
async getAnthropicKeyOption() {
return this.gitConfig.getWithDefault<KeyOption>(
return await this.gitConfig.getWithDefault<KeyOption>(
GitAIConfigKey.AnthropicKeyOption,
KeyOption.ButlerAPI
);
}
async getAnthropicKey() {
return this.gitConfig.get(GitAIConfigKey.AnthropicKey);
return await this.gitConfig.get(GitAIConfigKey.AnthropicKey);
}
async getAnthropicModelName() {
return this.gitConfig.getWithDefault<AnthropicModelName>(
return await this.gitConfig.getWithDefault<AnthropicModelName>(
GitAIConfigKey.AnthropicModelName,
AnthropicModelName.Haiku
);

View File

@ -43,6 +43,6 @@ export class AuthService {
}
async getPublicKey() {
return invoke<string>('get_public_key');
return await invoke<string>('get_public_key');
}
}

View File

@ -11,6 +11,6 @@ export class GitConfigService {
}
async set<T extends string>(key: string, value: T) {
return invoke<T | undefined>('git_set_global_config', { key, value });
return await invoke<T | undefined>('git_set_global_config', { key, value });
}
}

View File

@ -6,9 +6,9 @@ export type Verification = {
};
export async function initDeviceOauth() {
return invoke<Verification>('init_device_oauth');
return await invoke<Verification>('init_device_oauth');
}
export async function checkAuthStatus(params: { deviceCode: string }) {
return invoke<string>('check_auth_status', params);
return await invoke<string>('check_auth_status', params);
}

View File

@ -40,27 +40,27 @@ export class HttpClient {
body: formatBody(opts.body)
});
return parseResponseJSON(response);
return await parseResponseJSON(response);
}
async get<T>(path: string, opts?: Omit<RequestOptions, 'body'>) {
return this.request<T>(path, { ...opts, method: 'GET' });
return await this.request<T>(path, { ...opts, method: 'GET' });
}
async post<T>(path: string, opts?: RequestOptions) {
return this.request<T>(path, { ...opts, method: 'POST' });
return await this.request<T>(path, { ...opts, method: 'POST' });
}
async put<T>(path: string, opts?: RequestOptions) {
return this.request<T>(path, { ...opts, method: 'PUT' });
return await this.request<T>(path, { ...opts, method: 'PUT' });
}
async patch<T>(path: string, opts?: RequestOptions) {
return this.request<T>(path, { ...opts, method: 'PATCH' });
return await this.request<T>(path, { ...opts, method: 'PATCH' });
}
async delete<T>(path: string, opts?: RequestOptions) {
return this.request<T>(path, { ...opts, method: 'DELETE' });
return await this.request<T>(path, { ...opts, method: 'DELETE' });
}
}
@ -74,7 +74,7 @@ async function parseResponseJSON(response: Response) {
} else if (response.status >= 400) {
throw new Error(`HTTP Error ${response.statusText}: ${await response.text()}`);
} else {
return response.json();
return await response.json();
}
}

View File

@ -4,5 +4,8 @@ export function subscribe(
params: { projectId: string },
callback: (params: { projectId: string }) => Promise<void>
) {
return listen(`project://${params.projectId}/git/index`, async () => callback({ ...params }));
return listen(
`project://${params.projectId}/git/index`,
async () => await callback({ ...params })
);
}

View File

@ -82,5 +82,5 @@ export async function invoke<T>(command: string, params: Record<string, unknown>
export function listen<T>(event: EventName, handle: EventCallback<T>) {
const unlisten = listenTauri(event, handle);
return async () => unlisten.then((unlistenFn) => unlistenFn());
return async () => await unlisten.then((unlistenFn) => unlistenFn());
}

View File

@ -67,7 +67,7 @@ export class ProjectService {
) {}
private async loadAll() {
return invoke<Project[]>('list_projects').then((p) => plainToInstance(Project, p));
return await invoke<Project[]>('list_projects').then((p) => plainToInstance(Project, p));
}
async reload(): Promise<void> {
@ -90,7 +90,7 @@ export class ProjectService {
}
async deleteProject(id: string) {
return invoke('delete_project', { id });
return await invoke('delete_project', { id });
}
async promptForDirectory(): Promise<string | undefined> {
@ -98,7 +98,7 @@ export class ProjectService {
if (selectedPath) {
if (selectedPath === null) return;
if (Array.isArray(selectedPath) && selectedPath.length !== 1) return;
return Array.isArray(selectedPath) ? selectedPath[0] : selectedPath;
return Array.isArray(selectedPath) ? selectedPath[0] : await selectedPath;
}
}
@ -133,7 +133,7 @@ export class ProjectService {
uid?: string;
}
): Promise<CloudProject> {
return this.httpClient.post('projects.json', {
return await this.httpClient.post('projects.json', {
body: params,
token
});
@ -147,14 +147,14 @@ export class ProjectService {
description?: string;
}
): Promise<CloudProject> {
return this.httpClient.put(`projects/${repositoryId}.json`, {
return await this.httpClient.put(`projects/${repositoryId}.json`, {
body: params,
token
});
}
async getCloudProject(token: string, repositoryId: string): Promise<CloudProject> {
return this.httpClient.get(`projects/${repositoryId}.json`, {
return await this.httpClient.get(`projects/${repositoryId}.json`, {
token
});
}

View File

@ -68,13 +68,13 @@ export class PromptService {
// Feeds user supplied string as input to askpass
async respond(payload: PromptResponse) {
this.reset.next(undefined);
return invoke('submit_prompt_response', payload);
return await invoke('submit_prompt_response', payload);
}
// Cancels the executable input prompt
async cancel(id: string) {
this.reset.next(undefined);
return invoke('submit_prompt_response', { id: id, response: null });
return await invoke('submit_prompt_response', { id: id, response: null });
}
/**

View File

@ -1,13 +1,13 @@
import { invoke } from '$lib/backend/ipc';
export async function logs() {
return invoke<string>('get_logs_archive_path');
return await invoke<string>('get_logs_archive_path');
}
export async function gitbutlerData(params: { projectId: string }) {
return invoke<string>('get_project_data_archive_path', params);
return await invoke<string>('get_project_data_archive_path', params);
}
export async function projectData(params: { projectId: string }) {
return invoke<string>('get_project_archive_path', params);
return await invoke<string>('get_project_archive_path', params);
}

View File

@ -13,7 +13,7 @@
<button
class="btn"
class:pop
on:mousedown={async () => goto('/settings/')}
on:mousedown={async () => await goto('/settings/')}
class:collapsed={isNavCollapsed}
>
{#if !isNavCollapsed}

View File

@ -22,7 +22,7 @@
<button
use:tooltip={isNavCollapsed ? 'Trunk' : ''}
on:mousedown={async () => goto(`/${project.id}/base`)}
on:mousedown={async () => await goto(`/${project.id}/base`)}
class="base-branch-card"
class:selected
bind:this={baseContents}

View File

@ -145,9 +145,9 @@
role="button"
tabindex="0"
on:keypress={async () =>
open(`vscode://file${project.vscodePath}/?windowId=_blank`)}
await open(`vscode://file${project.vscodePath}/?windowId=_blank`)}
on:click={async () =>
open(`vscode://file${project.vscodePath}/?windowId=_blank`)}
await open(`vscode://file${project.vscodePath}/?windowId=_blank`)}
>
<div class="empty-board__suggestions__link__icon">
<Icon name="vscode" />

View File

@ -112,7 +112,7 @@
<SectionCard
labelFor="historySync"
on:change={async (e) => onSyncChange(e.detail)}
on:change={async (e) => await onSyncChange(e.detail)}
orientation="row"
>
<svelte:fragment slot="caption">
@ -122,7 +122,7 @@
<Toggle
id="historySync"
checked={project.api?.sync || false}
on:change={async (e) => onSyncChange(e.detail)}
on:change={async (e) => await onSyncChange(e.detail)}
/>
</svelte:fragment>
</SectionCard>

View File

@ -217,7 +217,7 @@
icon="ai-small"
disabled={!($aiGenEnabled && aiConfigurationValid)}
loading={aiLoading}
on:click={async () => generateCommitMessage($branch.files)}
on:click={async () => await generateCommitMessage($branch.files)}
>
Generate message
<ContextMenu type="checklist" slot="context-menu" bind:this={contextMenu}>

View File

@ -19,7 +19,7 @@
<button
use:tooltip={isNavCollapsed ? label : ''}
on:mousedown={async () => goto(href)}
on:mousedown={async () => await goto(href)}
class="domain-button text-base-14 text-semibold"
class:selected
>

View File

@ -36,7 +36,7 @@
<div class="mb-2 bg-red-500 px-2 py-0 font-bold text-white">
<button
class="font-bold text-white"
on:click={async () => branchController.markResolved(file.path)}
on:click={async () => await branchController.markResolved(file.path)}
>
Mark resolved
</button>

View File

@ -21,7 +21,7 @@
icon="settings"
style="ghost"
size="cta"
on:mousedown={async () => goto(`/${projectId}/settings`)}
on:mousedown={async () => await goto(`/${projectId}/settings`)}
wide={isNavCollapsed}
/>
</div>

View File

@ -70,7 +70,7 @@
style="ghost"
kind="solid"
icon="plus-small"
on:mousedown={async () => branchController.createBranch({})}>New branch</Button
on:mousedown={async () => await branchController.createBranch({})}>New branch</Button
>
</div>
</div>

View File

@ -53,7 +53,7 @@
style="pop"
kind="solid"
grow
on:click={async () => submit()}
on:click={async () => await submit()}
disabled={submitDisabled || isSubmitting}
loading={isSubmitting}
>

View File

@ -36,7 +36,7 @@
<Toggle
id="allowForcePush"
bind:checked={allowForcePushing}
on:change={async () => setWithForcePush(allowForcePushing)}
on:change={async () => await setWithForcePush(allowForcePushing)}
/>
</svelte:fragment>
</SectionCard>
@ -50,7 +50,7 @@
<Toggle
id="omitCertificateCheck"
bind:checked={omitCertificateCheck}
on:change={async () => setOmitCertificateCheck(omitCertificateCheck)}
on:change={async () => await setOmitCertificateCheck(omitCertificateCheck)}
/>
</svelte:fragment>
</SectionCard>

View File

@ -8,7 +8,7 @@
const project = getContext(Project);
async function setEnabled(enabled: boolean) {
return invoke('menu_item_set_enabled', {
return await invoke('menu_item_set_enabled', {
menuItemId: 'project/settings',
enabled
});

View File

@ -58,8 +58,8 @@
bind:this={modal}
width="small"
title="Git fetch requires input"
on:submit={async () => submit()}
on:close={async () => cancel()}
on:submit={async () => await submit()}
on:close={async () => await cancel()}
>
<div class="message">
{#if $error}

View File

@ -116,7 +116,7 @@
if (!timeUntilUdate) {
return;
}
setTimeout(async () => updateDetailsAndChecks(), timeUntilUdate * 1000);
setTimeout(async () => await updateDetailsAndChecks(), timeUntilUdate * 1000);
}
function getChecksCount(status: ChecksStatus): string {

View File

@ -57,10 +57,10 @@
kind="solid"
help="Does not create a commit. Can be toggled."
on:click={async () =>
pullrequest &&
branchController.createvBranchFromBranch(
'refs/remotes/origin/' + pullrequest.targetBranch
)}>Apply</Button
await (pullrequest &&
branchController.createvBranchFromBranch(
'refs/remotes/origin/' + pullrequest.targetBranch
))}>Apply</Button
>
</div>
</div>

View File

@ -30,7 +30,7 @@
}
async function gitIndexLength() {
return invoke<void>('git_index_size', {
return await invoke<void>('git_index_size', {
projectId: projectId
});
}
@ -76,22 +76,27 @@
toasts.promise(
Promise.all([
sendLogs ? zip.logs().then(async (path) => readZipFile(path, 'logs.zip')) : undefined,
sendLogs ? zip.logs().then(async (path) => await readZipFile(path, 'logs.zip')) : undefined,
sendProjectData
? zip.gitbutlerData({ projectId }).then(async (path) => readZipFile(path, 'data.zip'))
? zip
.gitbutlerData({ projectId })
.then(async (path) => await readZipFile(path, 'data.zip'))
: undefined,
sendProjectRepository
? zip.projectData({ projectId }).then(async (path) => readZipFile(path, 'project.zip'))
? zip
.projectData({ projectId })
.then(async (path) => await readZipFile(path, 'project.zip'))
: undefined
]).then(async ([logs, data, repo]) =>
createFeedback($user?.access_token, {
email,
message,
context,
logs,
data,
repo
})
]).then(
async ([logs, data, repo]) =>
await createFeedback($user?.access_token, {
email,
message,
context,
logs,
data,
repo
})
),
{
loading:
@ -125,7 +130,7 @@
if (params.data) formData.append('data', params.data);
// Content Type must be unset for the right form-data border to be set automatically
return httpClient.put('feedback', {
return await httpClient.put('feedback', {
body: formData,
headers: { 'Content-Type': undefined },
token
@ -141,7 +146,7 @@
<Modal
bind:this={modal}
on:close={() => close()}
on:submit={async () => submit()}
on:submit={async () => await submit()}
title="Share debug data with GitButler team for review"
>
<div class="content-wrapper">

View File

@ -61,7 +61,7 @@ function persisted<T>(initial: T, key: string): Writable<T> & { onDisk: () => Pr
}
async function onDisk() {
return storeValueWithDefault(initial, key);
return await storeValueWithDefault(initial, key);
}
const subscribe = thisStore.subscribe;

View File

@ -142,7 +142,7 @@ export class GitHubService {
)
);
this.reload$.next({ skipCache: true });
return fresh;
return await fresh;
}
fetchPrs(skipCache: boolean): Observable<PullRequest[]> {
@ -268,7 +268,7 @@ export class GitHubService {
draft: boolean
): Promise<{ pr: PullRequest } | { err: string | { message: string; help: string } }> {
this.setBusy('creating_pr', branchId);
return firstValueFrom(
return await firstValueFrom(
// We have to wrap with defer becasue using `async` functions with operators
// create a promise that will stay rejected when rejected.
defer(async () => {
@ -345,7 +345,7 @@ export class GitHubService {
// Wait for GitHub to become eventually consistent. If we refresh too quickly then
// then it'll show as mergeable and no checks even if checks are present.
delay(1000),
finalize(async () => this.reload())
finalize(async () => await this.reload())
)
);
}
@ -402,7 +402,7 @@ export class GitHubService {
}
async fetchChecks(ref: string) {
return this.octokit.checks.listForRef({
return await this.octokit.checks.listForRef({
headers: DEFAULT_HEADERS,
owner: this.owner,
repo: this.repo,

View File

@ -28,7 +28,7 @@ export class RemoteBranchService {
) {
this.branches$ = combineLatest([baseBranch$, head$, fetches$]).pipe(
mergeWith(this.reload$),
switchMap(async () => listRemoteBranches(projectId)),
switchMap(async () => await listRemoteBranches(projectId)),
shareReplay(1),
catchError((e) => {
console.error(e);

View File

@ -104,11 +104,11 @@ export class UserService {
// TODO: Remove token from URL, we don't want that leaking into logs.
async getLoginUser(token: string): Promise<User> {
return this.httpClient.get(`login/user/${token}.json`);
return await this.httpClient.get(`login/user/${token}.json`);
}
async getUser(token: string): Promise<User> {
return this.httpClient.get('user.json', { token });
return await this.httpClient.get('user.json', { token });
}
async updateUser(token: string, params: { name?: string; picture?: File }): Promise<any> {
@ -117,7 +117,7 @@ export class UserService {
if (params.picture) formData.append('avatar', params.picture);
// Content Type must be unset for the right form-data border to be set automatically
return this.httpClient.put('user.json', {
return await this.httpClient.put('user.json', {
body: formData,
headers: { 'Content-Type': undefined },
token

View File

@ -2,7 +2,7 @@ export async function on(combo: string, callback: (event: KeyboardEvent) => void
const comboContainsControlKeys =
combo.includes('Meta') || combo.includes('Alt') || combo.includes('Ctrl');
return import('tinykeys').then(({ tinykeys }) =>
return await import('tinykeys').then(({ tinykeys }) =>
tinykeys(window, {
[combo]: (event) => {
const target = event.target as HTMLElement;

View File

@ -1,3 +1,3 @@
export async function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
return await new Promise((resolve) => setTimeout(resolve, ms));
}

View File

@ -21,5 +21,5 @@ export async function promise(
error: 'Error!'
}
) {
return toast.promise(promise, opts, defaultOptions);
return await toast.promise(promise, opts, defaultOptions);
}

View File

@ -6,6 +6,6 @@ export function unsubscribe(...unsubscribers: MaybePromise<() => any>[]) {
const promises = awaitedUnsubscribers.map((unsubscriber) => unsubscriber?.());
return Promise.all(promises);
return await Promise.all(promises);
};
}

View File

@ -105,7 +105,7 @@ async function getBaseBranch(params: { projectId: string }): Promise<BaseBranch
export async function getRemoteBranches(projectId: string | undefined) {
if (!projectId) return [];
return invoke<Array<string>>('git_remote_branches', { projectId }).then((branches) =>
return await invoke<Array<string>>('git_remote_branches', { projectId }).then((branches) =>
branches
.map((name) => name.substring(13))
.sort((a, b) => a.localeCompare(b))

View File

@ -87,11 +87,11 @@ export class VirtualBranchService {
)
);
this.reload$.next();
return fresh;
return await fresh;
}
async getById(branchId: string) {
return firstValueFrom(
return await firstValueFrom(
this.branches$.pipe(
timeout(10000),
map((branches) => branches?.find((b) => b.id == branchId && b.upstream))

View File

@ -51,7 +51,7 @@
onMount(() => {
return unsubscribe(
events.on('goto', async (path: string) => goto(path)),
events.on('goto', async (path: string) => await goto(path)),
events.on('openSendIssueModal', () => shareIssueModal?.show()),
// Zoom using cmd +, - and =

View File

@ -50,7 +50,7 @@
baseBranchService.fetchFromTarget();
clearFetchInterval();
const intervalMs = 15 * 60 * 1000; // 15 minutes
intervalId = setInterval(async () => baseBranchService.fetchFromTarget(), intervalMs);
intervalId = setInterval(async () => await baseBranchService.fetchFromTarget(), intervalMs);
}
function clearFetchInterval() {