Skip to content

Commit abb6c95

Browse files
feat: add comprehensive pre-commit hooks for code quality
Add comprehensive pre-commit configuration with: Pre-commit hooks: - General file hygiene (trailing whitespace, line endings, BOM) - File validation (YAML, JSON, TOML, XML, Python AST) - Git safety (merge conflicts, case conflicts, large files) - Security (detect private keys, gitleaks secret detection) Python tooling: - Ruff for linting and formatting (replaces black, flake8, isort) - Mypy for type checking - Bandit for security scanning Additional linters: - Yamllint for YAML files - Markdownlint for Markdown files - Actionlint for GitHub Actions workflows - Shellcheck for shell scripts - Typos for spell checking - Validate-pyproject for pyproject.toml Config files: - .pre-commit-config.yaml: Main pre-commit configuration - .yamllint.yaml: YAML linting rules - .markdownlint.yaml: Markdown linting rules - .typos.toml: Spell check exclusions for F5 XC API terms Applied formatting fixes from ruff and type hint updates. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d99b58d commit abb6c95

20 files changed

+1059
-572
lines changed

.markdownlint.yaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Markdownlint configuration
2+
# https://github.com/DavidAnson/markdownlint
3+
4+
# Default state for all rules
5+
default: true
6+
7+
# MD003 - Heading style (atx)
8+
MD003:
9+
style: atx
10+
11+
# MD004 - Unordered list style
12+
MD004:
13+
style: dash
14+
15+
# MD007 - Unordered list indentation
16+
MD007:
17+
indent: 2
18+
19+
# MD009 - Trailing spaces (allow 2 for line breaks)
20+
MD009:
21+
br_spaces: 2
22+
23+
# MD012 - Multiple consecutive blank lines
24+
MD012:
25+
maximum: 2
26+
27+
# MD013 - Line length
28+
MD013:
29+
line_length: 150
30+
code_blocks: false
31+
tables: false
32+
headings: false
33+
34+
# MD022 - Headings should be surrounded by blank lines
35+
MD022:
36+
lines_above: 1
37+
lines_below: 1
38+
39+
# MD024 - Multiple headings with the same content
40+
MD024:
41+
siblings_only: true
42+
43+
# MD025 - Single title/top-level heading
44+
MD025:
45+
front_matter_title: ""
46+
47+
# MD026 - Trailing punctuation in heading
48+
MD026:
49+
punctuation: ".,;:!?"
50+
51+
# MD029 - Ordered list item prefix (allow actual numbers)
52+
MD029:
53+
style: ordered
54+
55+
# MD030 - Spaces after list markers
56+
MD030:
57+
ul_single: 1
58+
ol_single: 1
59+
ul_multi: 1
60+
ol_multi: 1
61+
62+
# MD033 - Inline HTML (allow certain elements)
63+
MD033:
64+
allowed_elements:
65+
- br
66+
- details
67+
- summary
68+
- sub
69+
- sup
70+
- kbd
71+
- img
72+
73+
# MD035 - Horizontal rule style
74+
MD035:
75+
style: "---"
76+
77+
# MD041 - First line in file should be a top-level heading
78+
MD041: false
79+
80+
# MD046 - Code block style
81+
MD046:
82+
style: fenced
83+
84+
# MD036 - Emphasis used instead of heading (allow for generated docs)
85+
MD036: false
86+
87+
# MD040 - Fenced code blocks should have a language (warning only, not error)
88+
MD040: false
89+
90+
# MD048 - Code fence style
91+
MD048:
92+
style: backtick
93+
94+
# MD049 - Emphasis style
95+
MD049:
96+
style: asterisk
97+
98+
# MD050 - Strong style
99+
MD050:
100+
style: asterisk

