-
Notifications
You must be signed in to change notification settings - Fork 430
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
210 lines (176 loc) · 6.7 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
210 lines (176 loc) · 6.7 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
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Summary: config for setting up git hooks using the pre-commit framework.
# Install it like this:
#
# pip install pre-commit
# pre-commit install
# pre-commit run
#
# After doing the above, the pre-commit hooks will be called automatically by
# git at the appropriate times. Note the use of pre-commit hooks is optional,
# and NOT set up by default nor used by the scripts in this repository.
default_stages:
# If a hook does not define a value for `stages:`, it applies to this stage.
- pre-commit
default_install_hook_types:
- commit-msg
- pre-commit
- pre-push
# Note: these are Python regular expressions matched with re.search.
exclude: |
(?x)^(
.*\.egg-info/.* |
.*\.h5 |
.*\.ipynb_checkpoints(/.*)? |
.*\.lock |
.*\.log |
.*\.out |
.*\.pytest_cache/.* |
.*\.tmp |
.*__pycache__/.* |
\.env/.* |
\.venv/.* |
\.([^/]*cache/.*) |
\.coverage(\..*)? |
docs/_build/.* |
venv/.*
)$
fail_fast: true
minimum_pre_commit_version: '4.4.0'
repos:
# ~~~~ Pre-commit hooks ~~~~
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0
hooks:
# Note: don't use check-yaml bc it doesn't read the yamllint config.
# Use separate yamllint hook later in this file.
- id: no-commit-to-branch
name: 'The commit is not being made to the main branch'
args: [--branch, main, --branch, master]
- id: check-merge-conflict
name: "Files are free of git merge conflict strings"
- id: check-illegal-windows-names
name: "File names are valid for use on Windows"
- id: check-case-conflict
name: "File names won't conflict on case-insensitive systems"
- id: name-tests-test
name: 'Test files are named correctly'
args: [--pytest]
- id: check-symlinks
name: 'All symlink targets exist'
- id: destroyed-symlinks
name: 'Symlinks are not being changed into regular files'
- id: mixed-line-ending
name: "Files don't mix line ending conventions"
- id: debug-statements
name: 'Python files are free of debug statements'
- id: check-shebang-scripts-are-executable
name: 'Shell script files are executable'
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.11.0.1
hooks:
- id: shellcheck
name: 'Shell scripts are lint-free'
files: '(\.sh$|^check/[^.]+$)'
- repo: https://github.com/Boeing/config-file-validator
rev: fc3dea5b2d0bfd47a785ca47375fe6080151f97b # frozen: v2.3.0
hooks:
- id: config-file-validator
name: 'Config files are free of syntax errors'
types_or: [editorconfig, yaml]
args: [--gitignore, --exclude-dirs=.git]
- repo: https://github.com/adrienverge/yamllint
rev: cba56bcde1fdd01c1deb3f945e69764c291a6530 # frozen: v1.38.0
hooks:
- id: yamllint
name: 'YAML files are lint-free'
files: \.(yaml|yml|cff)$
args: [--format=colored, --no-warnings]
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: '8ef330cbb7204d388aa7a620f9549bcea8009663' # frozen: 0.37.3
hooks:
- id: check-jsonschema
name: 'Jupyter notebooks are valid JSON files'
types: [jupyter]
files: '.*\.ipynb$'
# Note: pre-commit will download & cache this file automatically.
# yamllint disable rule:line-length
args: [--schemafile, https://raw.githubusercontent.com/jupyter/nbformat/refs/heads/main/nbformat/v4/nbformat.v4.0.schema.json]
- repo: https://github.com/AleksaC/hadolint-py
rev: '458cb25edf664682e3e856a53a2f9af33e068297' # frozen: 2.14.0
hooks:
- id: hadolint
name: 'Docker files are lint-free'
files: (?i)dockerfile$
args: [--failure-threshold, error]
- repo: https://github.com/abravalheri/validate-pyproject
rev: 4b2e70d08cb2ccd26d1fba73588de41c7a5d50b7 # frozen: v0.25
hooks:
- id: validate-pyproject
name: 'The pyproject.toml file is valid'
files: pyproject.toml
# ~~~~ Commit message hooks ~~~~
- repo: https://github.com/crate-ci/typos
rev: d80b8e26878e372a041833cd67163dbdb6a4336e # frozen: v1
hooks:
- id: typos
name: 'Commit message is free of typos'
stages: [commit-msg]
# Important: add "args: []" to prevent typos from autofixing your files.
# C.f. https://github.com/crate-ci/typos/blob/master/docs/pre-commit.md
args: []
# ~~~~ Pre-push hooks ~~~~
- repo: local
hooks:
- id: format-incremental
name: 'check/format-incremental runs without errors'
entry: check/format-incremental
language: script
pass_filenames: false
files: \.(cc|h|cu|py)$
stages: [pre-push]
- repo: https://github.com/Pierre-Sassoulas/copyright_notice_precommit
rev: 'd9215b6b2a028d1614c92cf43a9fcff3b1dd889e' # frozen: 0.1.2
hooks:
- id: copyright-notice
name: 'Files have copyright notices'
types: [python]
stages: [pre-push]
args: [--notice=dev_tools/apache-license-header.txt]
# Note this is used for YAML files, despite that it's named "jsonschema".
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: '8ef330cbb7204d388aa7a620f9549bcea8009663' # frozen: 0.37.3
hooks:
- id: check-github-workflows
name: 'GitHub Actions workflow files are syntactically valid'
stages: [pre-push]
- id: check-github-actions
name: 'GitHub Actions definitions (if any) are syntactically valid'
stages: [pre-push]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: 3a6eb0fadf60b3cccfd80bad9dbb6fae7e47b316 # frozen: v1.10.0
hooks:
- id: python-check-blanket-noqa
name: '"# noqa" annotations include error codes'
types: [python]
stages: [pre-push]
- id: python-check-blanket-type-ignore
name: '"# type: ignore" comments include error codes'
types: [python]
stages: [pre-push]
- id: python-check-mock-methods
name: 'Uses of unittest.mock are free of some common mistakes'
types: [python]
stages: [pre-push]