Skip to content
Draft
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
7 changes: 7 additions & 0 deletions .changeset/add-curly-eslint-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/eslint-config": major
---

Add `curly` ESLint rule to enforce braces for control statements

This rule requires braces around the body of all control statements (if, else, for, while, etc.) to improve code readability and reduce diff size when adding statements.
4 changes: 3 additions & 1 deletion demo/admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ export function App() {
return config.scope.domain === scope.domain;
});

if (!siteConfig) throw new Error(`siteConfig not found for domain ${scope.domain}`);
if (!siteConfig) {
throw new Error(`siteConfig not found for domain ${scope.domain}`);
}
return {
url: siteConfig.url,
preloginEnabled: siteConfig.preloginEnabled || false,
Expand Down
4 changes: 3 additions & 1 deletion demo/admin/src/dam/ImportFromPicsum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const ImportFromPicsum = () => {
};

const handleSave = async () => {
if (picsumImage === undefined) return;
if (picsumImage === undefined) {
return;
}
await uploadFiles(
{ acceptedFiles: [picsumImage.file], fileRejections: [] },
{
Expand Down
4 changes: 3 additions & 1 deletion demo/admin/src/documents/links/EditLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ export const EditLink = ({ id }: Props) => {
return <Loading behavior="fillPageHeight" />;
}

if (!linkState) return null;
if (!linkState) {
return null;
}

return (
<>
Expand Down
9 changes: 7 additions & 2 deletions demo/admin/src/documents/pages/EditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ export const EditPage = ({ id }: Props) => {
<ContentGenerationConfigProvider
seo={{
getRelevantContent: () => {
if (!pageState || !pageState.document) return [];
if (!pageState || !pageState.document) {
return [];
}

return PageContentBlock.extractTextContents?.(pageState.document.content, { includeInvisibleContent: false }) ?? [];
},
Expand All @@ -152,7 +154,10 @@ export const EditPage = ({ id }: Props) => {
{hasChanges && (
<RouterPrompt
message={(location) => {
if (location.pathname.startsWith(match.url)) return true; //we navigated within our self
//we navigated within our self
if (location.pathname.startsWith(match.url)) {
return true;
}
return intl.formatMessage({
id: "editPage.discardChanges",
defaultMessage: "Discard unsaved changes?",
Expand Down
4 changes: 3 additions & 1 deletion demo/admin/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { App } from "./App";

const loadHtml = () => {
const rootElement = document.querySelector<HTMLElement>("#root");
if (!rootElement) return false;
if (!rootElement) {
return false;
}

const root = createRoot(rootElement);
root.render(createElement(App));
Expand Down
5 changes: 4 additions & 1 deletion demo/admin/src/mainMenu/components/EditMainMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ const EditMainMenuItem = ({ item }: EditMainMenuItemProps) => {
{hasChanges && (
<RouterPrompt
message={(location) => {
if (location.pathname.startsWith(match.url)) return true; //we navigated within our self
//we navigated within our self
if (location.pathname.startsWith(match.url)) {
return true;
}
return intl.formatMessage(messages.saveUnsavedChanges);
}}
saveAction={handleSaveAction}
Expand Down
16 changes: 12 additions & 4 deletions demo/admin/src/products/ManufacturerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export function ManufacturerForm({ id }: FormProps) {
const filteredData = data
? filterByFragment<GQLManufacturerFormDetailsHandmadeFragment>(manufacturerFormFragment, data.manufacturer)
: undefined;
if (!filteredData) return {};
if (!filteredData) {
return {};
}
return {
...filteredData,
useAlternativeAddress: !!filteredData.address?.alternativeAddress,
Expand Down Expand Up @@ -119,7 +121,9 @@ export function ManufacturerForm({ id }: FormProps) {
});

const handleSubmit = async ({ useAlternativeAddress, ...formValues }: FormValues, form: FormApi<FormValues>, event: FinalFormSubmitEvent) => {
if (await saveConflict.checkForConflicts()) throw new Error("Conflicts detected");
if (await saveConflict.checkForConflicts()) {
throw new Error("Conflicts detected");
}
const output = {
...formValues,
address: formValues.address
Expand Down Expand Up @@ -149,7 +153,9 @@ export function ManufacturerForm({ id }: FormProps) {
},
};
if (mode === "edit") {
if (!id) throw new Error();
if (!id) {
throw new Error();
}
await client.mutate<GQLUpdateManufacturerMutation, GQLUpdateManufacturerMutationVariables>({
mutation: updateManufacturerMutation,
variables: { id, input: output },
Expand All @@ -170,7 +176,9 @@ export function ManufacturerForm({ id }: FormProps) {
}
};

if (error) throw error;
if (error) {
throw error;
}

if (loading) {
return <Loading behavior="fillPageHeight" />;
Expand Down
4 changes: 3 additions & 1 deletion demo/admin/src/products/ManufacturersGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ export function ManufacturersGrid() {
sort: muiGridSortToGql(sortModel),
},
});
if (error) throw error;
if (error) {
throw error;
}

const rows = data?.manufacturers.nodes ?? [];
const rowCount = useBufferedRowCount(data?.manufacturers.totalCount);
Expand Down
12 changes: 9 additions & 3 deletions demo/admin/src/products/ProductForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ export function ProductForm({ id, width, onCreate }: FormProps) {
});

const handleSubmit = async ({ manufacturerCountry, ...formValues }: FormValues, form: FormApi<FormValues>, event: FinalFormSubmitEvent) => {
if (await saveConflict.checkForConflicts()) throw new Error("Conflicts detected");
if (await saveConflict.checkForConflicts()) {
throw new Error("Conflicts detected");
}

const output = {
...formValues,
Expand All @@ -148,7 +150,9 @@ export function ProductForm({ id, width, onCreate }: FormProps) {
};

if (mode === "edit") {
if (!id) throw new Error();
if (!id) {
throw new Error();
}
await client.mutate<GQLUpdateProductMutation, GQLUpdateProductMutationVariables>({
mutation: updateProductMutation,
variables: { id, input: output },
Expand All @@ -167,7 +171,9 @@ export function ProductForm({ id, width, onCreate }: FormProps) {
}
};

if (error) throw error;
if (error) {
throw error;
}

if (loading) {
return <Loading behavior="fillPageHeight" />;
Expand Down
4 changes: 3 additions & 1 deletion demo/admin/src/products/ProductPriceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export function ProductPriceForm({ id }: FormProps) {
});

const handleSubmit = async (formValues: FormValues, form: FormApi<FormValues>, event: FinalFormSubmitEvent) => {
if (await saveConflict.checkForConflicts()) throw new Error("Conflicts detected");
if (await saveConflict.checkForConflicts()) {
throw new Error("Conflicts detected");
}
const output = {
...formValues,
price: formValues.price ? parseFloat(formValues.price) : null,
Expand Down
12 changes: 9 additions & 3 deletions demo/admin/src/products/ProductVariantForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ export function ProductVariantForm({ id, productId }: FormProps) {
});

const handleSubmit = async (formValues: FormValues, form: FormApi<FormValues>, event: FinalFormSubmitEvent) => {
if (await saveConflict.checkForConflicts()) throw new Error("Conflicts detected");
if (await saveConflict.checkForConflicts()) {
throw new Error("Conflicts detected");
}
const output = {
...formValues,
image: rootBlocks.image.state2Output(formValues.image),
};
if (mode === "edit") {
if (!id) throw new Error();
if (!id) {
throw new Error();
}
await client.mutate<GQLUpdateProductVariantMutation, GQLUpdateProductVariantMutationVariables>({
mutation: updateProductVariantFormMutation,
variables: { id, input: output },
Expand All @@ -102,7 +106,9 @@ export function ProductVariantForm({ id, productId }: FormProps) {
}
};

if (error) throw error;
if (error) {
throw error;
}

if (loading) {
return <Loading behavior="fillPageHeight" />;
Expand Down
4 changes: 3 additions & 1 deletion demo/admin/src/products/categories/ProductCategoriesGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ export function ProductCategoriesGrid() {
},
});
const rowCount = useBufferedRowCount(data?.productCategories.totalCount);
if (error) throw error;
if (error) {
throw error;
}
const rows =
data?.productCategories.nodes.map((node) => ({
...node,
Expand Down
12 changes: 9 additions & 3 deletions demo/admin/src/products/categories/ProductCategoryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ export function ProductCategoryForm({ id }: FormProps) {
},
});
const handleSubmit = async (formValues: FormValues, form: FormApi<FormValues>, event: FinalFormSubmitEvent) => {
if (await saveConflict.checkForConflicts()) throw new Error("Conflicts detected");
if (await saveConflict.checkForConflicts()) {
throw new Error("Conflicts detected");
}
const output = {
...formValues,
};
if (mode === "edit") {
if (!id) throw new Error();
if (!id) {
throw new Error();
}
const { ...updateInput } = output;
await client.mutate<GQLUpdateProductCategoryMutation, GQLUpdateProductCategoryMutationVariables>({
mutation: updateProductCategoryMutation,
Expand All @@ -81,7 +85,9 @@ export function ProductCategoryForm({ id }: FormProps) {
}
}
};
if (error) throw error;
if (error) {
throw error;
}
if (loading) {
return <Loading behavior="fillPageHeight" />;
}
Expand Down
12 changes: 9 additions & 3 deletions demo/admin/src/products/highlights/ProductHighlightForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ export function ProductHighlightForm({ id }: FormProps) {
},
});
const handleSubmit = async ({ productCategory, ...formValues }: FormValues, form: FormApi<FormValues>, event: FinalFormSubmitEvent) => {
if (await saveConflict.checkForConflicts()) throw new Error("Conflicts detected");
if (await saveConflict.checkForConflicts()) {
throw new Error("Conflicts detected");
}
const output = {
...formValues,
product: formValues.product?.id,
};
if (mode === "edit") {
if (!id) throw new Error();
if (!id) {
throw new Error();
}
const { ...updateInput } = output;
await client.mutate<GQLUpdateProductHighlightMutation, GQLUpdateProductHighlightMutationVariables>({
mutation: updateProductHighlightMutation,
Expand All @@ -101,7 +105,9 @@ export function ProductHighlightForm({ id }: FormProps) {
}
}
};
if (error) throw error;
if (error) {
throw error;
}
if (loading) {
return <Loading behavior="fillPageHeight" />;
}
Expand Down
4 changes: 3 additions & 1 deletion demo/admin/src/products/highlights/ProductHighlightsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export function ProductHighlightsGrid() {
},
});
const rowCount = useBufferedRowCount(data?.productHighlights.totalCount);
if (error) throw error;
if (error) {
throw error;
}
const rows = data?.productHighlights.nodes ?? [];
return (
<DataGridPro
Expand Down
12 changes: 9 additions & 3 deletions demo/admin/src/products/tags/ProductTagForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ export function ProductTagForm({ id }: FormProps) {
},
});
const handleSubmit = async (formValues: FormValues, form: FormApi<FormValues>, event: FinalFormSubmitEvent) => {
if (await saveConflict.checkForConflicts()) throw new Error("Conflicts detected");
if (await saveConflict.checkForConflicts()) {
throw new Error("Conflicts detected");
}
const output = {
...formValues,
};
if (mode === "edit") {
if (!id) throw new Error();
if (!id) {
throw new Error();
}
const { ...updateInput } = output;
await client.mutate<GQLUpdateProductTagMutation, GQLUpdateProductTagMutationVariables>({
mutation: updateProductTagMutation,
Expand All @@ -76,7 +80,9 @@ export function ProductTagForm({ id }: FormProps) {
}
}
};
if (error) throw error;
if (error) {
throw error;
}
if (loading) {
return <Loading behavior="fillPageHeight" />;
}
Expand Down
4 changes: 3 additions & 1 deletion demo/admin/src/products/tags/ProductTagsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export function ProductTagsGrid() {
},
});
const rowCount = useBufferedRowCount(data?.productTags.totalCount);
if (error) throw error;
if (error) {
throw error;
}
const rows = data?.productTags.nodes ?? [];
return (
<DataGridPro
Expand Down
12 changes: 9 additions & 3 deletions demo/api/src/auth/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ import { staticUsers } from "./static-users";
@Injectable()
export class UserService implements UserPermissionsUserServiceInterface, JwtToUserServiceInterface {
convertJwtToUser(jwt: JwtPayload): User {
if (!jwt.sub) throw new Error("JWT does not contain sub");
if (!jwt.sub) {
throw new Error("JWT does not contain sub");
}
const user = this.getUser(jwt.sub);
if (!user) throw new Error(`User not found: ${jwt.sub}`);
if (!user) {
throw new Error(`User not found: ${jwt.sub}`);
}
return user;
}
getUser(id: string): User {
const index = parseInt(id) - 1;
if (staticUsers[index]) return staticUsers[index];
if (staticUsers[index]) {
return staticUsers[index];
}
throw new Error("User not found");
}
findUsers(args: FindUsersArgs): Users {
Expand Down
4 changes: 3 additions & 1 deletion demo/api/src/db/fixtures/generators/image-fixture.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export class ImageFixtureService {
this.svgImageFiles.push(await this.filesService.upload(file, { scope }));
count++;

if (count === maximumImageCount) break;
if (count === maximumImageCount) {
break;
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions demo/api/src/open-telemetry/api-metrics.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@ export class ApiMetricsMiddleware implements NestMiddleware {
}

private getStatusCodeClass(code: number): string {
if (code < 200) return "info";
if (code < 300) return "success";
if (code < 400) return "redirect";
if (code < 500) return "client_error";
if (code < 200) {
return "info";
}
if (code < 300) {
return "success";
}
if (code < 400) {
return "redirect";
}
if (code < 500) {
return "client_error";
}
return "server_error";
}
}
Loading