forked from luminartech/dev-tools
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.pre-commit-hooks.yaml
More file actions
330 lines (305 loc) · 12.3 KB
/
Copy path.pre-commit-hooks.yaml
File metadata and controls
330 lines (305 loc) · 12.3 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
- id: check-build-file-without-extensions
name: check for BUILD files without extensions
description: Check that `BUILD` files have a `.bazel` ending. `BUILD.bazel` file is the recommended way to name these files.
entry: BUILD files must have a .bazel ending
language: fail
files: "(^|/)BUILD$"
- id: check-readme-md-consistency
name: check README.md consistency
description: Check that readme files are consistently named `README.md`.
entry: Readme files must be named README.md
language: fail
files: "(^|/)(?!README\\.md$)(?i:readme)(?:\\.[^/]*)?$"
- id: check-snake-case
name: check snake case
description: |-
Check that all source code files are `snake_case`.
We don't want to use `camelCase` or `kebab-case` file names.
entry: file names and paths must be snake_case
language: fail
files: "-|[A-Z]"
types_or:
- c++
- cuda
- python
- shell
- id: check-cpp-and-cu-unit-test-naming-pattern
name: Check c++ and cu unit test naming pattern
description: Check that all C++ and Cuda unit test files end with `_test.cpp` or `_test.cu` (no `_tests`) and that they're under a `/tests/` folder (not `/test/`).
entry: C++ and Cuda unit tests must be matched by `**/tests/**/*_test.(cpp|cu)`
language: fail
# The last pattern below matches any test that doesn't contain /tests/ in the path.
# It's a Tempered Greedy Token pattern, see https://stackoverflow.com/a/38846455
files: |
(?x)^(
.*(?<=test)(?<!_test)\.(cpp|cu)$|
.*_tests\.(cpp|cu)$|
.*/test/.*\.(cpp|cu)$|
(?:(?!/tests/).)*_test\.(cpp|cu)$
)
types_or:
- c++
- cuda
- id: check-no-dashes
name: check no dashes
description: Check that markdown filenames do not use dashes
entry: Markdown filenames must not use dashes
language: fail
files: "-"
types_or:
- markdown
- id: check-sys-path-append
name: Check sys path append usage
description: Check that no `sys.path.append` is used in Python code
entry: "sys.path.append"
language: pygrep
types:
- "python"
- id: check-sys-path-insert
name: Check sys path append usage
description: Check that no `sys.path.insert` is used in Python code
entry: "sys.path.insert"
language: pygrep
types:
- "python"
- id: go-fmt
name: Go Format
description: Format go files
entry: gofmt
args:
- -s
- -w
- -d=false
language: golang
types:
- go
- id: go-imports
name: Go Imports
description: Order go imports
entry: goimports
args:
- -w
- -d=false
additional_dependencies:
- golang.org/x/tools/cmd/goimports@v0.44.0
language: golang
types:
- go
- id: go-revive
name: Go Revive
description: Run Go Revive linter
entry: revive
args:
- -set_exit_status
- -formatter
- friendly
additional_dependencies:
- github.com/mgechev/revive@v1.15.0
language: golang
types:
- go
- id: generate-hook-docs
name: generate hook docs
description: |-
Generate markdown documentation from the hook descriptions in `.pre-commit-hooks.yaml` into the `README.md`.
Docs are generated between `hooks-doc start` and `hooks-doc end` markdown comment blocks.
entry: generate-hook-docs
language: python
pass_filenames: false
files: (README.md|.pre-commit-hooks.yaml)
additional_dependencies:
- pre-commit==4.6.0
- id: check-number-of-lines-count
name: Check Number of Lines
description: |-
Check that number of lines in scripts do not exceed max-lines.
Use `--max-lines=<number>` to set the maximum number of lines.
Default is 50 for shell scripts.
entry: check-number-of-lines-count
language: python
types_or:
- shell
args:
- --max-lines=50
- id: check-shellscript-set-options
name: Check 'set' options
description: |-
Check if options are set with `set -euxo pipefail` for bash scripts and `set -eux` for sh scripts.
Use `--bash-options` or `--shell-options` to set different expected options.
Use `# nolint(set_options)` to ignore this check.
entry: check-shellscript-set-options
language: python
types_or:
- shell
- id: check-jira-reference-in-todo
name: Check Jira reference in TODO
description: "Check that all TODO comments follow the same pattern and link a Jira ticket: `TODO(ABC-1234):`."
entry: check-jira-reference-in-todo
language: python
exclude_types:
- svg
exclude: ".pre-commit-config.yaml"
- id: check-load-statement
name: Check that a rule is loaded from a specific rule set
description: |-
Check that a rule is loaded from a specific rule set.
Use `--rule-path` to set the rule load path and `--rule-name` to set the rule name.
Both arguments are required.
Example args in the pre-commit config: `args: [--rule-path=@rules_python//python:defs.bzl, --rule-name=py_test]`.
Make sure you don't put any ticks around the rule path and rule name.
This hook can be used multiple times to check different rules.
entry: check-load-statement
language: python
types:
- bazel
- id: check-rule-has-tag
name: Check that a Bazel rule has a specific tag
description: |-
Check that a Bazel rule contains a specific tag in its `tags` attribute.
Use `--rule-name` to select the rule and `--tag` to define the required tag.
Both arguments are required.
Example args in the pre-commit config: `args: [--rule-name=py_venv, --tag=manual]`
This is useful for checks such as: `py_venv(..., tags = ["manual"])` or `pkg_tar(..., tags = ["no-remote"])`.
Alternatively, you can
- make use of Bazel's `--modify_execution_info` flag, see <https://github.com/bazel-contrib/tar.bzl?tab=readme-ov-file#remote-cache-and-rbe>
- wrap the rule with a macro that always applies these tags (combine this with the [`check-load-statement`](#check-load-statement) hook to make sure users always use the wrapper)
This hook can be used multiple times to check different rules and tags.
entry: check-rule-has-tag
language: python
types:
- bazel
- id: check-forbidden-tags
name: Check that Bazel rules do not use forbidden tags
description: |-
Check that Bazel rules do not contain forbidden tags in their `tags` attribute.
Use `--forbidden-tag` to define the disallowed tag.
Use `--allow-in-rule-kind` to permit that tag for rule kinds matching a regular expression.
Example args in the pre-commit config: `args: [--forbidden-tag=no-remote, --allow-in-rule-kind=pkg_tar]`
entry: check-forbidden-tags
language: python
types:
- bazel
- id: check-non-existing-and-duplicate-excludes
name: Check non-existing and duplicate excludes in pre-commit-config
description: |-
Check for non existing and duplicate paths in `.pre-commit-config.yaml`.
Background: In a big codebase, the exclude lists can be quite long and it's easy to make a typo or forget to remove an entry when it's no longer needed.
This hook helps you to maintain a clean and up to date exclude list.
Note: This hook deliberately only supports simple `|`-separated lists of file paths in `exclude` fields — complex regular expressions are not supported.
Keeping exclusions as plain `|`-separated paths also makes it easier for humans to maintain an overview of what is excluded.
entry: check-useless-exclude-paths-hooks
pass_filenames: false
always_run: true
language: python
additional_dependencies:
- pre-commit-excludes>=0.2.0
- id: print-pre-commit-metrics
name: Print pre-commit metrics such as number of excluded files
description: |-
Count the number of excludes in `.pre-commit-config.yaml` and print them in json format.
Use `--output-file` to also write the metrics to a file in json format.
Paths are relative to the root of the repository.
On large projects this can help to collect metrics over time for how many files are excluded from pre-commit.
entry: print-pre-commit-metrics
pass_filenames: false
language: python
additional_dependencies:
- pre-commit-excludes>=0.2.0
- id: sync-vscode-config
name: Sync VSCode Config
description: |-
Sync VSCode settings and extensions from `devcontainer.json` to `.vscode` folder.
`devcontainer.json` will be now your source of truth.
Entries defined in `settings.json` and `extensions.json` which don't exist in `devcontainer.json` will be left as is.
If `settings.json` and `extensions.json` are ignored in Git, consider running the hook in `post-checkout` and `post-merge` stages by overwriting the `stages` config.
In this case, define your `default_install_hook_types` in the pre-commit config and set `always_run: true` for this hook.
entry: sync-vscode-config
language: python
stages:
- pre-commit
files: |
(?x)^(
(.devcontainer/)?devcontainer.json|
.vscode/extensions.json|
.vscode/settings.json
)
pass_filenames: false
additional_dependencies:
- pyjson5==2.0.0
- id: sync-tool-versions
name: Sync tool versions
description: |-
Sync tool versions across files based on `.versions.yaml`.
Each version entry defines a `name`, a `version`, and a list of `entries` containing a file `path` and a regex `pattern` with a single capture group for the version.
The `path` is relative to `.versions.yaml` and can be any glob pattern supported by `pathlib.Path.glob`.
You can also use `THE_VERSION` in the pattern as a placeholder for that capture group (defaults to SemVer with an optional leading `v`).
Use `version_override` on an entry to replace with a different value than the sync `version`.
If you need prefixes like `py314`, use an explicit capture group instead of `THE_VERSION`.
Example `.versions.yaml`:
```yaml
name: tool-versions
sync_versions:
- name: rust
version: 1.91.0
entries:
- path: MODULE.bazel
pattern: RUST_VERSION\s*=\s*"THE_VERSION"
- path: .pre-commit-config.yaml
pattern: rust:\s*([0-9.]+)
- name: python
version: '3.14'
entries:
- path: .python-version
pattern: ([0-9]+\.[0-9]+)
- path: pyproject.toml
pattern: target-version\s*=\s*"py([0-9]+)"
version_override: '314'
- path: packages/**/pyproject.toml
pattern: target-version\s*=\s*"py([0-9]+)"
version_override: '314'
```
entry: sync-tool-versions
language: python
pass_filenames: false
always_run: true
additional_dependencies:
- pre-commit==4.6.0
- id: check-max-one-sentence-per-line
name: Check max one sentence per line
description: |-
This hook is a simplified version of [rumdl MD013 sentence-per-line-mode](https://github.com/rvben/rumdl/blob/main/docs/md013.md#sentence-per-line-mode).
In contrast to rumdl, this hook doesn't reflow all your text; it only enforces one sentence per line.
Check that each line in markdown files contains at most one sentence.
This makes diffs easier to read and avoids merge conflicts.
Sentences are split on `.`, `!`, or `?` followed by a space and a capital letter.
This hook doesn't respect surrounding indentation, so be sure to combine it with <https://github.com/hukkin/mdformat> or a similar formatter that fixes indentation.
entry: check-max-one-sentence-per-line
additional_dependencies:
- regex==2026.2.28
language: python
types_or:
- asciidoc
- markdown
- rst
- tex
- id: check-ownership
name: Check CODEOWNERS consistency (can take a while)
description: |
Check if all folders in the `CODEOWNERS` file exist, there are no duplicates, and it has acceptable codeowners.
What is an acceptable codeowner?
We want to make sure that every folder has a codeowner other than the team that should exclusively own the CODEOWNERS file.
For this, we define a `CODEOWNERS_OWNER` using the `--codeowners-owner` argument.
Your `CODEOWNERS` file should look as follows:
```shell
* CODEOWNERS_OWNER
# Here goes all your CODEOWNERS file content overriding the wildcard owner
# leave this at the bottom to have highest ownership priority
/.github/CODEOWNERS CODEOWNERS_OWNER
```
If the hook detects `CODEOWNERS_OWNER` owns anything else than `.github/CODEOWNERS` it will fail to make sure every file added has an acceptable codeowner.
Supported providers and their CODEOWNERS files are GitHub, GitLab, and Bitbucket.
entry: check-ownership
language: python
always_run: true
additional_dependencies:
- whoowns>=0.8.0