Files
trailofbits-buttercup/.pre-commit-config.yaml
Dan Guido 7ab5da641e feat: add pre-commit infrastructure for code quality (#311)
* feat: add minimal pre-commit infrastructure

- Add pre-commit configuration with essential checks only
- Check YAML, TOML, JSON syntax
- Check for merge conflicts and large files
- Enforce LF line endings (fix 2 test files with CRLF)
- Add debug statement detection
- Integrate ruff for Python formatting and linting
- Add GitHub workflow for pre-commit CI
- No unnecessary Python code changes

* fix: add explicit permissions to pre-commit workflow

- Set GITHUB_TOKEN permissions to read-only for contents
- Follows principle of least privilege
- Addresses CodeQL security recommendation
- Pre-commit checks only need to read code, not write

* fix: exclude test data from line ending modifications

- Exclude .proto files and test/data directories from mixed-line-ending hook
- Revert changes to test data files (traced_crash.proto, java_stacktrace.txt)
- These files need to preserve their original format for test integrity
- Binary proto files could be corrupted by line ending changes

* docs: add pre-commit hooks documentation to CONTRIBUTING.md

- Add pre-commit installation instructions to development setup
- Document pre-commit hooks in Code Quality Standards section
- Update submission workflow to include pre-commit checks
- Provide manual pre-commit run commands for contributors

* docs: streamline CONTRIBUTING.md for better readability

- Reduce from 214 to 124 lines (42% reduction) while keeping all essential info
- Consolidate setup instructions into concise Quick Start section
- Convert component descriptions to scannable table format
- Streamline testing strategy with clear requirements and timing
- Add back critical testing prerequisites (codequery, ripgrep, cscope)
- Create actionable Getting Help section with common troubleshooting
- Remove redundant command listings and verbose explanations
- Maintain all security requirements and essential workflows
2025-08-22 16:42:23 -04:00

54 lines
1.3 KiB
YAML

# Pre-commit hooks for Buttercup CRS
# See https://pre-commit.com for more information
repos:
# Standard file fixes
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-yaml
args: [--allow-multiple-documents]
exclude: 'deployment/k8s/.*\.(yaml|yml)$'
- id: check-added-large-files
args: [--maxkb=1000]
- id: check-merge-conflict
- id: mixed-line-ending
args: [--fix=lf]
exclude: '(\.proto$|test/data/|tests/data/)'
- id: check-toml
- id: check-json
- id: debug-statements
# Ruff - Python linting and formatting
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.0
hooks:
# Run the formatter first
- id: ruff-format
types_or: [python, pyi]
# Then run the linter with auto-fix
- id: ruff
types_or: [python, pyi]
args: [--fix, --exit-non-zero-on-fix]
# Global exclusions for files that should never be checked
exclude: |
(?x)^(
external/.*|
.*\.pb\.py|
.*_pb2\.py|
.*_pb2_grpc\.py|
.*/\.venv/.*|
.*/\.mypy_cache/.*|
.*/\.ruff_cache/.*|
.*/\.pytest_cache/.*|
__pycache__/.*|
.*\.egg-info/.*
)$
# Configuration
fail_fast: false
ci:
autofix_prs: true
autoupdate_schedule: weekly