-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
102 lines (94 loc) · 4.63 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
102 lines (94 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Run on every `git commit`. Install via `make hooks` (or
# `pre-commit install` directly). The hooks run on STAGED files only,
# so they're fast — typical commit = sub-second.
#
# To run against the whole tree manually:
# uvx pre-commit run --all-files
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.14
hooks:
- id: ruff # lint
args: [--fix]
- id: ruff-format # format
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
# Everything in scripts/ is POSIX sh (the curl|sh installer plus, for
# uniformity, the dev tooling). `-s sh` lints as POSIX, so a future
# bashism ([[, arrays, local, set -o pipefail, $BASH_SOURCE) fails here.
# shellcheck-py ships the binary via pip (no Docker needed per commit).
- id: shellcheck
args: [-s, sh]
files: ^scripts/.*\.sh$
- repo: local
hooks:
- id: check-branch-name
name: branch name convention
# Reject a commit on a branch that doesn't match <type>/<kebab-slug>.
# Same script CI runs, so local + CI agree ; main + detached HEAD
# (rebase) are skipped inside the script.
entry: ./scripts/check-branch-name.sh
language: system
pass_filenames: false
always_run: true
- id: check-whitespace
name: trailing whitespace + final newlines
# The repo's existing checker — scans tracked text files via git.
# `--fix` would mutate without staging the fix; keep check-only
# in the hook so the commit fails loudly.
entry: ./scripts/check-whitespace.sh
language: system
pass_filenames: false
always_run: true
- id: check-file-length
name: file length (350-line max for .py)
# Aggressive line cap; the message points the LLM (or human)
# at the right fix: split distinct concerns, convert long
# files into directory packages.
entry: ./scripts/check-file-length.sh
language: system
pass_filenames: false
always_run: true
- id: ty
name: ty type check (core + shared schema + schema_sync)
# ty is a WHOLE-PROGRAM checker: a change in one file can break types in
# another, so we check the same targets as `make local-types` and CI
# (pass_filenames: false) instead of only staged files. Same SCOPE, not
# the same literal command: --no-sync reuses the dev's already-synced
# env, where local-types/CI use `--package openmagpie-core`; the set of
# files checked is identical, which is what keeps them in agreement.
entry: uv run --no-sync ty check apps/core packages/openmagpie-schema tools/schema_sync
language: system
types_or: [python]
pass_filenames: false
require_serial: true
- id: schema-sync
name: schema.json is fresh
# The committed JSON Schema is generated from the Pydantic models
# (the web client generates its validators from it). A model change
# that isn't regenerated would silently drift the schema, so fail like
# `uv lock --locked`: regenerate in memory and diff. Fix with
# `make local-schema` (or `uv run --no-sync python -m tools.schema_sync.generate`).
entry: uv run --no-sync python -m tools.schema_sync.generate --check
language: system
# Fire on a change to the generator, to a model, or a hand-edit of the
# artifact (so reverting/corrupting only schema.json still trips the
# guard, which types_or: [python] would miss). CI runs the same --check
# unconditionally as a backstop.
files: '^(tools/schema_sync/.*\.py|packages/openmagpie-schema/(.*\.py|schema\.json))$'
pass_filenames: false
require_serial: true
- id: web-schema
name: web generated.ts is fresh
# Hop 2 of the contract: schema.json -> web zod (packages/schema/src/generated.ts).
# Hop 1 (Pydantic -> schema.json) is guarded by `schema-sync` above; without
# this, a schema.json change (or a hand-edit of the generator / output) could
# silently leave the web validators stale. Regenerate in memory and diff, same
# as schema-sync. Fix with `pnpm --filter @magpie/schema generate` (in web/).
# Needs pnpm/node; CI runs the same --check as a backstop for anyone without them.
entry: bash -c 'cd web && pnpm --filter @magpie/schema check'
language: system
files: '^(packages/openmagpie-schema/schema\.json|web/packages/schema/(scripts/generate\.mjs|src/generated\.ts))$'
pass_filenames: false
require_serial: true