-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
383 lines (351 loc) · 11.8 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
383 lines (351 loc) · 11.8 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
exclude: ^misc/bench.py$
default_language_version:
rust: 1.96.0
node: 24.18.0
repos:
##############
# Common stuff
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: mixed-line-ending
alias: eol
- id: trailing-whitespace
exclude_types: [svg, diff]
exclude: ^docs/cli/manpages/.*.1 # autogenerated files
- id: end-of-file-fixer
alias: eof
exclude_types: [svg, diff]
# `libparsec/version` must not have a trailing newline !
exclude: ^libparsec/version$
- repo: local
hooks:
# - id: releaser
# name: releaser
# entry: python ./misc/releaser.py check
# language: python
# language_version: python3
# pass_filenames: false
# require_serial: true
- id: license_headers
name: license_headers
alias: headers
entry: python ./misc/license_headers.py add
language: python
language_version: python3
# see: https://github.com/pre-commit/identify/blob/master/identify/extensions.py
types_or:
[
python,
pyi,
sql,
rust,
vue,
ts,
tsx,
javascript,
jsx,
c++,
c,
idl,
jinja,
markdown,
scss,
]
- id: static-assets-hash
name: static_assets_hash
alias: static-assets-hash
entry: python ./misc/update_server_static_assets_hash_prefix.py --check
language: python
language_version: python3
pass_filenames: false
files: ^server/parsec/static/
- repo: https://github.com/adrienverge/yamllint
rev: v1.38.0
hooks:
- id: yamllint
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v10.0.1
hooks:
- id: cspell
stages:
- manual
args:
- --config=./.cspell/cspell.config.yml
- --no-progress
- --dot
- --no-must-find-files
- --show-suggestions
- --no-summary
additional_dependencies:
- "@cspell/dict-en_us"
- "@cspell/dict-fr-fr"
- "@cspell/dict-fr-reforme" # cspell:disable-line
- "@cspell/dict-bash"
- "@cspell/dict-shell"
- "@cspell/dict-win32"
# ShellCheck, the static analysis tool for shell scripts
#
# We do not use the official pre-commit hook [0] because it requires
# docker executable (see [1]).
# [0] https://github.com/koalaman/shellcheck-precommit
# [1] https://github.com/koalaman/shellcheck/issues/2495
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.11.0.1
hooks:
- id: shellcheck
args: [
--severity=info,
# Follow source statements to check source'd files.
# Otherwise, shellcheck will only check input files (i.e. .sh files that has been changed)
--external-sources,
# Specify paths to search for sourced files (useful for SC1090 & SC1091)
--source-path=SCRIPTDIR,
]
########
# Python
# Long story short we cannot use pre-commit isolated environments for the
# tools below because they require access to the project dependencies.
#
# So instead, we run these tools with `uv run`, thus reusing project
# configuration and virtual env:
# - `uv run` will stick to the shell current virtual env
# - if the shell is not into a virtual env, uv will create one and install Parsec&deps
# - lastly, the tools are executed
#
# This approach requires the tools to be listed as dev dependencies but in
# general (type checkers, linters, etc.) this is already the case since we
# need them for development.
#
# This approach has the following benefits:
# - It prevents going out of sync in tools version between pre-commit config
# and uv.lock
# - It saves time on initial run because we don't have to create isolated
# virtualenv for those tools
# - Pre-commit hook are really simple, so it's no big deal to inline them.
# - Pre-commit hook need sometime tweaks (e.g. ruff hook not correctly
# handling .pyi), it's more readable then to have all the config here.
- repo: local
hooks:
- id: ruff-check
name: ruff check
entry: uv --project ./server run --only-dev ruff check --fix
require_serial: true
pass_filenames: false
language: system
types_or: [python, pyi]
- id: ruff-format
name: ruff format
entry: uv --project ./server run --only-dev ruff format
require_serial: true
language: system
types_or: [python, pyi]
- id: pyright
name: pyright
entry: uv --project ./server run --only-dev pyright
exclude: ^docs/ # Ignore pythons files in docs requiring specific dependencies
require_serial: true
language: system
types_or: [python, pyi]
args: [--project=server/]
- id: deptry
name: deptry
entry: uv --project ./server run --only-dev deptry server --config=server/pyproject.toml
files: ^server/
types_or: [python, pyproj]
pass_filenames: false # deptry expects only the root directory to scan
require_serial: true
language: system
- id: sqlfluff
name: SQLFluff
entry: uv --project ./server run --only-dev ./misc/lint_sql.py --fix
types_or: [sql]
files: |
(?x)^(
libparsec/crates/platform_storage/src/native/.*|
server/parsec/components/postgresql/migrations/.*|
server/tests/migrations/.*
)$
require_serial: true
language: system
- id: sqlfluff-in-python
name: SQLFluff in Python server components
entry: uv --project ./server run --only-dev ./misc/lint_sql.py --non-sql-file-print-fix
types_or: [python]
files: ^(server/parsec/components/postgresql/)
require_serial: true
language: system
# powrap, script to fix indentation of .po files.
#
# - running with uv in order to reuse environment from ./docs
# - powrap is called via "make wrap" (see ./docs/Makefile)
- id: powrap
name: powrap
entry: uv --directory ./docs run make wrap
pass_filenames: false
types: [pofile]
require_serial: true
language: system
######
# Rust
- repo: local
hooks:
- id: toml-fmt
name: toml-fmt
entry: taplo fmt
language: system
types: [toml]
- id: fmt
name: fmt
entry: cargo fmt
language: system
types: [rust]
args: [--]
- &clippy
id: clippy
name: clippy
entry: cargo clippy
language: system
types: [rust]
pass_filenames: false
args:
[
--workspace,
--tests,
--bins,
--lib,
--exclude=libparsec_bindings_web,
--exclude=libparsec_bindings_electron,
--,
--deny=warnings,
--deny=clippy::undocumented_unsafe_blocks,
--deny=clippy::unwrap_used,
]
- id: clippy-fix
name: clippy-fix
entry: cargo clippy
language: system
types: [rust]
pass_filenames: false
stages:
- manual
args:
[
--workspace,
--tests,
--bins,
--lib,
--exclude=libparsec_bindings_web,
--exclude=libparsec_bindings_electron,
--fix,
--allow-staged,
--,
--deny=warnings,
--deny=clippy::undocumented_unsafe_blocks,
--deny=clippy::unwrap_used,
]
####
# Js
# We use the same trick that for Python here: we run the tools with `npx`
# from the GUI project directory to reuse the installed dependencies.
- repo: local
hooks:
- id: eslint
name: eslint (using `npx`)
# Note we don't use `npx eslint` with `--prefix=./client` because it causes
# random compat issues since every sub-command expects to be run from
# the root of the node project.
entry: |
node -e "
const { spawnSync } = require('child_process');
const { exit, argv } = require('process');
let files = argv.slice(1).map(function (x) { return x.replace(/^client\//, '') });
let ret = spawnSync('npx', ['eslint', '--no-warn-ignored', '--max-warnings=0'].concat(files), {cwd: './client', stdio: 'inherit'});
exit(ret.status);
"
require_serial: true
language: system
files: ^client/
types_or: [vue, ts, tsx, javascript, jsx]
- id: vue-tsc
name: vue-tsc (using `npx`)
# Note we don't use `npx vue-tsc` with `--prefix=./client` because it causes
# random compat issues since every sub-command expects to be run from
# the root of the node project.
entry: |
node -e "
const { spawnSync } = require('child_process');
const { exit, argv } = require('process');
let files = argv.slice(1).map(function (x) { return x.replace(/^client\//, '') });
let ret = spawnSync('npx', ['vue-tsc', '--noEmit'].concat(files), {cwd: './client', stdio: 'inherit'});
exit(ret.status);
"
require_serial: true
language: system
files: ^client/
types_or: [vue, ts, tsx]
- id: prettier
name: prettier (using `npx`)
# Note we don't use `npx prettier` with `--prefix=./client` because it causes
# random compat issues since every sub-command expects to be run from
# the root of the node project.
entry: |
node -e "
const { spawnSync } = require('child_process');
const { exit, argv } = require('process');
let files = argv.slice(1).map(function (x) { return x.replace(/^client\//, '') });
let ret = spawnSync('npx', ['prettier', '--write'].concat(files), {cwd: './client', stdio: 'inherit'});
exit(ret.status);
"
require_serial: true
language: system
files: ^client/
types_or: [vue, ts, tsx, javascript, jsx, html]
######
# JSON
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.38.0
hooks:
- id: check-jsonschema
name: Validate protocol files with jsonschema
alias: check-protocol-schema
types_or: [json5]
files: ^libparsec/crates/protocol/schema/
args: [--schemafile, json_schema/protocol.schema.json]
additional_dependencies: [json5]
- id: check-jsonschema
name: Validate data files with jsonschema
alias: check-data-schema
types_or: [json5]
files: ^libparsec/crates/types/schema/
args: [--schemafile, json_schema/data.schema.json]
additional_dependencies: [json5]
- id: check-metaschema
files: ^json_schema/
- id: check-jsonschema
name: Validate dependabot config with jsonschema
alias: check-dependabot
files: .github/dependabot.yml
args:
[
--builtin-schema,
vendor.dependabot,
]
- id: check-jsonschema
name: Validate Read the doc configuration files
alias: check-readthedocs
files: .readthedocs.yml
args:
[
--builtin-schema,
vendor.readthedocs,
]
- id: check-jsonschema
name: Validate snapcraft config
alias: check-snapcraft
files: ^packaging/snap/snap/snapcraft.yaml
args:
[
--builtin-schema,
vendor.snapcraft,
]