|
1 | | -# REQ.PROJECT: This repository SHOULD include a .pre-commit-config.yaml when quality gates are required.# REQ: Any check that can be run locally MUST be available here.# WHY: Provide fast, consistent local checks aligned with upstream quality gates.# WHY: Keep local checks compatible with repository-wide formatting rules.# OBS: Formatting baselines are defined in# .editorconfig (whitespace/indentation) and# .gitattributes (EOL normalization).# OBS: These hooks do not override .editorconfig or .gitattributes;# they only prevent common diff noise and validate repository metadata.# ALT: Checks that are inherently non-local are handled upstream.# CUSTOM: Keep the hook set minimal and non-destructive for normative Markdown specs.## OPTIONAL LOCAL USAGE (no repo venv required):# Install uv (once, user-level).# uv self update# uvx pre-commit install# uvx pre-commit run --all-files## OBS: If a hook reports "files were modified", re-run last command to confirm a clean pass.## NOTE: pre-commit is optional.# Repositories do not require Python, uv, or pre-commit to clone or commit.exclude: | (?x)^( \.DS_Store| \.ipynb_checkpoints/| \.mypy_cache/| \.pytest_cache/| \.ruff_cache/| \.tox/| \.venv/| build/| dist/| node_modules/| site/ )repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 # OBS: v6 current as of Dec 30 2025 hooks: - id: check-added-large-files # OBS: prevent large binary files - id: trailing-whitespace # OBS: clean trailing whitespace per .editorconfig - id: end-of-file-fixer # OBS: ensure files end with a newline per .gitattributes - id: check-merge-conflict # OBS: prevent committing unresolved merge conflicts # WHY: Workflow files may intentionally include marker-like strings (e.g., >>>>). exclude: ^\.github/workflows/.*\.(yml|yaml)$ - id: check-yaml # OBS: validate YAML syntax files: \.(yml|yaml)$ - repo: https://github.com/adrienverge/yamllint rev: v1.37.1 # OBS: pinned for reproducibility hooks: - id: yamllint # OBS: validate YAML structure and policy (no line-length enforcement) args: [-c, .yamllint.yml] files: \.(yml|yaml)$ - repo: https://github.com/rhysd/actionlint rev: v1.7.10 # OBS: v1.7.10 current as of Dec 30 2025 hooks: - id: actionlint # OBS: validate GitHub Actions workflow syntax files: ^\.github/workflows/.*\.(yml|yaml)$# REQ.PROJECT: This repository SHOULD include a .pre-commit-config.yaml when quality gates are required. |
2 | | -# REQ: Any check that can be run locally MUST be available here. |
3 | | -# WHY: Provide fast, consistent local checks aligned with upstream quality gates. |
4 | | -# WHY: Keep local checks compatible with repository-wide formatting rules. |
5 | | -# OBS: Formatting baselines are defined in |
6 | | -# .editorconfig (whitespace/indentation) and |
7 | | -# .gitattributes (EOL normalization). |
8 | | -# OBS: These hooks do not override .editorconfig or .gitattributes; |
9 | | -# they only prevent common diff noise and validate repository metadata. |
10 | | -# ALT: Checks that are inherently non-local are handled upstream. |
11 | | -# CUSTOM: Keep the hook set minimal and non-destructive for normative Markdown specs. |
| 1 | +# ============================================================ |
| 2 | +# .pre-commit-config.yaml (Lean Hygiene) |
| 3 | +# ============================================================ |
| 4 | +# VARIANT: lean-hygiene |
| 5 | +# SOURCE: https://github.com/denisecase/templates |
| 6 | +# |
| 7 | +# REQ: Lean repos MAY include a .pre-commit-config.yaml for repo hygiene (optional). |
| 8 | +# WHY: Keep diffs clean across OSes and validate repo metadata files (TOML/YAML/JSON). |
| 9 | +# |
| 10 | +# OBS: These hooks use and do NOT override: |
| 11 | +# - .editorconfig (whitespace / indentation) |
| 12 | +# - .gitattributes (EOL normalization) |
| 13 | +# - tool configs (if present), e.g., lakefile.lean, pyproject.toml |
12 | 14 | # |
13 | 15 | # OPTIONAL LOCAL USAGE (no repo venv required): |
14 | 16 | # Install uv (once, user-level). |
15 | 17 | # uv self update |
16 | 18 | # uvx pre-commit install |
17 | | -# uvx pre-commit run --all-files |
18 | | -# |
19 | | -# OBS: If a hook reports "files were modified", re-run last command to confirm a clean pass. |
| 19 | +# uvx pre-commit run --all-files (just once, to check all files) |
| 20 | +# Subsequent commits will AUTOMATICALLY run pre-commit hooks after git add |
| 21 | +# and before git commit. |
20 | 22 | # |
21 | 23 | # NOTE: pre-commit is optional. |
22 | | -# Repositories do not require Python, uv, or pre-commit to clone or commit. |
| 24 | +# Repositories do NOT require Python, uv, or pre-commit to clone or commit. |
23 | 25 |
|
24 | 26 | exclude: | |
25 | 27 | (?x)^( |
26 | 28 | \.DS_Store| |
| 29 | + \.coverage| |
27 | 30 | \.ipynb_checkpoints/| |
28 | 31 | \.mypy_cache/| |
| 32 | + \.nox/| |
29 | 33 | \.pytest_cache/| |
30 | 34 | \.ruff_cache/| |
31 | 35 | \.tox/| |
32 | 36 | \.venv/| |
| 37 | + .*\.(egg-info)/| |
| 38 | + .*\.log| |
| 39 | + __pycache__/| |
| 40 | + _minted.*/| |
33 | 41 | build/| |
| 42 | + coverage\.xml| |
34 | 43 | dist/| |
| 44 | + htmlcov/| |
| 45 | + lake-packages/| |
35 | 46 | node_modules/| |
| 47 | + out/| |
36 | 48 | site/ |
37 | 49 | ) |
38 | 50 |
|
39 | 51 | repos: |
| 52 | + # === REPO: PRE-COMMIT HOOKS (cross-platform, zero config) === |
| 53 | + # |
| 54 | + # These hooks prevent problems that show up later as: |
| 55 | + # - mysterious diffs |
| 56 | + # - broken builds on another OS |
| 57 | + |
40 | 58 | - repo: https://github.com/pre-commit/pre-commit-hooks |
41 | 59 | rev: v6.0.0 |
42 | 60 | hooks: |
43 | | - - id: check-added-large-files # OBS: prevent large binary files |
44 | | - - id: trailing-whitespace # OBS: clean trailing whitespace per .editorconfig |
45 | | - - id: end-of-file-fixer # OBS: ensure files end with a newline per .gitattributes |
| 61 | + # === PRE-COMMIT: NORMALIZE FILE FORMATTING === |
46 | 62 |
|
47 | | - - id: mixed-line-ending # OBS: normalize line endings before linters run |
48 | | - # WHY: yamllint enforces LF; Windows working copies may be CRLF. |
49 | | - args: [--fix=lf] |
| 63 | + - id: trailing-whitespace |
| 64 | + name: A1) Clean trailing whitespace (per .editorconfig) |
| 65 | + args: [--markdown-linebreak-ext=md] # Preserves markdown double-space line breaks |
50 | 66 |
|
51 | | - - id: check-merge-conflict # OBS: prevent committing unresolved merge conflicts |
| 67 | + - id: end-of-file-fixer |
| 68 | + name: A2) End files with a newline (per .gitattributes) |
52 | 69 |
|
53 | | - - id: check-yaml # OBS: validate YAML syntax |
54 | | - files: \.(yml|yaml)$ |
| 70 | + - id: mixed-line-ending |
| 71 | + name: A3) Normalize line endings to LF before linters |
| 72 | + args: [--fix=lf] # OBS: Windows working copies may be CRLF. |
55 | 73 |
|
56 | | - - repo: https://github.com/adrienverge/yamllint |
57 | | - rev: v1.37.1 |
58 | | - hooks: |
59 | | - - id: yamllint # OBS: validate YAML structure and policy (no line-length enforcement) |
60 | | - args: [-c, .yamllint.yml] |
| 74 | + # === PRE-COMMIT: CHECK DATA FILE FORMATS === |
| 75 | + |
| 76 | + - id: check-json |
| 77 | + name: B1) Validate JSON syntax |
| 78 | + |
| 79 | + - id: check-toml |
| 80 | + name: B2) Validate TOML syntax |
| 81 | + |
| 82 | + - id: check-yaml |
| 83 | + name: B3) Validate YAML syntax |
61 | 84 | files: \.(yml|yaml)$ |
| 85 | + exclude: ^mkdocs\.ya?ml$ # OBS: mkdocs.yaml may include non-standard tags. |
62 | 86 |
|
63 | | - - repo: https://github.com/rhysd/actionlint |
64 | | - rev: v1.7.10 |
65 | | - hooks: |
66 | | - - id: actionlint # OBS: validate GitHub Actions workflow syntax |
67 | | - files: ^\.github/workflows/.*\.(yml|yaml)$ |
| 87 | + # === PRE-COMMIT:CHECK FOR COMMON PROBLEMS === |
| 88 | + |
| 89 | + - id: check-added-large-files |
| 90 | + name: C1) Prevent accidental commits of large binaries |
| 91 | + args: [--maxkb=500] |
| 92 | + |
| 93 | + - id: check-merge-conflict |
| 94 | + name: C2) Prevent committing merge conflicts |
| 95 | + |
| 96 | + - id: check-case-conflict |
| 97 | + name: C3) Check for filename case conflicts |
| 98 | + |
| 99 | +# === GLOBAL SETTINGS === |
| 100 | +# ALT: Set fail_fast to true to stop at first failure. |
| 101 | +fail_fast: false # Run all hooks even if one fails |
0 commit comments