|
1 | 1 | # .pre-commit-config.yaml |
2 | 2 | # See https://pre-commit.com/ |
| 3 | +default_stages: [commit] |
3 | 4 |
|
4 | | -# This file configures the pre-commit framework, listing hooks that run on staged files before commits. |
5 | | -# Ruff is configured to run the full set of enabled linting rules and formatting on files in the commit. |
6 | | - |
7 | | -# --- Default settings for hooks if not overridden --- |
8 | | -default_stages: [commit] # Run hooks by default on 'commit' stage |
9 | | - |
10 | | -# Exclude patterns for hooks (relative to project root). |
11 | | -# Ensure consistency with .gitignore. Hooks often have built-in excludes for standard dirs. |
12 | | -# exclude: ^docs/.*$ # Example exclude for documentation source files (handled by Ruff excludes often) |
13 | | - |
14 | | -# --- Repositories containing hooks --- |
15 | 5 | repos: |
16 | | - # Standard pre-commit hooks provided by the framework developers. |
17 | | - # See https://github.com/pre-commit/pre-commit-hooks |
18 | 6 | - repo: https://github.com/pre-commit/pre-commit-hooks |
19 | | - # Use a specific tag or commit hash (pinning for reproducibility). |
20 | | - rev: v4.6.0 # Update periodically to get newer hooks/fixes. |
| 7 | + rev: v4.6.0 |
21 | 8 | hooks: |
22 | | - # Prevent adding large files that should probably be in Git LFS or ignored. |
23 | 9 | - id: check-added-large-files |
24 | | - args: ["--max-size=1000000"] # Set max file size to 1MB (adjust as needed). |
25 | | - |
26 | | - # Check YAML files (e.g., CI workflows, Docker Compose) for syntax errors. |
| 10 | + args: ["--max-size=1000000"] |
27 | 11 | - id: check-yaml |
28 | | - |
29 | | - # Check TOML files (e.g., pyproject.toml, .ruff.toml) for syntax errors. |
30 | 12 | - id: check-toml |
31 | | - |
32 | | - # Ensure files end with a single newline and are not excessively blank at the end. |
33 | 13 | - id: end-of-file-fixer |
34 | | - |
35 | | - # Removes unwanted trailing whitespace from lines. |
36 | 14 | - id: trailing-whitespace |
37 | 15 |
|
38 | | - # Ruff hooks (Formatter and Linter checks) from Astral. |
39 | | - # See https://github.com/astral-sh/ruff-pre-commit |
40 | | - # Match the rev/version to the version of Ruff used in the template's pyproject.toml dependencies. |
41 | | - - repo: https://github.com/astral-sh/ruff-pre-commit # Official hooks from Astral (Ruff creator) |
42 | | - # Pin to the version of Ruff used in pyproject.toml (or a compatible version). |
43 | | - rev: v0.3.5 # **Ensure this matches/is compatible with the Ruff version in pyproject.toml** |
| 16 | + - repo: https://github.com/astral-sh/ruff-pre-commit |
| 17 | + rev: v0.3.5 |
44 | 18 | hooks: |
45 | | - # Run the Ruff formatter (covers code formatting and import sorting). |
46 | | - # Automatically fixes issues like line length, spacing, quotes, and sorts imports. |
47 | | - # Run this hook first so the linter doesn't report fixable style issues. |
48 | 19 | - id: ruff-format |
49 | | - # Explicitly point to the separate ruff config file. |
50 | | - args: [--config={{ PROJECT_SLUG }}/.ruff.toml] # Path relative to project root. |
| 20 | + args: [--config={{ PROJECT_SLUG }}/.ruff.toml] |
51 | 21 |
|
52 | | - # Run the Ruff linter. |
53 | | - # This hook runs the *full set of enabled linting rules* configured in .ruff.toml. |
54 | | - # Use --fix to automatically fix many lint issues. |
55 | | - # Use --exit-non-zero-on-fix to make the commit fail if any fixes were applied |
56 | | - # (prompts user to 'git add' and re-commit the corrected files). |
57 | 22 | - id: ruff |
58 | 23 | args: [--fix, --exit-non-zero-on-fix, --config={{ PROJECT_SLUG }}/.ruff.toml] |
59 | | - |
60 | | - |
61 | | - # --- Optional Hooks --- |
62 | | - # Add hooks for other tools if they are fast enough for pre-commit and needed. |
63 | | - # Ensure any tools used here are listed as development dependencies in pyproject.toml |
64 | | - # so pre-commit can install them. |
65 | | - |
66 | | -# Note: More time-consuming checks (e.g., full Pyright, comprehensive Bandit/pip-audit scans) |
67 | | -# are typically too slow for mandated pre-commit hooks across large projects. |
68 | | -# These are run via Task Automation (Nox) and enforced in CI. |
0 commit comments