Add frontend autoformatting and set CI to require formatted code for all languages (#6052)

# Description of Changes
Changes the strategy for autoformatting to reject PRs if they are not
formatted correctly instead of allowing them to merge and then spawning
a new PR to fix the formatting. The old strategy just caused more work
for us because we'd have to manually approve the followup PR and get it
merged, which required 2 reviewers so in practice it rarely got done and
just meant everyone's PRs ended up containing reformatting for unrelated
files, which makes code review unnecessarily difficult. If the PR's code
is not formatted correctly after this PR, a comment will be added
automatically to tell the author how to run the formatter script to fix
their code so it can go in.

This also enables autoformatting for the frontend code, using Prettier.
I've enabled it for pretty much everything in the frontend folder, other
than 3rd party files and files it doesn't make sense for. I also
excluded Markdown because it sounds likely to be more annoying to have
to autoformat the Markdown in the frontend folder but nowhere else. Open
to changing this though if people disagree.

> [!note]
> 
> Advice to reviewers: The first commit contains all of the actual logic
I've introduced (CI changes, Prettier config, etc.)
> The second commit is just the reformatting of the entire frontend
folder.
> The first commit needs proper review, the second one just give it a
spot-check that it's doing what you'd expect.
This commit is contained in:
James Brunton
2026-04-10 17:41:19 +01:00
committed by GitHub
parent 33b2b5827a
commit a3e45bc182
1359 changed files with 57784 additions and 57460 deletions
@@ -1,21 +1,21 @@
import { useEffect, useMemo, useRef } from 'react';
import { isAxiosError } from 'axios';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import apiClient from '@app/services/apiClient';
import { useAuth } from '@app/auth/UseSession';
import { useFileActions } from '@app/contexts/FileContext';
import { useNavigationActions } from '@app/contexts/NavigationContext';
import { alert } from '@app/components/toast';
import type { StirlingFile } from '@app/types/fileContext';
import type { FileId } from '@app/types/file';
import { fileStorage } from '@app/services/fileStorage';
import { useEffect, useMemo, useRef } from "react";
import { isAxiosError } from "axios";
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import apiClient from "@app/services/apiClient";
import { useAuth } from "@app/auth/UseSession";
import { useFileActions } from "@app/contexts/FileContext";
import { useNavigationActions } from "@app/contexts/NavigationContext";
import { alert } from "@app/components/toast";
import type { StirlingFile } from "@app/types/fileContext";
import type { FileId } from "@app/types/file";
import { fileStorage } from "@app/services/fileStorage";
import {
getShareBundleEntryRootId,
isZipBundle,
loadShareBundleEntries,
parseContentDispositionFilename,
} from '@app/services/shareBundleUtils';
} from "@app/services/shareBundleUtils";
interface ShareLinkLoaderProps {
token: string;
@@ -60,7 +60,7 @@ export default function ShareLinkLoader({ token }: ShareLinkLoaderProps) {
try {
const metadataResponse = await apiClient.get<ShareLinkMetadata>(
`/api/v1/storage/share-links/${normalizedToken}/metadata`,
{ suppressErrorToast: true, skipAuthRedirect: true, signal }
{ suppressErrorToast: true, skipAuthRedirect: true, signal },
);
shareMetadata = metadataResponse.data;
} catch {
@@ -68,21 +68,17 @@ export default function ShareLinkLoader({ token }: ShareLinkLoaderProps) {
}
const response = await apiClient.get(`/api/v1/storage/share-links/${normalizedToken}`, {
responseType: 'blob',
responseType: "blob",
suppressErrorToast: true,
skipAuthRedirect: true,
signal,
});
if (signal.aborted) return;
const contentType =
(response.headers && (response.headers['content-type'] || response.headers['Content-Type'])) ||
'';
const contentType = (response.headers && (response.headers["content-type"] || response.headers["Content-Type"])) || "";
const disposition =
(response.headers &&
(response.headers['content-disposition'] || response.headers['Content-Disposition'])) ||
'';
const filename = parseContentDispositionFilename(disposition) || 'shared-file';
(response.headers && (response.headers["content-disposition"] || response.headers["Content-Disposition"])) || "";
const filename = parseContentDispositionFilename(disposition) || "shared-file";
const blob = response.data as Blob;
const contentTypeValue = contentType || blob.type;
@@ -114,13 +110,9 @@ export default function ShareLinkLoader({ token }: ShareLinkLoaderProps) {
const entry = sortedEntries[i];
const newId = idMap.get(entry.logicalId);
if (!newId) continue;
const parentId = entry.parentLogicalId
? idMap.get(entry.parentLogicalId)
: undefined;
const parentId = entry.parentLogicalId ? idMap.get(entry.parentLogicalId) : undefined;
const rootId =
rootIdMap.get(getShareBundleEntryRootId(manifest, entry)) ||
idMap.get(manifest.rootLogicalId) ||
newId;
rootIdMap.get(getShareBundleEntryRootId(manifest, entry)) || idMap.get(manifest.rootLogicalId) || newId;
const sharedUpdates = {
remoteStorageId: shareMetadata?.fileId,
remoteOwnerUsername: shareMetadata?.owner ?? undefined,
@@ -150,9 +142,7 @@ export default function ShareLinkLoader({ token }: ShareLinkLoaderProps) {
const selectedIds: FileId[] = [];
for (const rootId of rootOrder) {
const rootEntries = sortedEntries.filter(
(entry) => getShareBundleEntryRootId(manifest, entry) === rootId
);
const rootEntries = sortedEntries.filter((entry) => getShareBundleEntryRootId(manifest, entry) === rootId);
const latestEntry = rootEntries[rootEntries.length - 1];
if (!latestEntry) {
continue;
@@ -166,8 +156,8 @@ export default function ShareLinkLoader({ token }: ShareLinkLoaderProps) {
actions.setSelectedFiles(selectedIds);
}
navActions.setWorkbench('viewer');
navigate('/', { replace: true });
navActions.setWorkbench("viewer");
navigate("/", { replace: true });
return;
}
}
@@ -183,62 +173,62 @@ export default function ShareLinkLoader({ token }: ShareLinkLoaderProps) {
if (stirlingFiles.length > 0) {
const ids = stirlingFiles.map((stirlingFile: StirlingFile) => stirlingFile.fileId);
actions.setSelectedFiles(ids);
const sharedUpdates = {
remoteStorageId: shareMetadata?.fileId,
remoteOwnerUsername: shareMetadata?.owner ?? undefined,
remoteOwnedByCurrentUser: false,
remoteAccessRole: shareMetadata?.accessRole ?? undefined,
remoteSharedViaLink: true,
remoteHasShareLinks: false,
remoteShareToken: shareMetadata?.shareToken || normalizedToken,
};
const sharedUpdates = {
remoteStorageId: shareMetadata?.fileId,
remoteOwnerUsername: shareMetadata?.owner ?? undefined,
remoteOwnedByCurrentUser: false,
remoteAccessRole: shareMetadata?.accessRole ?? undefined,
remoteSharedViaLink: true,
remoteHasShareLinks: false,
remoteShareToken: shareMetadata?.shareToken || normalizedToken,
};
for (const fileId of ids) {
actions.updateStirlingFileStub(fileId, sharedUpdates);
await fileStorage.updateFileMetadata(fileId, sharedUpdates);
}
}
navActions.setWorkbench('viewer');
navigate('/', { replace: true });
navActions.setWorkbench("viewer");
navigate("/", { replace: true });
} catch (error: unknown) {
if (signal.aborted) return;
const status = isAxiosError(error) ? error.response?.status : undefined;
if (status === 401 || status === 403) {
if (!isAuthenticated && !authLoading) {
alert({
alertType: 'warning',
title: t('storageShare.requiresLogin', 'This shared file requires login.'),
alertType: "warning",
title: t("storageShare.requiresLogin", "This shared file requires login."),
expandable: false,
durationMs: 4000,
});
navigate('/login', {
navigate("/login", {
replace: true,
state: { from: { pathname: `/share/${normalizedToken}` } },
});
return;
}
alert({
alertType: 'warning',
alertType: "warning",
title: t(
'storageShare.accessDenied',
'You do not have access to this shared file. Ask the owner to share it with you.'
"storageShare.accessDenied",
"You do not have access to this shared file. Ask the owner to share it with you.",
),
expandable: false,
durationMs: 4500,
});
navigate('/', { replace: true });
navigate("/", { replace: true });
} else if (status === 404 || status === 410) {
alert({
alertType: 'error',
title: t('storageShare.expiredTitle', 'Link expired'),
alertType: "error",
title: t("storageShare.expiredTitle", "Link expired"),
expandable: false,
durationMs: 4000,
});
navigate('/', { replace: true });
navigate("/", { replace: true });
} else {
alert({
alertType: 'error',
title: t('storageShare.loadFailed', 'Unable to open shared file.'),
alertType: "error",
title: t("storageShare.loadFailed", "Unable to open shared file."),
expandable: false,
durationMs: 4000,
});