Skip to content

Commit 54b250c

Browse files
committed
🧪 Add Python linters to pre-commit.ci
1 parent 967acbb commit 54b250c

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

.pre-commit-config.yaml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ ci:
33
autoupdate_schedule: quarterly
44

55
repos:
6+
- repo: https://github.com/asottile/add-trailing-comma.git
7+
rev: v2.3.0
8+
hooks:
9+
- id: add-trailing-comma
10+
11+
- repo: https://github.com/PyCQA/isort.git
12+
rev: 5.10.1
13+
hooks:
14+
- id: isort
15+
args:
16+
- --honor-noqa
17+
618
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
719
rev: v1.3.1
820
hooks:
@@ -31,6 +43,9 @@ repos:
3143
- id: trailing-whitespace
3244
- id: mixed-line-ending
3345
# Non-modifying checks:
46+
- id: name-tests-test
47+
files: >-
48+
^tests/[^_].*\.py$
3449
- id: check-added-large-files
3550
- id: check-byte-order-marker
3651
- id: check-case-conflict
@@ -40,6 +55,10 @@ repos:
4055
- id: check-symlinks
4156
- id: check-yaml
4257
- id: detect-private-key
58+
# Heavy checks:
59+
- id: check-ast
60+
- id: debug-statements
61+
language_version: python3
4362

4463
- repo: https://github.com/codespell-project/codespell
4564
rev: v2.2.1
@@ -57,4 +76,106 @@ repos:
5776
args:
5877
- --strict
5978

79+
- repo: https://github.com/PyCQA/flake8.git
80+
rev: 6.0.0
81+
hooks:
82+
- id: flake8
83+
alias: flake8-no-wps
84+
name: flake8 WPS-excluded
85+
args:
86+
- --ignore
87+
- >-
88+
D100,
89+
D101,
90+
D103,
91+
D107,
92+
E402,
93+
E501,
94+
additional_dependencies:
95+
- flake8-2020 ~= 1.7.0
96+
- flake8-pytest-style ~= 1.6.0
97+
language_version: python3
98+
99+
- repo: https://github.com/PyCQA/flake8.git
100+
# NOTE: This is kept at v4 for until WPS starts supporting flake v5.
101+
rev: 4.0.1 # enforce-version: 4.0.1
102+
hooks:
103+
- id: flake8
104+
alias: flake8-only-wps
105+
name: flake8 WPS-only
106+
args:
107+
- --ignore
108+
- >-
109+
WPS102,
110+
WPS110,
111+
WPS111,
112+
WPS305,
113+
WPS347,
114+
WPS360,
115+
WPS421,
116+
WPS422,
117+
WPS432,
118+
WPS433,
119+
WPS437,
120+
WPS440,
121+
WPS441,
122+
WPS453,
123+
- --select
124+
- WPS
125+
additional_dependencies:
126+
- wemake-python-styleguide ~= 0.16.1
127+
language_version: python3
128+
129+
- repo: https://github.com/PyCQA/pylint.git
130+
rev: v2.15.3
131+
hooks:
132+
- id: pylint
133+
args:
134+
- --disable
135+
- >-
136+
import-error,
137+
invalid-name,
138+
line-too-long,
139+
missing-class-docstring,
140+
missing-function-docstring,
141+
missing-module-docstring,
142+
protected-access,
143+
super-init-not-called,
144+
unused-argument,
145+
wrong-import-position,
146+
- --output-format
147+
- colorized
148+
149+
- repo: local
150+
hooks:
151+
- id: enforced-flake8-version
152+
name: Verify that enforced flake8 version stays unchanged
153+
description: >-
154+
This is a sanity check and fixer that makes sure that
155+
the `flake8` version in this file remains matching the
156+
corresponding request in the `# enforce-version` comment.
157+
# Using Python here because using
158+
# shell test does not always work in CIs:
159+
entry: >-
160+
python -c 'import pathlib, re, sys;
161+
pre_commit_config = pathlib.Path(sys.argv[1]);
162+
cfg_txt = pre_commit_config.read_text();
163+
new_cfg_txt = re.sub(
164+
r"(?P<spaces>\s+)rev:\s(?:\d+\.\d+\.\d+)\s{0,2}"
165+
r"#\senforce-version:\s(?P<enforced_version>\d+\.\d+\.\d+)"
166+
r"[ \t\f\v]*",
167+
r"\g<spaces>rev: \g<enforced_version> "
168+
r"# enforce-version: \g<enforced_version>",
169+
cfg_txt,
170+
);
171+
cfg_txt != new_cfg_txt and
172+
pre_commit_config.write_text(new_cfg_txt)
173+
'
174+
pass_filenames: true
175+
language: system
176+
files: >-
177+
^\.pre-commit-config\.ya?ml$
178+
types:
179+
- yaml
180+
60181
...

0 commit comments

Comments
 (0)