From 7dc33124267b28dfbeddfd2e3c9490c41360e222 Mon Sep 17 00:00:00 2001 From: Pamella Bezerra Date: Wed, 12 Jun 2024 09:14:44 -0300 Subject: [PATCH] Add frontend-lint and frontend-tsc local hooks --- .pre-commit-config.yaml | 27 +++++++++++++++++++++++---- frontend/package.json | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e8e0a61..e507169 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,5 @@ fail_fast: true + repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 @@ -15,33 +16,51 @@ repos: - id: check-symlinks - id: debug-statements - id: detect-private-key + - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.1.6 + rev: v0.1.8 hooks: # Run the linter. - id: ruff args: [--fix] # Run the formatter. - id: ruff-format + - repo: local hooks: + - id: frontend-lint + name: run frontend lint + entry: sh -c 'cd frontend && npm run lint' + language: system + types: [file] + files: ^frontend/.*\.(js|jsx|ts|tsx)$ + pass_filenames: true + - id: frontend-tsc + name: run frontend tsc + entry: sh -c 'cd frontend && npm run tsc' + language: system + types: [file] + files: ^frontend/.*\.(ts|tsx)$ + pass_filenames: false - id: missing-migrations - name: missing-migrations-local + name: check missing migrations entry: poetry run python manage.py makemigrations --check language: system # Only run missing migration check if migration-generating files have changed: files: (.*/?(settings|migrations|models)/.+|.+models\.py|.+constants\.py|.+choices\.py|.+pyproject\.toml) pass_filenames: false - id: generate-openapi-schema - name: Generate OpenAPI schema + name: generate OpenAPI schema entry: poetry run python manage.py generate_openapi_schema --output frontend/openapi_schema.json language: system + # Only run OpenAPI schema generation if views.py has changed: files: views\.py$ pass_filenames: false - id: generate-frontend-client - name: Generate frontend client + name: generate frontend client entry: sh -c 'cd frontend && npm run generate-client' language: system + # Only run frontend client generation if frontend files have changed: files: openapi_schema\.json$ pass_filenames: false diff --git a/frontend/package.json b/frontend/package.json index df87a0d..586b927 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -37,6 +37,7 @@ "test:cov": "jest --coverage", "test:watch": "jest --watch", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "tsc": "tsc", "generate-client": "openapi-ts" }, "dependencies": {