# Pre-commit hooks configuration for MIESC
# Implements Shift-Left Security by running checks before commits
#
# Installation:
#   pip install pre-commit
#   pre-commit install
#
# Usage:
#   pre-commit run --all-files  # Run all hooks manually
#   git commit -m "message"      # Hooks run automatically

repos:
  # Code Formatting
  - repo: https://github.com/psf/black
    rev: 24.1.1
    hooks:
      - id: black
        name: Black Code Formatter
        language_version: python3.9
        args: ['--line-length=100']

  # Fast Linting (Ruff)
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.1.14
    hooks:
      - id: ruff
        name: Ruff Linter
        args: ['--fix', '--exit-non-zero-on-fix']

  # Traditional Linting (Flake8)
  - repo: https://github.com/PyCQA/flake8
    rev: 7.0.0
    hooks:
      - id: flake8
        name: Flake8 Style Checker
        args: ['--max-line-length=100', '--ignore=E203,W503']

  # Security Scanning (Bandit)
  - repo: https://github.com/PyCQA/bandit
    rev: 1.7.6
    hooks:
      - id: bandit
        name: Bandit Security Scanner
        args: ['-r', 'src/', '-ll']  # Low-level severity
        exclude: ^tests/

  # Secret Scanning
  - repo: https://github.com/Yelp/detect-secrets
    rev: v1.4.0
    hooks:
      - id: detect-secrets
        name: Detect Hardcoded Secrets
        args: ['--baseline', '.secrets.baseline']
        exclude: tests/

  # YAML Validation
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: check-yaml
        name: Check YAML Syntax
      - id: check-json
        name: Check JSON Syntax
      - id: check-toml
        name: Check TOML Syntax
      - id: end-of-file-fixer
        name: Fix End of Files
      - id: trailing-whitespace
        name: Trim Trailing Whitespace
      - id: check-added-large-files
        name: Check for Large Files
        args: ['--maxkb=1000']
      - id: check-merge-conflict
        name: Check for Merge Conflicts
      - id: check-case-conflict
        name: Check for Case Conflicts

  # Python-specific checks
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: check-ast
        name: Check Python AST
      - id: check-docstring-first
        name: Check Docstring First
      - id: debug-statements
        name: Check for Debug Statements
      - id: name-tests-test
        name: Check Test Naming
        args: ['--pytest-test-first']

  # Type Checking (MyPy)
  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: v1.8.0
    hooks:
      - id: mypy
        name: MyPy Type Checker
        args: ['--ignore-missing-imports', '--show-error-codes']
        additional_dependencies:
          - 'types-requests'
          - 'types-PyYAML'
          - 'types-click'
        exclude: ^tests/

  # Markdown Linting
  - repo: https://github.com/igorshubovych/markdownlint-cli
    rev: v0.38.0
    hooks:
      - id: markdownlint
        name: Markdown Linter
        args: ['--fix']

  # Commit Message Validation
  - repo: https://github.com/commitizen-tools/commitizen
    rev: v3.13.0
    hooks:
      - id: commitizen
        name: Check Commit Message Format
        stages: [commit-msg]

# Configuration
default_language_version:
  python: python3.9

fail_fast: false  # Run all hooks even if one fails
minimum_pre_commit_version: '3.0.0'

# Exclude patterns
exclude: |
  (?x)^(
      venv/|
      .venv/|
      __pycache__/|
      \.git/|
      \.pytest_cache/|
      \.mypy_cache/|
      build/|
      dist/|
      \.egg-info/
  )
