forked from apple/coreai-optimization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
354 lines (318 loc) · 13.1 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
354 lines (318 loc) · 13.1 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
# =============================================================================
# 0. File Generation
# =============================================================================
- repo: local
hooks:
- id: section-generation
name: '━━━━━━━━━━━━ 0. File Generation ━━━━━━━━━━━━━━━━━━'
language: system
entry: 'true'
pass_filenames: false
always_run: true
# ----------------------------------------------------------------------------
# 0.1 Insert/refresh BSD-3-Clause license header
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: add-license-header
name: 'Add BSD-3 license header'
language: system
entry: scripts/pre_commit/add_license_header.py --license-file configs/BSD-3-LICENSE-HEADER-TEMPLATE --start-year 2026
files: '\.(py|sh|js|css|html)$|(^|/)(GNUmakefile|[Mm]akefile)$'
exclude: ^src/coreai_opt/deps/
# ----------------------------------------------------------------------------
# 0.2 Update LICENSE year
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: update-license-year
name: 'Update LICENSE year'
description: Render LICENSE from configs/BSD-3-LICENSE-TEMPLATE, replacing {year} with `<start>-<current>` (or just `<current>` if equal). Always runs so the year auto-bumps on the first commit of each calendar year.
language: system
entry: scripts/pre_commit/update_license_year.py --template configs/BSD-3-LICENSE-TEMPLATE --license-file LICENSE
pass_filenames: false
always_run: true
# =============================================================================
# 1. Sanity / Text Hygiene
# =============================================================================
- repo: local
hooks:
- id: section-sanity
name: '━━━━━━━━━━━━ 1. Sanity / Text Hygiene ━━━━━━━━━━━━'
language: system
entry: 'true'
pass_filenames: false
always_run: true
- repo: local
hooks:
- id: trailing-whitespace
name: trim trailing whitespace
language: system
entry: trailing-whitespace-fixer
types: [text]
- id: end-of-file-fixer
name: fix end of files
language: system
entry: end-of-file-fixer
types: [text]
exclude: ^\.codegenius/
- id: check-yaml
name: check yaml
language: system
entry: check-yaml
types: [yaml]
- id: check-added-large-files
name: check for added large files
language: system
entry: check-added-large-files
exclude: ^tests/_test_artifacts/
# =============================================================================
# 2. Formatting / Auto-fixes
# =============================================================================
- repo: local
hooks:
- id: section-formatting
name: '━━━━━━━━━━━━ 2. Formatting / Auto-fixes ━━━━━━━━━━'
language: system
entry: 'true'
pass_filenames: false
always_run: true
# ----------------------------------------------------------------------------
# 2.1 Format Python Import Sorting (ruff)
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: ruff-isort
name: 'Format Python Import Sorting (ruff)'
language: system
entry: ruff check --select=I --fix
types_or: [python, pyi]
# ----------------------------------------------------------------------------
# 2.2 Format Python `__all__` Sorting (ruff)
# ----------------------------------------------------------------------------
- id: ruff-all-sort
name: 'Format Python `__all__` Sorting (ruff)'
language: system
entry: ruff check --select=RUF022 --fix
types: [python]
# ----------------------------------------------------------------------------
# 2.3 Format Python Code (darker)
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: darker
name: 'Format Python Code Line Length (darker)'
language: system
entry: darker
types: [python]
args: [--config, configs/darker.toml]
# ----------------------------------------------------------------------------
# 2.4 Format TOML Sorting (toml-sort)
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: toml-sort-fix
name: 'Format TOML Sorting (toml-sort)'
language: system
entry: toml-sort --in-place
types: [toml]
# pyproject-shaped files are owned by pyproject-fmt; toml-sort's
# whitespace conventions (blank line after header comments, no spaces
# inside inline tables) conflict with pyproject-fmt's, and neither
# tool exposes a knob to align them.
exclude: (^|/)pyproject[^/]*\.toml$
# ----------------------------------------------------------------------------
# 2.5 Format pyproject.toml (pyproject-fmt)
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: pyproject-fmt
name: 'Format pyproject.toml (pyproject-fmt)'
language: system
entry: pyproject-fmt --config configs/pyproject-fmt.toml
files: (^|/)(pyproject\.toml|pyproject_[^/]+\.toml)$
# `src/coreai_opt_benchmarking/` is internal-only (stripped from the
# OSS export); its sub-pyproject has its own convention and shouldn't
# be reformatted by the main project's pyproject-fmt config.
exclude: ^src/coreai_opt_benchmarking/pyproject\.toml$
# ----------------------------------------------------------------------------
# 2.6 Format Makefile (mbake)
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: mbake-format
name: Format Makefile (mbake)
entry: mbake format --config configs/.bake.toml
language: system
files: '(^|/)(GNUmakefile|[Mm]akefile|.*\.mk)$'
# ----------------------------------------------------------------------------
# 2.7 Format Markdown (mdformat)
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: mdformat
name: 'Format Markdown (mdformat)'
language: system
entry: mdformat --number
files: \.(md)$
exclude: ^(CHANGELOG\.md$|\.codegenius/)
args: [
--number, # Force 1., 2., 3. instead of all 1.
--wrap=keep, # Preserve existing line breaks
]
# ----------------------------------------------------------------------------
# 2.8 Format Shell Scripts (shfmt)
# ----------------------------------------------------------------------------
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.12.0-2
hooks:
- id: shfmt
name: 'Format Shell Script (shfmt)'
# =============================================================================
# 3. Lint / Static Analysis
# =============================================================================
- repo: local
hooks:
- id: section-lint
name: '━━━━━━━━━━━━ 3. Lint / Static Analysis ━━━━━━━━━━━'
language: system
entry: 'true'
pass_filenames: false
always_run: true
# ----------------------------------------------------------------------------
# 3.1 Linter: Ruff
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: ruff-lint
name: 'Ruff Comprehensive Lint Fix'
language: system
entry: ruff check --fix
types_or: [python, pyi]
# ----------------------------------------------------------------------------
# 3.2 Lint TOML (taplo-lint)
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: taplo-lint
name: 'Lint TOML (taplo-lint)'
language: system
entry: taplo lint --no-schema
types: [toml]
# ----------------------------------------------------------------------------
# 3.3 Lint Makefile (checkmake)
# ----------------------------------------------------------------------------
- repo: https://github.com/checkmake/checkmake
rev: '0.2.2'
hooks:
- id: checkmake
name: 'Lint Makefile (checkmake)'
args: ['--config', 'configs/checkmake.ini']
- repo: local
hooks:
- id: check-makefile
name: 'Lint Makefile .PHONY consistency'
description: Ensure all Makefile targets are listed in .PHONY and sorted alphabetically
entry: scripts/pre_commit/check_makefile.py
language: system
files: ^(GNUmakefile|[Mm]akefile)$
pass_filenames: false
# ----------------------------------------------------------------------------
# 3.4 Lint Markdown (PyMarkdown)
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: pymarkdown
name: 'Lint Markdown (PyMarkdown)'
language: system
entry: pymarkdown --disable-rules MD013,MD024 scan
files: \.(md)$
exclude: ^\.codegenius/
# ----------------------------------------------------------------------------
# 3.5 Lint Shell Script (bashate)
# ----------------------------------------------------------------------------
- repo: local
hooks:
- id: bashate
name: 'Lint Shell Script (bashate)'
language: system
entry: bashate --max-line-length 100
types: [shell]
# (Future: add mypy, flake8, or other static analysis tools here)
# =============================================================================
# 4. Link / Reference Checks
# =============================================================================
- repo: local
hooks:
- id: section-links
name: '━━━━━━━━━━━━ 4. Link / Reference Checks ━━━━━━━━━━━━'
language: system
entry: 'true'
pass_filenames: false
always_run: true
# =============================================================================
# 5. Project-specific / Build / Generated Code Checks
# =============================================================================
- repo: local
hooks:
- id: section-project-specific
name: '━━━━━━━━━━━━ 5. Project-specific Checks ━━━━━━━━━━━━'
language: system
entry: 'true'
pass_filenames: false
always_run: true
- repo: local
hooks:
- id: check-all-declarations
name: Check __all__ declarations
description: Ensure all Python modules have __all__ declarations
entry: env USE_LOCAL_COREAI=1 python scripts/pre_commit/check_all_declarations.py src/coreai_opt
language: system
types: [python]
exclude: ^tests/
- repo: local
hooks:
- id: towncrier-check
name: Check changelog fragments (towncrier)
entry: scripts/pre_commit/towncrier_check.sh
language: system
pass_filenames: false
- repo: local
hooks:
- id: validate-changelog
name: Validate CHANGELOG.md (Keep a Changelog format)
description: Ensure CHANGELOG.md follows Keep a Changelog standards
entry: kacl-cli verify
language: system
files: ^CHANGELOG\.md$
pass_filenames: false
# =============================================================================
# 6. Policy / Commit Metadata / Security Checks
# =============================================================================
- repo: local
hooks:
- id: section-policy
name: '━━━━━━━━━━━━ 6. Policy / Security Checks ━━━━━━━━━'
language: system
entry: 'true'
pass_filenames: false
always_run: true
# (Future: add commit message linting, secret scanning, branch checks, etc.)
# Examples:
# - commitizen for commit message linting
# - detect-secrets or gitleaks for secret scanning
# - check-commit for branch name validation
# =============================================================================
# 7. Summary
# =============================================================================
- repo: local
hooks:
- id: section-summary
name: '━━━━━━━━━━━━━━━━━━━━━ Done ━━━━━━━━━━━━━━━━━━━━━━━'
language: system
entry: 'true'
pass_filenames: false
always_run: true