Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ tests/**/tmp/

# Logs
*.log

articles/
118 changes: 113 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ A collection of reusable git hook scripts for automating code quality checks and

## Features

- **JavaScript/TypeScript**: ESLint, Prettier, TypeScript type checking, Vitest test runner, test existence validation
- **Python**: Flake8 linting, Mypy static analysis, Pytest runner, service test validation (local and Docker modes)
- **PHP/Laravel**: PHPStan analysis with progressive error reduction, Pint code style fixing, test coverage validation
- **Docker**: Dockerfile linting with Hadolint
- **Shell**: Script validation with ShellCheck
Expand All @@ -17,6 +19,33 @@ A collection of reusable git hook scripts for automating code quality checks and

## Available Scripts

### JavaScript / TypeScript

| Script | Description |
|--------|-------------|
| `javascript/check_eslint_all.sh` | Runs ESLint with `--fix` across the entire project (`app/`, `components/`, `lib/`, `types/`). |
| `javascript/check_prettier.sh` | Runs Prettier on staged `.ts` files passed as arguments. |
| `javascript/check_prettier_all.sh` | Runs Prettier on all TypeScript files using glob patterns. |
| `javascript/check_tsc_all.sh` | Runs TypeScript type checking via `tsconfig.check.json`. |
| `javascript/check_vitest.sh` | Runs Vitest for specified files or the full suite. Supports `--watch` and `--coverage`. |
| `javascript/check_vitest_all.sh` | Runs the full Vitest test suite. |
| `javascript/check_tests.sh` | Runs Vitest only for changed/staged TypeScript files, auto-discovers matching test files. |
| `javascript/check_tests_all.sh` | Runs the full Vitest test suite (simple wrapper). |
| `javascript/check_test_coverage.sh` | Runs Vitest with optional `--watch` and `--coverage` flags. |
| `javascript/check_tests_exist.sh` | Validates that each staged TypeScript source file has a corresponding `tests/...test.ts` file. |

### Python

| Script | Description |
|--------|-------------|
| `python/check_flake8.sh` | Runs Flake8 locally on Python files (line length 120). |
| `python/check_flake8_in_docker.sh` | Runs Flake8 inside the `app_dev` Docker container. |
| `python/check_mypy.sh` | Runs Mypy locally on changed `app/*.py` files. |
| `python/check_mypy_in_docker.sh` | Runs Mypy inside the Docker container, maps host/container paths. |
| `python/check_pytest.sh` | Runs the full Pytest suite locally with `PYTHONPATH=./app`. |
| `python/check_pytest_in_docker.sh` | Runs Pytest inside the Docker container, converts container paths to host paths. |
| `python/find_test.sh` | Validates that each service in `app/services/` has exactly one corresponding test file. |

### PHP

| Script | Description |
Expand Down Expand Up @@ -49,6 +78,56 @@ A collection of reusable git hook scripts for automating code quality checks and

## Usage Examples

### JavaScript/TypeScript

```bash
# ESLint — fix entire project
./javascript/check_eslint_all.sh

# Prettier — format specific files
./javascript/check_prettier.sh app/utils.ts lib/helpers.ts

# TypeScript type check
./javascript/check_tsc_all.sh

# Run tests for changed files (auto-discovers matching test files)
./javascript/check_tests.sh app/utils.ts app/helpers.ts

# Run Vitest with coverage
./javascript/check_vitest.sh --coverage

# Run Vitest for specific files in watch mode
./javascript/check_vitest.sh app/utils.ts --watch

# Verify test files exist for staged sources
./javascript/check_tests_exist.sh app/utils.ts components/Header.tsx
```

### Python

```bash
# Flake8 — local
./python/check_flake8.sh app/services/user_service.py app/routes/api.py

# Flake8 — in Docker
./python/check_flake8_in_docker.sh app/services/user_service.py

# Mypy — local
./python/check_mypy.sh app/services/auth.py app/models/user.py

# Mypy — in Docker
./python/check_mypy_in_docker.sh app/services/auth.py

# Pytest — local
./python/check_pytest.sh

# Pytest — in Docker
./python/check_pytest_in_docker.sh

# Verify test files exist for services
./python/find_test.sh app/services/user_service.py app/services/auth.py
```

### PHPStan with Progressive Error Reduction

```bash
Expand Down Expand Up @@ -85,12 +164,33 @@ A collection of reusable git hook scripts for automating code quality checks and
#!/bin/bash
# .git/hooks/pre-commit

set -e

FILES=$(git diff --cached --name-only --diff-filter=ACM)
PHP_FILES=$(echo "$FILES" | grep '\.php$')
SH_FILES=$(echo "$FILES" | grep '\.sh$')

[[ -n "$PHP_FILES" ]] && ./php/check_phpstan.sh default $PHP_FILES
[[ -n "$SH_FILES" ]] && ./scripts/check_shellcheck.sh $SH_FILES
# JavaScript/TypeScript
bash javascript/check_eslint_all.sh
bash javascript/check_prettier.sh $FILES
bash javascript/check_tests_exist.sh $FILES
bash javascript/check_tests.sh $FILES

# Python (local)
bash python/check_flake8.sh $FILES
bash python/check_mypy.sh $FILES
bash python/find_test.sh $FILES

# Python (Docker) — use instead of local variants if project runs in Docker
# bash python/check_flake8_in_docker.sh $FILES
# bash python/check_mypy_in_docker.sh $FILES
# bash python/check_pytest_in_docker.sh

# PHP
PHP_FILES=$(echo "$FILES" | grep '\.php$' || true)
[[ -n "$PHP_FILES" ]] && bash php/check_phpstan.sh default $PHP_FILES

# Shell
SH_FILES=$(echo "$FILES" | grep '\.sh$' || true)
[[ -n "$SH_FILES" ]] && bash scripts/check_shellcheck.sh $SH_FILES
```

## Testing
Expand All @@ -101,15 +201,23 @@ SH_FILES=$(echo "$FILES" | grep '\.sh$')

# Run specific test suite
./tests/php/phpstan/run.sh
./tests/javascript/tests_exist/run.sh
./tests/javascript/eslint_all/run.sh
./tests/javascript/vitest/run.sh
./tests/python/flake8/run.sh
./tests/python/mypy/run.sh
./tests/python/find_test/run.sh
```

## Requirements

- Bash 4.0+
- Git
- jq
- Node.js with npx (for JavaScript/TypeScript hooks)
- Python 3, Flake8, Mypy, Pytest (for Python hooks)
- PHP 8.1+ with Composer (for PHP hooks)
- Docker (optional)
- Docker (optional, for Docker-based hooks)
- ShellCheck (for shell validation)

## License
Expand Down