From a430284aa21e3ae1f0d5654e55b2ad2852519cc2 Mon Sep 17 00:00:00 2001
From: wwf <yearningwang@iqtogether.com>
Date: 星期三, 04 六月 2025 15:17:49 +0800
Subject: [PATCH] 初始化
---
.husky/pre-commit | 36 ++++++++++++++++++++----------------
1 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/.husky/pre-commit b/.husky/pre-commit
index 2ad3922..d9290e1 100644
--- a/.husky/pre-commit
+++ b/.husky/pre-commit
@@ -1,4 +1,6 @@
-#!/bin/sh
+#!/usr/bin/env bash
+. "$(dirname -- "$0")/_/husky.sh"
+
# get the list of modified files
files=$(git diff --cached --name-only)
@@ -9,17 +11,13 @@
for file in $files
do
- # Use POSIX compliant pattern matching
- case "$file" in
- api/*.py)
- # set api_modified flag to true
- api_modified=true
- ;;
- web/*)
- # set web_modified flag to true
- web_modified=true
- ;;
- esac
+ if [[ $file == "api/"* && $file == *.py ]]; then
+ # set api_modified flag to true
+ api_modified=true
+ elif [[ $file == "web/"* ]]; then
+ # set web_modified flag to true
+ web_modified=true
+ fi
done
# run linters based on the modified modules
@@ -27,11 +25,17 @@
if $api_modified; then
echo "Running Ruff linter on api module"
+ # python style checks rely on `ruff` in path
+ if ! command -v ruff &> /dev/null; then
+ echo "Installing linting tools (Ruff, dotenv-linter ...) ..."
+ poetry install -C api --only lint
+ fi
+
# run Ruff linter auto-fixing
- uv run --project api --dev ruff check --fix ./api
+ ruff check --fix ./api
# run Ruff linter checks
- uv run --project api --dev ruff check ./api || status=$?
+ ruff check --preview ./api || status=$?
status=${status:-0}
@@ -46,7 +50,7 @@
if $web_modified; then
echo "Running ESLint on web module"
cd ./web || exit 1
- lint-staged
+ npx lint-staged
echo "Running unit tests check"
modified_files=$(git diff --cached --name-only -- utils | grep -v '\.spec\.ts$' || true)
@@ -59,7 +63,7 @@
# check if the test file exists
if [ -f "../$test_file" ]; then
echo "Detected changes in $file, running corresponding unit tests..."
- pnpm run test "../$test_file"
+ npm run test "../$test_file"
if [ $? -ne 0 ]; then
echo "Unit tests failed. Please fix the errors before committing."
--
Gitblit v1.8.0