.pre-commit-config.yaml

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# Pre-commit hooks for F5 XC API Spec Validation Framework
2+
# See https://pre-commit.com for more information
3+
# Run: pre-commit install && pre-commit run --all-files
4+
5+
default_install_hook_types: [pre-commit, commit-msg]
6+
default_stages: [pre-commit]
7+
8+
repos:
9+
# =============================================================================
10+
# General File Hygiene & Unix Standards
11+
# =============================================================================
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v5.0.0
14+
hooks:
15+
# Whitespace & Line Endings
16+
- id: trailing-whitespace
17+
args: [--markdown-linebreak-ext=md]
18+
- id: end-of-file-fixer
19+
- id: mixed-line-ending
20+
args: [--fix=lf]
21+
- id: fix-byte-order-marker
22+
23+
# File Validation
24+
- id: check-yaml
25+
args: [--unsafe]
26+
- id: check-json
27+
- id: check-toml
28+
- id: check-xml
29+
- id: check-ast
30+
- id: check-executables-have-shebangs
31+
- id: check-shebang-scripts-are-executable
32+
33+
# Git Safety
34+
- id: check-merge-conflict
35+
- id: check-case-conflict
36+
- id: check-added-large-files
37+
args: [--maxkb=1000]
38+
- id: no-commit-to-branch
39+
args: [--branch, main, --branch, master]
40+
41+
# Security - Private Keys
42+
- id: detect-private-key
43+
44+
# Python Specific
45+
- id: check-docstring-first
46+
- id: debug-statements
47+
- id: name-tests-test
48+
args: [--pytest-test-first]
49+
- id: requirements-txt-fixer
50+
51+
# =============================================================================
52+
# Python Linting & Formatting (Ruff - Fast, All-in-One)
53+
# =============================================================================
54+
- repo: https://github.com/astral-sh/ruff-pre-commit
55+
rev: v0.9.4
56+
hooks:
57+
# Linter with auto-fix
58+
- id: ruff
59+
name: ruff (lint + fix)
60+
args: [--fix, --exit-non-zero-on-fix]
61+
types_or: [python, pyi]
62+
# Formatter
63+
- id: ruff-format
64+
name: ruff (format)
65+
types_or: [python, pyi]
66+
67+
# =============================================================================
68+
# Python Type Checking
69+
# =============================================================================
70+
- repo: https://github.com/pre-commit/mirrors-mypy
71+
rev: v1.14.1
72+
hooks:
73+
- id: mypy
74+
name: mypy (type check)
75+
additional_dependencies:
76+
- types-requests>=2.32.0
77+
- types-PyYAML>=6.0.0
78+
args:
79+
- --ignore-missing-imports
80+
- --no-error-summary
81+
- --disable-error-code=no-any-return
82+
- --disable-error-code=assignment
83+
- --disable-error-code=attr-defined
84+
- --disable-error-code=arg-type
85+
- --disable-error-code=return-value
86+
- --disable-error-code=misc
87+
- --disable-error-code=index
88+
exclude: ^tests/
89+
90+
# =============================================================================
91+
# Python Security Scanning
92+
# =============================================================================
93+
- repo: https://github.com/PyCQA/bandit
94+
rev: 1.8.2
95+
hooks:
96+
- id: bandit
97+
name: bandit (security scan)
98+
args: [-c, pyproject.toml, -r, scripts/]
99+
additional_dependencies: ["bandit[toml]"]
100+
101+
# =============================================================================
102+
# Secret Detection (Gitleaks)
103+
# =============================================================================
104+
- repo: https://github.com/gitleaks/gitleaks
105+
rev: v8.22.1
106+
hooks:
107+
- id: gitleaks
108+
name: gitleaks (secret detection)
109+
110+
# =============================================================================
111+
# Shell Script Analysis
112+
# =============================================================================
113+
- repo: https://github.com/shellcheck-py/shellcheck-py
114+
rev: v0.10.0.1
115+
hooks:
116+
- id: shellcheck
117+
name: shellcheck (shell lint)
118+
args: [--severity=warning]
119+
120+
# =============================================================================
121+
# YAML Linting
122+
# =============================================================================
123+
- repo: https://github.com/adrienverge/yamllint
124+
rev: v1.35.1
125+
hooks:
126+
- id: yamllint
127+
name: yamllint (YAML lint)
128+
args: [-c, .yamllint.yaml]
129+
130+
# =============================================================================
131+
# Markdown Linting
132+
# =============================================================================
133+
- repo: https://github.com/DavidAnson/markdownlint-cli2
134+
rev: v0.17.2
135+
hooks:
136+
- id: markdownlint-cli2
137+
name: markdownlint (Markdown lint)
138+
139+
# =============================================================================
140+
# GitHub Actions Linting
141+
# =============================================================================
142+
- repo: https://github.com/rhysd/actionlint
143+
rev: v1.7.6
144+
hooks:
145+
- id: actionlint
146+
name: actionlint (GitHub Actions lint)
147+
args: [-shellcheck=] # Disable shellcheck integration (too noisy)
148+
149+
# =============================================================================
150+
# JSON Formatting
151+
# =============================================================================
152+
- repo: https://github.com/pre-commit/pre-commit-hooks
153+
rev: v5.0.0
154+
hooks:
155+
- id: pretty-format-json
156+
name: pretty-format-json
157+
args: [--autofix, --no-sort-keys, --indent=2]
158+
exclude: |
159+
(?x)^(
160+
specs/.*|
161+
release/.*
162+
)$
163+
164+
# =============================================================================
165+
# Pyproject.toml Validation
166+
# =============================================================================
167+
- repo: https://github.com/abravalheri/validate-pyproject
168+
rev: v0.23
169+
hooks:
170+
- id: validate-pyproject
171+
name: validate-pyproject
172+
173+
# =============================================================================
174+
# Typo Detection
175+
# =============================================================================
176+
- repo: https://github.com/crate-ci/typos
177+
rev: v1.29.4
178+
hooks:
179+
- id: typos
180+
name: typos (spell check)
181+
args: [--force-exclude]
182+
exclude: |
183+
(?x)^(
184+
\.git/.*|
185+
specs/.*|
186+
release/.*
187+
)$
188+
189+
# =============================================================================
190+
# Commit Message Linting
191+
# =============================================================================
192+
- repo: https://github.com/commitizen-tools/commitizen
193+
rev: v4.2.2
194+
hooks:
195+
- id: commitizen
196+
name: commitizen (commit message lint)
197+
stages: [commit-msg]
198+
199+
# CI Configuration
200+
ci:
201+
autofix_commit_msg: |
202+
[pre-commit.ci] auto fixes from pre-commit.com hooks
203+
204+
for more information, see https://pre-commit.ci
205+
autofix_prs: true
206+
autoupdate_branch: ''
207+
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
208+
autoupdate_schedule: weekly
209+
skip: [mypy, actionlint] # Skip hooks that need additional setup in CI
210+
submodules: false

.typos.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Typos configuration
2+
# https://github.com/crate-ci/typos
3+
4+
[default]
5+
extend-ignore-identifiers-re = [
6+
# Technical abbreviations and identifiers
7+
"ves",
8+
"waf",
9+
"xc",
10+
"f5xc",
11+
]
12+
13+
[default.extend-words]
14+
# Allow specific words that might be flagged
15+
ves = "ves"
16+
# F5 XC API uses non-standard pluralization in endpoint names
17+
policys = "policys"
18+
discoverys = "discoverys"
19+
20+
[files]
21+
# Ignore generated files and dependencies
22+
extend-exclude = [
23+
".git/",
24+
".venv/",
25+
"*.lock",
26+
"specs/",
27+
"release/",
28+
"site/",
29+
"htmlcov/",
30+
".pytest_cache/",
31+
"__pycache__/",
32+
"*.egg-info/",
33+
]

0 commit comments

Comments
 (0)