-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.pre-commit-hooks.yaml
150 lines (144 loc) · 5.85 KB
/
.pre-commit-hooks.yaml
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
- 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-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: 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.27.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.5.1]
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
files: (README.md|.pre-commit-hooks.yaml)
additional_dependencies: [pre-commit>=3.5.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 30 for shell scripts.
entry: check-number-of-lines-count
language: python
types_or:
- shell
args: [--max-lines=30]
- id: check-shellscript-set-options
name: Check 'set' options
description: Check if options are set with `set -euxo pipefail`. 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
- 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."
entry: check-useless-exclude-paths-hooks
language: python
additional_dependencies: ["pre-commit >= 3.5.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>=1.6.8]
- id: check-ownership
name: Check `.github/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.
entry: check-ownership
language: python
always_run: true