From 6ee53cbf68d4f8b3ef97da6b71229dd86b972dfe Mon Sep 17 00:00:00 2001 From: bugman-007 Date: Thu, 12 Mar 2026 04:02:03 -0400 Subject: [PATCH 1/2] ci: add pre-commit hooks for code quality Adds comprehensive pre-commit hooks for automated code quality checks: Hooks added: - shellcheck: Lints shell scripts (excludes SC1091, SC2034, SC2086) - ruff: Python linting (E, F, W checks, ignores E501 line length) - black: Python formatting (line-length=100) - trailing-whitespace, end-of-file-fixer - check-yaml, check-json Also updates CONTRIBUTING.md with pre-commit setup instructions. --- .pre-commit-config.yaml | 34 +++++++++++++++++++++++++++++++++- CONTRIBUTING.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) 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..8a269e47d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,6 +34,36 @@ 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 +``` + +**Note:** All Python files have been formatted with `black --line-length=100`. The pre-commit hooks will enforce this formatting going forward. + ## 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. From 31b1918b966f9b72f9f3beaf1c48c365a679b7d8 Mon Sep 17 00:00:00 2001 From: bugman-007 Date: Thu, 12 Mar 2026 22:34:21 +0100 Subject: [PATCH 2/2] fix: remove premature black formatting claim from CONTRIBUTING.md Addresses review feedback on PR #178. The statement about all Python files being formatted with black is only true after PR #177 merges. Removed the premature claim to avoid misleading contributors --- CONTRIBUTING.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8a269e47d..1082f21b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,8 +62,6 @@ To bypass hooks (not recommended): git commit --no-verify ``` -**Note:** All Python files have been formatted with `black --line-length=100`. The pre-commit hooks will enforce this formatting going forward. - ## 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.