.pre-commit-config.yaml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Pre-commit hooks for BamBuddy
  2. # Install with: pip install pre-commit && pre-commit install
  3. repos:
  4. # Ruff - Fast Python linter and formatter
  5. - repo: https://github.com/astral-sh/ruff-pre-commit
  6. rev: v0.14.11
  7. hooks:
  8. # Linter
  9. - id: ruff
  10. args: [--fix, --exit-non-zero-on-fix]
  11. types_or: [python, pyi]
  12. # Formatter
  13. - id: ruff-format
  14. types_or: [python, pyi]
  15. # Standard pre-commit hooks
  16. - repo: https://github.com/pre-commit/pre-commit-hooks
  17. rev: v5.0.0
  18. hooks:
  19. - id: trailing-whitespace
  20. # Exclude static/ (build output) so whitespace normalisation
  21. # doesn't drift the files away from upstream.
  22. exclude: ^static/
  23. - id: end-of-file-fixer
  24. # .basedpyright/baseline.json is written by basedpyright without a final
  25. # newline, and rewritten by it whenever an error is fixed.
  26. exclude: ^(static/|\.basedpyright/)
  27. - id: check-yaml
  28. - id: check-json
  29. exclude: ^(static/|frontend/tsconfig\.)
  30. - id: check-added-large-files
  31. args: ['--maxkb=1000']
  32. # CHANGELOG.md is intentionally large (detailed per-release entries over
  33. # many versions); exempt it while keeping the 1 MB guard for everything else.
  34. #
  35. # backend/tests/.test_durations is ~1.5 MB and cannot be made smaller:
  36. # its 11703 pytest node IDs are 1160 kB of keys before a single duration
  37. # value is written, so no encoding fits under the guard (compact JSON
  38. # with 3-decimal values still measures 1263 kB). Pruning fast tests is
  39. # worse than useless -- pytest-split gives a test missing from the file
  40. # the AVERAGE of the entries that remain, so dropped 1 ms tests come back
  41. # weighted at ~89 ms and the balance it exists to provide degrades.
  42. # It compresses to ~314 kB in the object store. Regenerate with
  43. # --store-durations; see the backend test job in .github/workflows/ci.yml.
  44. #
  45. # The label fonts in backend/app/data/fonts are embedded in label PDFs.
  46. # The CJK fallbacks (#3560) cannot fit under the guard: Droid Sans
  47. # Fallback is 4 MB of mostly Chinese, and Noto Sans KR is already cut
  48. # down to Hangul alone (2.4 MB). A PDF embeds only the glyphs it uses.
  49. exclude: ^(static/assets/|CHANGELOG\.md$|backend/tests/\.test_durations$|backend/app/data/fonts/[^/]+\.ttf$)
  50. - id: check-merge-conflict
  51. - id: debug-statements
  52. - id: detect-private-key
  53. # Check for import shadowing (custom)
  54. - repo: local
  55. hooks:
  56. - id: check-import-shadowing
  57. name: Check for dangerous import shadowing
  58. entry: python -m pytest backend/tests/unit/test_code_quality.py::TestImportShadowing -v --tb=short
  59. language: system
  60. pass_filenames: false
  61. types: [python]
  62. files: ^backend/app/
  63. - id: frontend-typecheck
  64. name: TypeScript type check
  65. entry: bash -c 'cd frontend && npm run typecheck'
  66. language: system
  67. pass_filenames: false
  68. files: ^frontend/src/
  69. types_or: [ts, tsx]