Skip to content

Commit e0c625a

Browse files
authored
ci: Add Pre-commit hooks (#221)
https://pre-commit.com/
1 parent fad6601 commit e0c625a

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

.github/actions/spelling/excludes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@
8888
CHANGELOG.md
8989
noxfile.py
9090
^src/a2a/grpc/
91+
.pre-commit-config.yaml

.pre-commit-config.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
repos:
3+
# ===============================================
4+
# Pre-commit standard hooks (general file cleanup)
5+
# ===============================================
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v4.6.0
8+
hooks:
9+
- id: trailing-whitespace # Removes extra whitespace at the end of lines
10+
- id: end-of-file-fixer # Ensures files end with a newline
11+
- id: check-yaml # Checks YAML file syntax (before formatting)
12+
- id: check-toml # Checks TOML file syntax (before formatting)
13+
- id: check-added-large-files # Prevents committing large files
14+
args: [--maxkb=500] # Example: Limit to 500KB
15+
- id: check-merge-conflict # Checks for merge conflict strings
16+
- id: detect-private-key # Detects accidental private key commits
17+
18+
# Formatter and linter for TOML files
19+
- repo: https://github.com/ComPWA/taplo-pre-commit
20+
rev: v0.9.3
21+
hooks:
22+
- id: taplo-format
23+
- id: taplo-lint
24+
25+
# YAML files
26+
- repo: https://github.com/lyz-code/yamlfix
27+
rev: 1.16.1
28+
hooks:
29+
- id: yamlfix
30+
31+
# ===============================================
32+
# Python Hooks
33+
# ===============================================
34+
# no_implicit_optional for ensuring explicit Optional types
35+
- repo: https://github.com/hauntsaninja/no_implicit_optional
36+
rev: '1.4'
37+
hooks:
38+
- id: no_implicit_optional
39+
args: [--use-union-or]
40+
41+
# Pyupgrade for upgrading Python syntax to newer versions
42+
- repo: https://github.com/asottile/pyupgrade
43+
rev: v3.20.0
44+
hooks:
45+
- id: pyupgrade
46+
args: [--py310-plus] # Target Python 3.10+ syntax, matching project's target
47+
48+
# Autoflake for removing unused imports and variables
49+
- repo: https://github.com/pycqa/autoflake
50+
rev: v2.3.1
51+
hooks:
52+
- id: autoflake
53+
args: [--in-place, --remove-all-unused-imports]
54+
55+
# Ruff for linting and formatting
56+
- repo: https://github.com/astral-sh/ruff-pre-commit
57+
rev: v0.12.0
58+
hooks:
59+
- id: ruff # Linter: applies auto-fixable linting rules
60+
args: [--fix, --exit-zero] # Apply fixes, and exit with 0 even if files were modified
61+
- id: ruff-format # Formatter: similar to Black, handles consistent code style
62+
args: [] # Check formatting, but do not auto-fix during commit; fail if not formatted

.ruff.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# This file follows the standards in Google Python Style Guide
66
# https://google.github.io/styleguide/pyguide.html
7-
#
7+
#
88

99
line-length = 80 # Google Style Guide §3.2: 80 columns
1010
indent-width = 4 # Google Style Guide §3.4: 4 spaces
@@ -102,7 +102,6 @@ lines-between-types = 1
102102
[lint.pydocstyle]
103103
convention = "google"
104104
ignore-decorators = ["typing.overload", "abc.abstractmethod"]
105-
ignore-var-parameters = true
106105

107106
[lint.flake8-annotations]
108107
mypy-init-return = true

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ dev = [
8282
"uv-dynamic-versioning>=0.8.2",
8383
"types-protobuf",
8484
"types-requests",
85+
"pre-commit",
8586
]
8687

8788
[[tool.uv.index]]

0 commit comments

Comments
 (0)