-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.pre-commit-config.yaml
281 lines (262 loc) · 9.87 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
# Pre-commit configuration file.
# See https://pre-commit.com/
#
# Install pre-commit via
# python3 -m pip install --user --upgrade pre-commit
# Then install the git hook scripts in your project directory via
# cd path/to/your/project/root
# pre-commit install
# pre-commit install-hooks
# Now pre-commit will run automatically on every `git commit`.
# Bypass pre-commit and commit-msg hook with `git commit --no-verify`
# or bypass individual hooks with `SKIP=<hook_id> git commit`.
minimum_pre_commit_version: "3.0"
default_language_version:
python: "python3"
# Run pre-commit as CI workflow.
# See https://pre-commit.ci/
ci:
# Whether to autofix pull requests.
autofix_prs: false
# Interval for autoupdate.
autoupdate_schedule: "quarterly"
# TODO: Un-skip all hooks when all files have been revised. When this
# is done, the `lint` job in .github/workflows/tests.yml can be
# removed.
skip:
- "isort"
- "black"
- "flake8"
- "bandit"
########################################################################
# General Hooks #
########################################################################
repos:
- repo: "https://github.com/pre-commit/pre-commit-hooks"
rev: "v5.0.0"
hooks:
### Git ###
# Protect specific branches from direct check-ins.
- id: "no-commit-to-branch"
args: ["--branch", "main"]
### Security ###
# Detect the presence of private keys.
- id: "detect-private-key"
### Files ###
# Prevent giant files from being committed.
- id: "check-added-large-files"
# Check for files that would conflict in case-insensitive
# file systems.
- id: "check-case-conflict"
# Check for symlinks which do not point to anything.
- id: "check-symlinks"
# Detect symlinks which are changed to regular files.
- id: "destroyed-symlinks"
### Text ###
# Ensure that (non-binary) executables have a shebang.
- id: "check-executables-have-shebangs"
# Check for files that contain merge conflict strings.
- id: "check-merge-conflict"
# Ensure that a file is either empty, or ends with one newline.
- id: "end-of-file-fixer"
# Replace or checks mixed line ending.
- id: "mixed-line-ending"
args:
# Don't auto fix wrong line endings.
- "--fix=no"
# Trim trailing whitespace.
- id: "trailing-whitespace"
args:
# Preserve Markdown hard line breaks.
- "--markdown-linebreak-ext=md"
### Markup languages ###
# Check toml files for parseable syntax.
- id: "check-toml"
# Check xml files for parseable syntax.
- id: "check-xml"
# Check yaml files for parseable syntax.
- id: "check-yaml"
### json ###
# Check json files for parseable syntax.
- id: "check-json"
# VSCode supports comments in its json config files.
exclude: '\.vscode/.*\.json'
# Set a standard for formatting json files.
- id: "pretty-format-json"
# VSCode supports comments in its json config files.
exclude: '\.vscode/.*\.json'
### Python ###
# Check whether the files parse as valid Python.
- id: "check-ast"
# Check if docstrings come before the code.
- id: "check-docstring-first"
# Check for debug statements.
- id: "debug-statements"
# Verify that test files are named correctly.
- id: "name-tests-test"
args:
# Ensure tests match .*_test\.py
- "--pytest"
# Sort entries in requirements.txt.
- id: "requirements-txt-fixer"
######################################################################
# Validate CI Configuration Files #
######################################################################
- repo: "https://github.com/pre-commit-ci/pre-commit-ci-config"
rev: "v1.6.1"
hooks:
# Validate pre-commit.ci configuration.
- id: "check-pre-commit-ci-config"
- repo: "https://github.com/python-jsonschema/check-jsonschema"
rev: "0.29.4"
hooks:
# Validate Dependabot Config (v2) against the schema provided by
# SchemaStore.
- id: "check-dependabot"
# Validate GitHub Actions against the schema provided by
# SchemaStore.
- id: "check-github-actions"
# Validate GitHub Workflows against the schema provided by
# SchemaStore.
- id: "check-github-workflows"
# Validate GitLab CI config against the schema provided by
# SchemaStore.
# NOTE: Detects false positives for the code_quality job.
- id: "check-gitlab-ci"
# Validate ReadTheDocs config against the schema provided by
# ReadTheDocs.
- id: "check-readthedocs"
######################################################################
# Python Hooks #
######################################################################
- repo: "https://github.com/pre-commit/pygrep-hooks"
rev: "v1.10.0"
hooks:
# Enforce that `# noqa` comments always occur with specific codes.
- id: "python-check-blanket-noqa"
# Enforce that `# type: ignore` comments always occur with
# specific codes.
- id: "python-check-blanket-type-ignore"
# Prevent common mock mistakes.
- id: "python-check-mock-methods"
# Check if inline code touches normal text.
- id: "rst-inline-touching-normal"
- repo: "https://github.com/PyCQA/isort"
rev: "5.13.2"
hooks:
# Sort import statements with isort
- id: "isort"
args:
# Only check files without modifying them.
- "--check"
# Print a diff of all the changes isort would make.
- "--diff"
# Use color in terminal output.
- "--color"
additional_dependencies:
# Required for isort's `--color` option.
- "colorama"
- repo: "https://github.com/psf/black-pre-commit-mirror"
# Stay at black version 23, because some formatting rules change in
# version 24. Latest 23 version is 23.12.1.
rev: "23.12.1"
hooks:
# Format Python code with black.
- id: "black"
args:
# Only check files without modifying them.
- "--check"
# Print a diff of all the changes black would make.
- "--diff"
# Use color in terminal output.
- "--color"
- repo: "https://github.com/PyCQA/flake8"
rev: "7.1.1"
hooks:
# Lint Python code with Flake8.
- id: "flake8"
args:
# See .github/workflows/tests.yml.
- "--extend-ignore=S101,D205,D400,E203,W503,S404,S603,B028,N806,N813,W504,F821"
additional_dependencies:
# Required Flake8 plugins.
# Keep in sync with `requirements-dev.txt` and `.flake8`!
- "flake8-bandit >=4.0, <5.0"
- "flake8-bugbear >=24.0, <25.0"
- "flake8-builtins >=2.0, <3.0"
- "flake8-comprehensions >=3.0, <4.0"
- "flake8-docstrings >=1.0, <2.0"
- "flake8-isort >=6.0, <7.0"
- "flake8-logging-format >=0.1, <1.0"
- "flake8-pytest-style >=2.0, <3.0"
- "flake8-rst-docstrings >=0.2.6, <1.0"
- "pep8-naming >=0.1, <1.0"
- repo: "https://github.com/PyCQA/bandit"
rev: "1.7.10"
hooks:
# Check code security with bandit.
- id: "bandit"
args:
# Config file to use.
- "--configfile"
- "pyproject.toml"
# Number of code lines to output for each issue.
- "--number"
- "1"
# Find and process files in subdirectories.
- "--recursive"
additional_dependencies:
# Required to read config from pyproject.toml
- ".[toml]"
######################################################################
# Shell / Bash Hooks #
######################################################################
- repo: "https://github.com/maxwinterstein/shfmt-py"
rev: "v3.7.0.1"
hooks:
# Format shell scripts with shfmt.
# NOTE: The official shfmt hook from
# https://github.com/scop/pre-commit-shfmt requires Go or Docker
# to be installed. Therefore, we use the shfmt-py Python package
# instead.
- id: "shfmt"
args:
# Language variant to parse (bash/posix/mksh/bats).
- "-ln=bash"
# Indentation level.
- "-i=4"
# Indent switch cases.
- "-ci"
# Add a space after redirect operations (`>`).
- "-sr"
# List files whose formatting differs.
- "-l"
- repo: "https://github.com/shellcheck-py/shellcheck-py"
rev: "v0.10.0.1"
hooks:
# Lint shell scripts with shellcheck.
# NOTE: The official shellcheck hook from
# https://github.com/koalaman/shellcheck-precommit requires Docker
# to be installed. Therefore, we use the shellcheck-py Python
# package instead.
- id: "shellcheck"
args:
# Specify shell dialect (sh/bash/dash/ksh)
- "--shell=bash"
# Minimum severity to consider (error/warning/info/style)
- "--severity=style"
# Use color in terminal output.
- "--color=always"
######################################################################
# Markdown Hooks #
######################################################################
- repo: "https://github.com/markdownlint/markdownlint"
# openSUSE Leap 15.4 officially only provides ruby2.5 (which is also
# required for TeXLive).
# v0.12.0 requires ruby2.7
# v0.11.0 and v0.10.0 require ruby2.6
# => stay at v0.9.0
rev: "v0.9.0"
hooks:
# Lint Markdown files with markdownlint.
- id: "markdownlint"