-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pre-commit-config.yaml
302 lines (280 loc) · 11.7 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
##########################################################################################
# #
# Pre-commit configuration file #
# #
##########################################################################################
# https://blog.mphomphego.co.za/blog/2019/10/03/Why-you-need-to-stop-using-Git-Hooks.html
---
default_language_version:
python: python3
repos:
####################################### Various Checks ###############################
# Various checks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-ast
name: check-ast
description: Simply check whether files parse as valid python.
- id: check-builtin-literals
name: check-builtin-literals
description: Require literal syntax when initializing empty,
or zero Python builtin types.
- id: check-docstring-first
name: check-docstring-first
description: Checks for a common error of placing code before the docstring.
- id: check-added-large-files
name: check-added-large-files
description: Prevent giant files from being committed.
- id: check-merge-conflict
name: check-merge-conflict
description: Check for files that contain merge conflict strings.
- id: check-symlinks
name: check-symlinks
description: Checks for symlinks which do not point to anything.
- id: check-yaml
name: check-yaml
description: Attempts to load all yaml files to verify syntax.
- id: check-toml
name: check-toml
description: Attempts to load all TOML files to verify syntax.
- id: debug-statements
name: debug-statements
description: Check for debugger imports and py37+ breakpoint() calls in python source.
- id: detect-private-key
name: detect-private-key
description: Checks for the existence of private keys.
- id: end-of-file-fixer
name: end-of-file-fixer
description: Makes sure files end in a newline and only a newline.
- id: trailing-whitespace
name: trailing-whitespace
description: Trims trailing whitespace
- id: requirements-txt-fixer
name: requirements-txt-fixer
description: Sorts entries in requirements.txt
- repo: local
hooks:
# Python minor syntax related checks
# https://github.com/Pike/pygrep
- id: python-check-mock-methods
name: python-check-mock-methods
description: Prevent common mistakes of `assert mck.not_called()`, `assert mck.called_once_with(...)`
and `mck.assert_called`.
language: pygrep
entry: >
(?x)(
assert .*\.(
not_called|
called_
)|
\.assert_(
any_call|
called|
called_once|
called_once_with|
called_with|
has_calls|
not_called
)($|[^(\w])
)
types: [python]
- id: python-no-eval
name: python-no-eval
description: 'A quick check for the `eval()` built-in function'
entry: '\beval\('
language: pygrep
types: [python]
- id: python-no-log-warn
name: python-no-log-warn
description: 'A quick check for the deprecated `.warn()` method of python loggers'
entry: '(?<!warnings)\.warn\('
language: pygrep
types: [python]
- id: python-use-type-annotations
name: python-use-type-annotations
description: 'Enforce that python3.6+ type annotations are used instead of type comments'
entry: '# type(?!: *ignore *($|#))'
language: pygrep
types: [python]
# Python security check
# https://bandit.readthedocs.io/en/latest/
- id: bandit
name: bandit
description: Find common security issues in your Python code using bandit
entry: bandit
args: [
'-ll',
'--ini', 'setup.cfg',
'--recursive',
]
language: python
types: [python]
# Vulture
# https://github.com/jendrikseipp/vulture
- id: vulture
name: vulture
description: Find dead Python code
entry: vulture
args: [
"--min-confidence", "90",
"--exclude", "*env*", "docs/",
".",
]
language: system
types: [python]
####################################### Linters ######################################
- repo: local
hooks:
# Flake8 Linter
# https://flake8.pycqa.org/en/latest/
- id: flake8
name: flake8
description: Python style guide enforcement
entry: flake8
args: ["--config=.flake8"]
additional_dependencies: [
flake8-2020, # flake8 plugin which checks for misuse of `sys.version` or `sys.version_info`
flake8-blind-except, # A flake8 extension that checks for blind except: statements
flake8-bugbear, # A plugin for flake8 finding likely bugs and design problems in your program.
# Contains warnings that don't belong in pyflakes and pycodestyle.
flake8-builtins, # Check for python builtins being used as variables or parameters.
flake8-comprehensions, # It helps you write a better list/set/dict comprehensions.
flake8-copyright, # Adds copyright checks to flake8
flake8-deprecated, # Warns about deprecated method calls.
dlint, # Dlint is a tool for encouraging best coding practices and helping ensure we're writing secure Python code.
flake8-docstrings, # Extension for flake8 which uses pydocstyle to check docstrings
# flake8-eradicate, # Flake8 plugin to find commented out code
flake8-license,
pandas-vet, # A Flake8 plugin that provides opinionated linting for pandas code
flake8-pytest, # pytest assert checker plugin for flake8
flake8-variables-names, # flake8 extension that helps to make more readable variables names
flake8-tabs, # Tab (or Spaces) indentation style checker for flake8
pep8-naming, # Check PEP-8 naming conventions, plugin for flake8
]
language: python
types: [python]
# MyPy Linter
# https://mypy.readthedocs.io/en/latest/
- id: mypy
name: mypy
description: Optional static typing for Python 3 and 2 (PEP 484)
entry: mypy
args: ["--config-file", "setup.cfg"]
language: python
types: [python]
# PyDocstyle
# https://github.com/PyCQA/pydocstyle
# - id: pydocstyle
# name: pydocstyle
# description: pydocstyle is a static analysis tool for checking compliance with Python docstring conventions.
# entry: pydocstyle
# args: ["--config=setup.cfg", "--count"]
# language: python
# types: [python]
# YAML Linter
# - id: yamllint
# name: yamllint
# description: A linter for YAML files.
# # https://yamllint.readthedocs.io/en/stable/configuration.html#custom-configuration-without-a-config-file
# entry: yamllint
# args: [
# '--format', 'parsable',
# '--strict',
# '-d', "{
# extends: relaxed,
# rules: {
# hyphens: {max-spaces-after: 4},
# indentation: {spaces: consistent, indent-sequences: whatever,},
# key-duplicates: {},
# line-length: {max: 90}},
# }"
# ]
# language: system
# types: [python]
# additional_dependencies: [yamllint]
# Shell Linter
# NOTE: Hook requires shellcheck [installed].
- id: shellcheck
name: shellcheck (local)
language: script
entry: scripts/shellcheck.sh
types: [shell]
args: [-e, SC1091]
additional_dependencies: [shellcheck]
# Prose (speech or writing) Linter
- id: proselint
name: proselint
description: An English prose (speech or writing) linter
entry: proselint
language: system
types: [ rst, markdown ]
additional_dependencies: [proselint]
################################### Code Format ######################################
- repo: local
hooks:
# pyupgrade
# Upgrade Python syntax
- id: pyupgrade
name: pyupgrade
description: Automatically upgrade syntax for newer versions of the language.
entry: pyupgrade
args: ['--py3-plus']
language: python
types: [python]
additional_dependencies: [pyupgrade]
# Sort imports
# https://github.com/timothycrosley/isort
- id: isort
name: isort
description: Library to sort imports.
entry: isort
args: [
"--recursive",
"--settings-path", ".isort.cfg"
]
language: python
types: [python]
# Manifest.in checker
# https://github.com/mgedmin/check-manifest
# - id: check-manifest
# name: check-manifest
# description: Check the completeness of MANIFEST.in for Python packages.
# entry: check-manifest
# language: python
# types: [python]
# pycodestyle code format
# https://pypi.python.org/pypi/autopep8/
# - id: autopep8
# name: autopep8
# description: A tool that automatically formats Python code to conform to the PEP 8 style guide.
# entry: autopep8
# args: [
# '--in-place',
# '--aggressive', '--aggressive',
# '--global-config', 'setup.cfg',
# ]
# language: python
# types: [python]
# Python code format
# https://github.com/psf/black/
- id: black
name: black
description: The uncompromising Python code formatter
entry: black
args: [
'--line-length', '90',
'--target-version', 'py36'
]
language: python
types: [python]
################################### Test Runner ##########################################
- repo: local
hooks:
- id: tests
name: run tests
description: Run pytest
entry: pytest -sv
language: system
types: [python]
stages: [push]