.pre-commit-config.yaml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. exclude: ^(static/assets/|CHANGELOG\.md$|backend/tests/\.test_durations$)
  45. - id: check-merge-conflict
  46. - id: debug-statements
  47. - id: detect-private-key
  48. # Check for import shadowing (custom)
  49. - repo: local
  50. hooks:
  51. - id: check-import-shadowing
  52. name: Check for dangerous import shadowing
  53. entry: python -m pytest backend/tests/unit/test_code_quality.py::TestImportShadowing -v --tb=short
  54. language: system
  55. pass_filenames: false
  56. types: [python]
  57. files: ^backend/app/
  58. - id: frontend-typecheck
  59. name: TypeScript type check
  60. entry: bash -c 'cd frontend && npm run typecheck'
  61. language: system
  62. pass_filenames: false
  63. files: ^frontend/src/
  64. types_or: [ts, tsx]