chore: Add Stricter Frontend Formatting (#6262)

This commit is contained in:
Michael Genson
2025-09-27 13:57:53 -05:00
committed by GitHub
parent ecdf7de386
commit d16a10440d
52 changed files with 945 additions and 818 deletions

View File

@@ -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()

View File

@@ -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__":

View File

@@ -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}")

View File

@@ -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