diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cc65c1747..e16bd7f54 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,16 +1,48 @@ -# Pre-commit hooks for secret scanning +# Pre-commit hooks for DreamServer # Install: pip install pre-commit && pre-commit install # Run manually: pre-commit run --all-files repos: + # Secret scanning - repo: https://github.com/gitleaks/gitleaks rev: v8.21.2 hooks: - id: gitleaks + # Shell script linting + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.10.0.1 + hooks: + - id: shellcheck + args: ["--exclude=SC1091,SC2034,SC2086", "--severity=error"] + files: \.sh$ + + # Python linting with Ruff + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 + hooks: + - id: ruff + args: ["--select", "E,F,W", "--ignore", "E501"] + files: ^dream-server/.*\.py$ + + # Python formatting with Black + - repo: https://github.com/psf/black + rev: 24.3.0 + hooks: + - id: black + args: ["--line-length=100"] + files: ^dream-server/.*\.py$ + + # General file checks - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: - id: detect-private-key - id: check-added-large-files args: ['--maxkb=500'] + - id: trailing-whitespace + exclude: \.md$ + - id: end-of-file-fixer + - id: check-yaml + args: ["--unsafe"] + - id: check-json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4a60d5344..1082f21b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,6 +34,34 @@ Nothing exotic: - **Python** uses standard formatting (we're not picky -- just be consistent with the file you're editing). - Keep things readable. Comments are welcome where intent isn't obvious. +## Pre-commit Hooks + +This project uses pre-commit hooks to ensure code quality. To set up: + +```bash +pip install pre-commit +pre-commit install +``` + +The hooks will run automatically on `git commit` and check for: +- Secret leaks (gitleaks) +- Shell script issues (shellcheck) +- Python linting (ruff) +- Python formatting (black) +- Large files, trailing whitespace, YAML/JSON syntax + +To run hooks manually on all files: + +```bash +pre-commit run --all-files +``` + +To bypass hooks (not recommended): + +```bash +git commit --no-verify +``` + ## Pull Request Process 1. **Describe your changes** in the PR description. A sentence or two is fine for small changes; more detail helps for larger ones.