-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
.pre-commit-config.yaml
242 lines (235 loc) · 7.85 KB
/
.pre-commit-config.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
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
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Update versions with:
# pre-commit autoupdate --freeze && pre-commit run -a
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3 # Defaults to python2, so override it.
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-symlinks
exclude: ^bazel-execroot$
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
exclude: '^(.*/fuzzer_corpus/.*|.*\.svg)$'
- id: mixed-line-ending
args: ['--fix=lf']
exclude: '^(.*/fuzzer_corpus/.*|.*\.svg)$'
- id: trailing-whitespace
exclude: '^(.*/fuzzer_corpus/.*|.*/testdata/.*\.golden|.*\.svg)$'
- repo: https://github.com/google/pre-commit-tool-hooks
rev: efaea7c61c774c0b1a9805fd999e754a2d19dbd1 # frozen: v1.2.5
hooks:
- id: check-google-doc-style
- id: markdown-toc
- repo: local
hooks:
- id: fix-cc-deps
name: Fix missing C++ deps
entry: scripts/fix_cc_deps.py
language: python
files: ^.*/(BUILD|[^/]+\.(h|cpp))$
pass_filenames: false
# Formatters should be run late so that they can re-format any prior changes.
- repo: https://github.com/psf/black
rev: 1b2427a2b785cc4aac97c19bb4b9a0de063f9547 # frozen: 24.10.0
hooks:
- id: black
- repo: local
hooks:
- id: prettier
name: prettier
language: node
additional_dependencies: ['[email protected]']
types_or: [html, javascript, markdown, yaml]
entry: npx prettier --write --log-level=warn
- repo: local
hooks:
- id: buildifier
name: Bazel buildifier
entry: scripts/run_buildifier.py
# Beyond just formatting, explicitly fix lint warnings.
args: ['--lint=fix', '--warnings=all', '-r', '.']
language: python
files: |
(?x)^(
.*BUILD.*|
.*MODULE.bazel.*|
.*WORKSPACE.*|
.*\.bzl
)$
- id: check-bazel-mod-deps
# Check this after buildifier because buildifier may modify inputs, and
# MODULE.bazel.lock includes line/column details.
name: Check bazel mod deps
entry: scripts/bazel_mod_deps.py
language: python
files: |
(?x)^(
.*MODULE.bazel.*|
.*WORKSPACE.*
)$
- id: clang-format
name: clang-format
entry: clang-format
types_or: [c++, proto, def]
language: python
args: ['-i']
additional_dependencies: ['clang-format==17.0.1']
- id: explorer-format-grammar
name: Format the explorer grammar file
entry: explorer/syntax/format_grammar.py
language: python
files: ^explorer/syntax/(lexer.lpp|parser.ypp)$
pass_filenames: false
additional_dependencies: ['clang-format==17.0.1']
- repo: local
hooks:
- id: check-header-guards
# This should run after clang-format, which may reformat a guard.
name: Check header guards
entry: scripts/check_header_guards.py
language: python
files: ^.*\.h$
- id: check-sha-filenames
# This may rename files, so it's deliberately between formatters and
# linters.
name: Check fuzzer SHA filenames
entry: scripts/check_sha_filenames.py
language: python
files: ^.*/fuzzer_corpus/.*$
- id: check-toolchain-diagnostics
name: Check toolchain diagnostics
entry: toolchain/diagnostics/check_diagnostics.py
language: python
files: |
(?x)^(
toolchain/.*\.cpp|
toolchain/.*\.h|
toolchain/diagnostics/check_diagnostics\.py|
toolchain/diagnostics/diagnostic_kind\.def
)$
pass_filenames: false
# Run linters last, as formatters and other checks may fix issues.
- repo: local
hooks:
- id: forbid-llvm-googletest
name: Checks for deps on LLVM's version of GoogleTest
entry: scripts/forbid_llvm_googletest.py
language: python
files: ^.*/BUILD$
pass_filenames: false
- repo: https://github.com/PyCQA/flake8
rev: e43806be3607110919eff72939fda031776e885a # frozen: 7.1.1
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'f56614daa94d5cd733d3b7004c5df9caad267b4a' # frozen: v1.13.0
hooks:
- id: mypy
# Use setup.cfg to match the command line.
args:
- --config-file=setup.cfg
# This should match the requirements added in the WORKSPACE pip_install.
additional_dependencies:
- gql >= 2.0.0, < 3.0.0
- PyGitHub
# Exclusions are:
# - p#### scripts because they're not tested or maintained.
# - lit.cfg.py because it has multiple copies, breaking mypy.
# - Unit tests because they sometimes violate typing, such as by
# assigning a mock to a function.
exclude: |
(?x)^(
proposals/(?!scripts/).*|
.*/lit\.cfg\.py|
.*_test\.py
)$
- repo: https://github.com/codespell-project/codespell
rev: 193cd7d27cd571f79358af09a8fb8997e54f8fff # frozen: v2.3.0
hooks:
- id: codespell
args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
# Test data may contain intentional misspellings, as well as short,
# meaningless identifiers that codespell incorrectly identifies as
# typos but that we would want to detect in other contexts.
exclude: |
(?x)^(
.*/testdata/.*|
.*/fuzzer_corpus/.*
)$
- repo: https://github.com/google/pre-commit-tool-hooks
rev: efaea7c61c774c0b1a9805fd999e754a2d19dbd1 # frozen: v1.2.5
hooks:
- id: check-copyright
args:
- --copyright
- |+
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- --custom_format
- '\.(carbon|c|json|proto|scss|ypp)(\.tmpl)?$'
- ''
- '// '
- ''
- --custom_format
- '\.(l|lpp|y)$'
- '/*'
- ''
- '*/'
- --custom_format
- '\.(plist)$'
- '<!--'
- ''
- '\-->'
- --custom_format
- '\.vim$'
- ''
- '" '
- ''
- --custom_format
- '\.scm$'
- ''
- '; '
- ''
- --custom_format
- '\.lua$'
- ''
- '-- '
- ''
exclude: |
(?x)^(
.bazelversion|
.github/pull_request_template.md|
.python-version|
compile_flags.txt|
github_tools/requirements.txt|
third_party/.*|
website/.ruby-version|
website/Gemfile.lock|
.*\.def|
.*\.svg|
.*/fuzzer_corpus/.*|
.*/testdata/.*\.golden
)$
- id: check-links
# This excludes third-party code, and patches to third-party code.
exclude: |
(?x)^(
MODULE.bazel.lock|
bazel/bazel_clang_tidy/.*\.patch|
bazel/google_benchmark/.*\.patch|
bazel/libpfm/.*\.patch|
bazel/llvm_project/.*\.patch|
third_party/examples/.*/carbon/.*|
)$