From d16a10440dd64e7962254c059357325483549919 Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Sat, 27 Sep 2025 13:57:53 -0500 Subject: [PATCH] chore: Add Stricter Frontend Formatting (#6262) --- .vscode/settings.json | 5 +- .../gen_py_pytest_data_paths.py | 7 +- dev/code-generation/gen_py_schema_exports.py | 12 +- dev/code-generation/gen_ts_types.py | 10 + dev/code-generation/utils/template.py | 8 +- .../Domain/Cookbook/CookbookPage.vue | 6 +- .../Household/HouseholdPreferencesEditor.vue | 78 ++-- .../components/Domain/QueryFilterBuilder.vue | 6 +- .../Domain/Recipe/RecipeActionMenu.vue | 19 +- .../components/Domain/Recipe/RecipeCard.vue | 182 ++++---- .../Domain/Recipe/RecipeCardMobile.vue | 2 +- .../RecipeContextMenuContent.vue | 2 +- .../Recipe/RecipeDataAliasManagerDialog.vue | 30 +- .../Domain/Recipe/RecipePage/RecipePage.vue | 10 +- .../RecipePageEditorToolbar.vue | 38 +- .../RecipePageParts/RecipePageFooter.vue | 4 +- .../RecipePageParts/RecipePageInfoCard.vue | 8 +- .../RecipePageIngredientEditor.vue | 1 - .../RecipePageParts/RecipePageParseDialog.vue | 14 +- .../Domain/Recipe/RecipePrintView.vue | 115 ++--- .../components/Domain/Recipe/RecipeRating.vue | 6 +- .../ShoppingList/ShoppingListItemEditor.vue | 12 +- frontend/components/Layout/DefaultLayout.vue | 2 +- .../Layout/LayoutParts/AppSidebar.vue | 52 ++- frontend/components/global/AutoForm.vue | 3 +- frontend/components/global/BaseDialog.vue | 4 +- frontend/components/global/SafeMarkdown.vue | 4 +- .../composables/recipe-page/shared-state.ts | 16 +- .../composables/use-group-recipe-actions.ts | 4 +- .../composables/use-query-filter-builder.ts | 24 +- .../use-shopping-list-item-actions.ts | 4 +- frontend/eslint.config.mjs | 27 +- frontend/layouts/error.vue | 29 +- frontend/lib/api/types/admin.ts | 2 +- frontend/lib/api/types/analytics.ts | 2 +- frontend/lib/api/types/cookbook.ts | 2 +- frontend/lib/api/types/household.ts | 2 +- frontend/lib/api/types/labels.ts | 2 +- frontend/lib/api/types/meal-plan.ts | 2 +- frontend/lib/api/types/non-generated.ts | 12 +- frontend/lib/api/types/reports.ts | 2 +- frontend/lib/api/types/response.ts | 2 +- frontend/lib/api/types/user.ts | 2 +- frontend/pages/admin/maintenance/index.vue | 22 +- frontend/pages/admin/setup.vue | 403 +++++++++--------- .../pages/g/[groupSlug]/r/create/bulk.vue | 274 ++++++------ frontend/pages/household/index.vue | 193 ++++----- .../pages/household/mealplan/planner/edit.vue | 11 +- .../pages/household/mealplan/planner/view.vue | 22 +- frontend/pages/shopping-lists/index.vue | 50 +-- frontend/pages/user/profile/api-tokens.vue | 8 +- frontend/types/auth.d.ts | 6 +- 52 files changed, 945 insertions(+), 818 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 61ab0e239..760c44b5c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -59,8 +59,11 @@ "netlify.toml": "runtime.txt", "README.md": "LICENSE, SECURITY.md" }, + "[typescript]": { + "editor.formatOnSave": true + }, "[vue]": { - "editor.formatOnSave": false + "editor.formatOnSave": true }, "[python]": { "editor.formatOnSave": true, diff --git a/dev/code-generation/gen_py_pytest_data_paths.py b/dev/code-generation/gen_py_pytest_data_paths.py index 02313d819..53a75fee5 100644 --- a/dev/code-generation/gen_py_pytest_data_paths.py +++ b/dev/code-generation/gen_py_pytest_data_paths.py @@ -1,3 +1,4 @@ +import subprocess from dataclasses import dataclass from pathlib import Path @@ -105,12 +106,16 @@ def main(): # Flatten list of lists all_children = [item for sublist in all_children for item in sublist] + out_path = GENERATED / "__init__.py" render_python_template( TEMPLATE, - GENERATED / "__init__.py", + out_path, {"children": all_children}, ) + subprocess.run(["poetry", "run", "ruff", "check", str(out_path), "--fix"]) + subprocess.run(["poetry", "run", "ruff", "format", str(out_path)]) + if __name__ == "__main__": main() diff --git a/dev/code-generation/gen_py_schema_exports.py b/dev/code-generation/gen_py_schema_exports.py index 20da4a523..e7eb6c3ae 100644 --- a/dev/code-generation/gen_py_schema_exports.py +++ b/dev/code-generation/gen_py_schema_exports.py @@ -1,5 +1,6 @@ import pathlib import re +import subprocess from dataclasses import dataclass, field from utils import PROJECT_DIR, log, render_python_template @@ -84,16 +85,23 @@ def find_modules(root: pathlib.Path) -> list[Modules]: return modules -def main(): +def main() -> None: modules = find_modules(SCHEMA_PATH) + template_paths: list[pathlib.Path] = [] for module in modules: log.debug(f"Module: {module.directory.name}") for file in module.files: log.debug(f" File: {file.import_path}") log.debug(f" Classes: [{', '.join(file.classes)}]") - render_python_template(template, module.directory / "__init__.py", {"module": module}) + template_path = module.directory / "__init__.py" + template_paths.append(template_path) + render_python_template(template, template_path, {"module": module}) + + path_args = (str(p) for p in template_paths) + subprocess.run(["poetry", "run", "ruff", "check", *path_args, "--fix"]) + subprocess.run(["poetry", "run", "ruff", "format", *path_args]) if __name__ == "__main__": diff --git a/dev/code-generation/gen_ts_types.py b/dev/code-generation/gen_ts_types.py index 8a8932299..69c0d749e 100644 --- a/dev/code-generation/gen_ts_types.py +++ b/dev/code-generation/gen_ts_types.py @@ -1,4 +1,5 @@ import re +import subprocess from pathlib import Path from jinja2 import Template @@ -189,6 +190,7 @@ def generate_typescript_types() -> None: # noqa: C901 skipped_dirs: list[Path] = [] failed_modules: list[Path] = [] + out_paths: list[Path] = [] for module in schema_path.iterdir(): if module.is_dir() and module.stem in ignore_dirs: skipped_dirs.append(module) @@ -205,10 +207,18 @@ def generate_typescript_types() -> None: # noqa: C901 path_as_module = path_to_module(module) generate_typescript_defs(path_as_module, str(out_path), exclude=("MealieModel")) # type: ignore clean_output_file(out_path) + out_paths.append(out_path) except Exception: failed_modules.append(module) log.exception(f"Module Error: {module}") + # Run ESLint --fix on the files to clean up any formatting issues + subprocess.run( + ["yarn", "lint", "--fix", *(str(path) for path in out_paths)], + check=True, + cwd=PROJECT_DIR / "frontend", + ) + log.debug("\nšŸ“ Skipped Directories:") for skipped_dir in skipped_dirs: log.debug(f" šŸ“ {skipped_dir.name}") diff --git a/dev/code-generation/utils/template.py b/dev/code-generation/utils/template.py index 32ecf9c47..9d8724345 100644 --- a/dev/code-generation/utils/template.py +++ b/dev/code-generation/utils/template.py @@ -1,5 +1,4 @@ import logging -import subprocess from dataclasses import dataclass from pathlib import Path @@ -23,11 +22,6 @@ def render_python_template(template_file: Path | str, dest: Path, data: dict): dest.write_text(text) - # lint/format file with Ruff - log.info(f"Formatting {dest}") - subprocess.run(["poetry", "run", "ruff", "check", str(dest), "--fix"]) - subprocess.run(["poetry", "run", "ruff", "format", str(dest)]) - @dataclass class CodeSlicer: @@ -37,7 +31,7 @@ class CodeSlicer: indentation: str | None text: list[str] - _next_line = None + _next_line: int | None = None def purge_lines(self) -> None: start = self.start + 1 diff --git a/frontend/components/Domain/Cookbook/CookbookPage.vue b/frontend/components/Domain/Cookbook/CookbookPage.vue index 2267276cc..71c751a68 100644 --- a/frontend/components/Domain/Cookbook/CookbookPage.vue +++ b/frontend/components/Domain/Cookbook/CookbookPage.vue @@ -32,9 +32,9 @@ >
- - {{ $globals.icons.pages }} - + + {{ $globals.icons.pages }} + {{ book.name }} -
- -
- -
-

- {{ $t("household.private-household-description") }} -

- -
-
-
- -
-

- {{ $t("household.lock-recipe-edits-from-other-households-description") }} -

-
-
- +
+ +
+ +
+

+ {{ $t("household.private-household-description") }} +

+ +
+
+
+ +
+

+ {{ $t("household.lock-recipe-edits-from-other-households-description") }} +

+
+
+ - -
-
- -

- {{ p.description }} -

-
-
-
+ +
+
+ +

+ {{ p.description }} +

+
+
+
diff --git a/frontend/pages/household/mealplan/planner/edit.vue b/frontend/pages/household/mealplan/planner/edit.vue index b399d8e6b..82ce3b176 100644 --- a/frontend/pages/household/mealplan/planner/edit.vue +++ b/frontend/pages/household/mealplan/planner/edit.vue @@ -14,7 +14,7 @@ if (newMeal.existing) { actions.updateOne({ ...newMeal, date: newMealDateString }); } - else { + else { actions.createOne({ ...newMeal, date: newMealDateString }); } resetDialog(); @@ -147,7 +147,14 @@