-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
225 lines (209 loc) · 8.47 KB
/
.pre-commit-config.yaml
File metadata and controls
225 lines (209 loc) · 8.47 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
# To enable this pre-commit hook run:
# `pip install pre-commit` or `brew install pre-commit`
# Then run `pre-commit install`
# Learn more about this config here: https://pre-commit.com/
default_language_version:
python: python3.12
ci:
submodules: true
autoupdate_schedule: "monthly"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-toml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
exclude: ^.*\.(po|pot|type|svg|ini|mr|mrc|pg_dump)$
- id: mixed-line-ending
args:
- --fix=lf
- id: requirements-txt-fixer
- id: trailing-whitespace
args:
- --markdown-linebreak-ext=md
- repo: https://github.com/MarcoGorelli/auto-walrus
rev: 0.4.1
hooks:
- id: auto-walrus
- repo: https://github.com/sqlfluff/sqlfluff
rev: 4.1.0
hooks:
- id: sqlfluff-lint
args: [--dialect, postgres]
files: \.sql$
# Rule exclusions and their rationale are documented in pyproject.toml
# under [tool.sqlfluff.core].
# patron_data.sql contains raw PostgreSQL COPY data rows with tab-separated
# values and \N nulls which sqlfluff cannot parse.
# import-partial.sql uses a psql variable placeholder (:source) in a COPY
# command which sqlfluff cannot parse.
# See: https://github.com/internetarchive/openlibrary/issues/12245
exclude: ^(scripts/dev-instance/patron_data\.sql|scripts/solr_builder/sql/import-partial\.sql)$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.9
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format
# Exclude files currently touched by open (non-draft) PRs to avoid merge conflicts.
# List generated with: gh pr list --state open --draft=false --json files --jq '.[].files[].path' | sort | uniq
# Uses YAML literal block scalar (|) + (?x) verbose regex flag so each file is on
# its own line. Unlike >- (folded scalar), | preserves newlines exactly. The (?x)
# flag tells Python's re engine to ignore all whitespace/newlines in the pattern,
# so the leading | on each line works correctly as an alternation operator.
exclude: |
(?x)^(
openlibrary/accounts/model\.py
|openlibrary/catalog/add_book/__init__\.py
|openlibrary/core/lists/model\.py
|openlibrary/core/models\.py
|openlibrary/core/vendors\.py
|openlibrary/fastapi/search\.py
|openlibrary/plugins/admin/code\.py
|openlibrary/plugins/openlibrary/api\.py
|openlibrary/plugins/openlibrary/bulk_tag\.py
|openlibrary/plugins/openlibrary/code\.py
|openlibrary/plugins/openlibrary/lists\.py
|openlibrary/plugins/openlibrary/status\.py
|openlibrary/plugins/upstream/addbook\.py
|openlibrary/plugins/upstream/addtag\.py
|openlibrary/plugins/upstream/code\.py
|openlibrary/plugins/upstream/covers\.py
|openlibrary/plugins/upstream/jsdef\.py
|openlibrary/plugins/upstream/utils\.py
|openlibrary/plugins/worksearch/code\.py
|openlibrary/plugins/worksearch/schemes/__init__\.py
|openlibrary/plugins/worksearch/schemes/authors\.py
|openlibrary/plugins/worksearch/schemes/lists\.py
|openlibrary/plugins/worksearch/schemes/subjects\.py
|openlibrary/plugins/worksearch/schemes/works\.py
|openlibrary/utils/form\.py
|openlibrary/utils/request_context\.py
|openlibrary/utils/schema\.py
|scripts/find_duplicate_author\.py
|scripts/monitoring/fail2ban_monitor\.py
|scripts/monitoring/monitor\.py
|scripts/update_stale_ocaid_references\.py
)$
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.3.1
hooks:
- id: black # See pyproject.toml for args
# Complement to ruff-format above: black runs ONLY on files in active open PRs
# (the same set ruff-format excludes). Uses same (?x) + | literal block approach.
files: |
(?x)^(
openlibrary/accounts/model\.py
|openlibrary/catalog/add_book/__init__\.py
|openlibrary/core/lists/model\.py
|openlibrary/core/models\.py
|openlibrary/core/vendors\.py
|openlibrary/fastapi/search\.py
|openlibrary/plugins/admin/code\.py
|openlibrary/plugins/openlibrary/api\.py
|openlibrary/plugins/openlibrary/bulk_tag\.py
|openlibrary/plugins/openlibrary/code\.py
|openlibrary/plugins/openlibrary/lists\.py
|openlibrary/plugins/openlibrary/status\.py
|openlibrary/plugins/upstream/addbook\.py
|openlibrary/plugins/upstream/addtag\.py
|openlibrary/plugins/upstream/code\.py
|openlibrary/plugins/upstream/covers\.py
|openlibrary/plugins/upstream/jsdef\.py
|openlibrary/plugins/upstream/utils\.py
|openlibrary/plugins/worksearch/code\.py
|openlibrary/plugins/worksearch/schemes/__init__\.py
|openlibrary/plugins/worksearch/schemes/authors\.py
|openlibrary/plugins/worksearch/schemes/lists\.py
|openlibrary/plugins/worksearch/schemes/subjects\.py
|openlibrary/plugins/worksearch/schemes/works\.py
|openlibrary/utils/form\.py
|openlibrary/utils/request_context\.py
|openlibrary/utils/schema\.py
|scripts/find_duplicate_author\.py
|scripts/monitoring/fail2ban_monitor\.py
|scripts/monitoring/monitor\.py
|scripts/update_stale_ocaid_references\.py
)$
- repo: https://github.com/codespell-project/codespell
rev: v2.4.2
hooks:
- id: codespell # See pyproject.toml for args
additional_dependencies:
- tomli
args: ["--skip", "*.mjs"]
exclude: ^(openlibrary/plugins/upstream/utils\.py|openlibrary/catalog/marc/parse\.py|openlibrary/catalog/add_book/match\.py)$
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.19.0
hooks:
- id: cython-lint
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.19.1
hooks:
- id: mypy # See pyproject.toml for args
additional_dependencies:
- types-PyYAML
- types-aiofiles
- types-python-dateutil
- types-requests
- types-simplejson
- fastapi
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.25
hooks:
- id: validate-pyproject
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v9.9.1
hooks:
- id: eslint
types: [file]
types_or: [javascript, vue]
additional_dependencies:
- eslint@9.39.4
- "@eslint/js@9.39.4"
- eslint-plugin-no-jquery@3.1.1
- eslint-plugin-vue@9.32.0
- globals@15.14.0
- "@babel/eslint-parser@7.24.7"
- "@babel/core@7.24.7"
- "@babel/preset-env@7.24.7"
args: [--fix]
- repo: https://github.com/awebdeveloper/pre-commit-stylelint
rev: 0.0.2
hooks:
- id: stylelint
files: \.css$
additional_dependencies:
- stylelint@16.22.0
- stylelint-declaration-strict-value@1.11.1
- stylelint-prettier@5.0.3
args: [--fix]
- repo: local
hooks:
- id: generate-pot
name: Generate POT
description: This hook generates the .pot file for internationalization.
entry: python ./scripts/i18n-messages extract --skip-untracked
types_or: [python, html]
language: python
pass_filenames: false
# Dependencies must be manually updated to match versions in requirements.txt
additional_dependencies:
- Babel==2.12.1
- multipart==0.2.4
- "git+https://github.com/webpy/webpy.git@d3649322b85777b291ac2b7b3699fb6fc839e382"
- fastapi==0.119.0 # annoyingly, these three needed to be added when we started using contextvars in i18n files
- simplejson==3.19.1
- requests==2.32.4
- repo: local
hooks:
- id: detect-missing-i18n
name: Detect missing i18n
description: This hook checks .html files for i18n strings that might be missing.
entry: python ./scripts/detect_missing_i18n.py
types: [html]
language: python
verbose: true
require_serial: true