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 57785 additions and 57461 deletions
+28 -19
View File
@@ -2,19 +2,19 @@
* Standardized error handling utilities for tool operations
*/
import { normalizeAxiosErrorData } from '@app/services/errorUtils';
import { normalizeAxiosErrorData } from "@app/services/errorUtils";
/**
* Default error extractor that follows the standard pattern
*/
export const extractErrorMessage = (error: any): string => {
if (error.response?.data && typeof error.response.data === 'string') {
if (error.response?.data && typeof error.response.data === "string") {
return error.response.data;
}
if (error.message) {
return error.message;
}
return 'There was an error processing your request.';
return "There was an error processing your request.";
};
/**
@@ -24,7 +24,7 @@ export const extractErrorMessage = (error: any): string => {
*/
export const createStandardErrorHandler = (fallbackMessage: string) => {
return (error: any): string => {
if (error.response?.data && typeof error.response.data === 'string') {
if (error.response?.data && typeof error.response.data === "string") {
return error.response.data;
}
if (error.message) {
@@ -38,35 +38,44 @@ export const createStandardErrorHandler = (fallbackMessage: string) => {
* Parses a 422 response, extracts errored file IDs from the payload (JSON or UUID regex),
* and marks them in the UI. Returns true if IDs were found and handled, false otherwise.
*/
export const handle422Error = async (
error: any,
markFileError: (fileId: string) => void
): Promise<boolean> => {
export const handle422Error = async (error: any, markFileError: (fileId: string) => void): Promise<boolean> => {
const status = error?.response?.status;
if (typeof status !== 'number' || status !== 422) return false;
if (typeof status !== "number" || status !== 422) return false;
const payload = error?.response?.data;
let parsed: unknown = payload;
if (typeof payload === 'string') {
try { parsed = JSON.parse(payload); } catch { parsed = payload; }
} else if (payload && typeof (payload as Blob).text === 'function') {
if (typeof payload === "string") {
try {
parsed = JSON.parse(payload);
} catch {
parsed = payload;
}
} else if (payload && typeof (payload as Blob).text === "function") {
const text = await (payload as Blob).text();
try { parsed = JSON.parse(text); } catch { parsed = text; }
try {
parsed = JSON.parse(text);
} catch {
parsed = text;
}
}
let ids: string[] | undefined = Array.isArray((parsed as { errorFileIds?: unknown })?.errorFileIds)
? (parsed as { errorFileIds: string[] }).errorFileIds
: undefined;
if (!ids && typeof parsed === 'string') {
if (!ids && typeof parsed === "string") {
const match = parsed.match(/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/g);
if (match && match.length > 0) ids = Array.from(new Set(match));
}
if (ids && ids.length > 0) {
for (const id of ids) {
try { markFileError(id); } catch (_e) { void _e; }
try {
markFileError(id);
} catch (_e) {
void _e;
}
}
return true;
}
@@ -84,7 +93,7 @@ export const handle422Error = async (
export const handlePasswordError = async (
error: any,
incorrectPasswordMessage: string,
fallbackMessage: string
fallbackMessage: string,
): Promise<string> => {
const status = error?.response?.status;
@@ -100,8 +109,8 @@ export const handlePasswordError = async (
...error,
response: {
...error?.response,
data: normalizedData
}
data: normalizedData,
},
};
return extractErrorMessage(errorWithNormalizedData) || fallbackMessage;
};
};