-
Notifications
You must be signed in to change notification settings - Fork 38
/
.pre-commit-config.yaml
345 lines (317 loc) · 11.2 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
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
exclude: ^misc/bench.py$
default_language_version:
rust: 1.81.0
node: 18.12.0
repos:
##############
# Common stuff
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0 # Use the ref you want to point at
hooks:
- id: mixed-line-ending
alias: eol
- id: trailing-whitespace
exclude_types: [svg]
- id: end-of-file-fixer
alias: eof
exclude_types: [svg]
# `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,
]
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.13.3
hooks:
- id: cspell
stages:
- manual
args:
- --config=./.cspell/cspell.config.yml
- --no-progress
- --dot
- --no-must-find-files
- --no-summary
- --gitignore
additional_dependencies:
- "@cspell/dict-en_us"
- "@cspell/dict-fr-fr"
- "@cspell/dict-fr-reforme"
- "@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]).
# To learn more about a specific error or warning, take a look at
# shellcheck's wiki (e.g. for SC1090 directive, see [2]).
# [0] https://github.com/koalaman/shellcheck-precommit
# [1] https://github.com/koalaman/shellcheck/issues/2495
# [2] https://www.shellcheck.net/wiki/SC1090
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
args: [--exclude=SC1090, --severity=warning]
########
# Python
# Long story short we cannot use pre-commit isolated venv system for mypy
# given mypy requires to have access to the project dependencies.
# We used to specify the list of dependencies actually needed by mypy as
# additional dependencies to install before running the pre-commit but it
# was incredibly error-prone and create random breakages.
# Instead we go the pragmatic way by calling mypy trough poetry:
# - `poetry run` will stick to the shell current virtual env
# - if the shell is not into a virtual env, poetry will create one and install Parsec&deps
# - lastly, mypy is started
# So this is similar to what the developer does when running mypy from it dev shell \o/
#
# Now that we use poetry to run mypy, why not also use it for ruff linter & formatter !
# This have the following benefits:
# - It prevents going out of sync in tools version between pre-commit-config
# and poetry.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 then.
- repo: local
hooks:
- id: ruff
name: ruff (using `poetry run ruff`)
# Wow this looks ugly ! But there is a reason why:
# - Ruff's `extend-exclude` doesn't work if it is not run from it config's folder
# - Pre-commit only run script from the repo root directory
# - A file passed as parameter is check by Ruff even if it part of `extend-exclude`
# - Splitting lines with YAML add heading whitespaces for no reason, and Python
# then complains about indentation :'(
#
# So (after a lot of pain) we came up with this: a one liner (because YAML)
# of a Python script that jumps in the correct directory (because pre-commit)
# to run Ruff on the whole codebase (because Ruff).
#
# Fortunately Ruff is (as cool kids say) blazingly fast, so it's no big
# deal to check everything on each run.
entry: poetry --directory ./server run python -c 'import os;os.chdir("./server");os.execlp("ruff", "ruff", "check", "--fix", "./parsec", "./tests", "../docs", "../make.py", "../misc");'
require_serial: true
pass_filenames: false
language: system
types_or: [python, pyi]
- id: black # Still named `black` as it makes a unique recognizable name
name: black (using `poetry run ruff format`)
entry: poetry --directory ./server run ruff format
require_serial: true
language: system
types_or: [python, pyi]
args: [--config=server/pyproject.toml]
- id: pyright
name: Pyright (using `poetry run pyright`)
entry: poetry --directory ./server run pyright
require_serial: true
language: system
types_or: [python, pyi]
args: [--project=server/]
- id: deptry
name: deptry (using `poetry run deptry server`)
entry: poetry --directory ./server run deptry server --config=server/pyproject.toml
files: ^server/
types_or: [python, pyproj]
pass_filenames: false # no need to pass filenames, deptry expects only the root directory to scan
require_serial: true
language: system
- id: sqlfluff
name: SQLFluff (using `poetry run ./misc/lint_sql.py`)
entry: poetry --directory ./server run ./misc/lint_sql.py --fix
types_or: [python, sql]
# TODO: currently SQL embedded in Python server code is dirty, so we ignore it
files: ^(server/parsec/components/postgresql/migrations/)|(libparsec/crates/platform_storage/src/native/)
require_serial: true
language: system
# powrap, script to fix indentation of .po files.
#
# - running with poetry in order to reuse environment from ./docs
# - using one-liner because pre-commit run script from the repo root directory
# - powrap is called via "make wrap" (see ./docs/Makefile)
- id: powrap
name: powrap (using `poetry --directory ./docs run make wrap`)
entry: poetry --directory ./docs run python -c 'import os;os.chdir("./docs");os.execlp("make", "make", "wrap");'
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_android,
--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_android,
--exclude=libparsec_bindings_web,
--exclude=libparsec_bindings_electron,
--fix,
--allow-staged,
--,
--deny=warnings,
--deny=clippy::undocumented_unsafe_blocks,
--deny=clippy::unwrap_used,
]
####
# Js
- repo: local
hooks:
- id: eslint
name: eslint
entry: eslint
language: node
files: ^client/
# see: https://github.com/pre-commit/identify/blob/master/identify/extensions.py
types_or: [vue, ts, tsx, javascript, jsx]
args: [--config=client/.eslintrc.cjs]
stages:
- manual
# Deps should be kept updated with `client/package-lock.json` !
additional_dependencies:
- "@intlify/[email protected]"
- "@typescript-eslint/[email protected]"
- "@typescript-eslint/[email protected]"
- "@vue/[email protected]"
- repo: local
hooks:
- id: prettier
name: prettier
entry: >-
npx prettier
--config=client/.prettierrc.json5
--ignore-path=client/.prettierignore
--write
language: node
files: ^client/
types_or: [vue, ts, tsx, javascript, jsx, html]
stages:
- manual
additional_dependencies:
######
# JSON
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.2
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 Read the doc configuration files
alias: check-readthedocs
files: .readthedocs.yml
args:
[
--schemafile,
https://raw.githubusercontent.com/readthedocs/readthedocs.org/main/readthedocs/rtd_tests/fixtures/spec/v2/schema.json,
]
- id: check-jsonschema
name: Validate snapcraft config
alias: check-snapcraft
files: ^packaging/snap/snap/snapcraft.yaml
args:
[
--schemafile,
https://raw.githubusercontent.com/snapcore/snapcraft/main/schema/snapcraft.json,
]