Skip to content

Commit 7ae8211

Browse files
Organize the linting setup around tox+pre-commit (#657)
* Add a no-op check job to GHA for branch protection This patch adds an "empty" job that depends on all the important ones making it possible to use just this `check` job in the branch protection settings. This reduces the maintenance burden by preventing the need to update these settings on any changes to the job declarations. * Add a config for YAMLLint * Add a config for flake8 * Add an initial auto-generated PyLint config * Align pylint line length settings in with flake8 * Colorize the pylint report output * Correct spelling mistakes caught by `codespell` * Disable all currently violated PyLint rules * Start managing the linters setup with pre-commit Co-authored-by: Abhinav Singh <[email protected]>
1 parent 05f8a86 commit 7ae8211

File tree

4 files changed

+231
-6
lines changed

4 files changed

+231
-6
lines changed

.github/workflows/test-library.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ jobs:
2424
pip install -r requirements.txt
2525
pip install -r requirements-testing.txt
2626
pip install -r requirements-tunnel.txt
27-
- name: Quality Check
28-
run: |
29-
flake8 --ignore=W504 --max-line-length=127 --max-complexity=19 proxy/ tests/
30-
mypy --strict --ignore-missing-imports proxy/ tests/
3127
- name: Run Tests
3228
run: pytest --cov=proxy tests/
3329
- name: Upload coverage to Codecov
@@ -49,6 +45,7 @@ jobs:
4945
matrix:
5046
toxenv:
5147
- cleanup-dists,build-dists,metadata-validation
48+
- lint
5249
fail-fast: false
5350

5451
env:

.pre-commit-config.yaml

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
---
2+
repos:
3+
# - repo: https://github.com/asottile/add-trailing-comma.git
4+
# rev: v2.0.1
5+
# hooks:
6+
# - id: add-trailing-comma
7+
8+
# - repo: https://github.com/timothycrosley/isort.git
9+
# rev: 5.4.2
10+
# hooks:
11+
# - id: isort
12+
# args:
13+
# - --honor-noqa
14+
15+
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
16+
rev: v1.1.7
17+
hooks:
18+
- id: remove-tabs
19+
exclude: |
20+
(?x)
21+
^
22+
helper/proxy\.pac|
23+
Makefile|
24+
proxy/common/pki\.py|
25+
README\.md|
26+
.+\.(plist|pbxproj)
27+
$
28+
29+
- repo: https://github.com/pre-commit/pre-commit-hooks.git
30+
rev: v4.0.1
31+
hooks:
32+
# Side-effects:
33+
- id: trailing-whitespace
34+
exclude: |
35+
(?x)
36+
^
37+
\.github/workflows/codeql-analysis\.yml|
38+
dashboard/src/core/plugins/inspect_traffic\.json
39+
$
40+
- id: check-merge-conflict
41+
- id: double-quote-string-fixer
42+
exclude: |
43+
(?x)
44+
^
45+
(
46+
tests/(
47+
http/exceptions/test_http_proxy_auth_failed|
48+
plugin/test_http_proxy_plugins
49+
)|
50+
proxy/(
51+
common/constants|
52+
plugin/(cache/store/disk|filter_by_url_regex|proxy_pool)
53+
)
54+
)\.py
55+
$
56+
- id: end-of-file-fixer
57+
exclude: |
58+
(?x)
59+
^
60+
dashboard/(
61+
src/core/plugins/inspect_traffic\.json|
62+
static/bootstrap-4\.3\.1\.min\.(cs|j)s
63+
)|
64+
menubar/proxy\.py/(
65+
Assets\.xcassets/(
66+
AppIcon\.appiconset/|
67+
StatusBarButtonImage\.imageset/|
68+
)|
69+
Preview\sContent/Preview\sAssets\.xcassets/
70+
)Contents\.json|
71+
requirements-release\.txt
72+
$
73+
- id: requirements-txt-fixer
74+
exclude: >-
75+
^requirements(|-(release|testing|tunnel))\.txt$
76+
# Non-modifying checks:
77+
- id: name-tests-test
78+
args:
79+
- --django
80+
exclude: >-
81+
^tests/plugin/utils\.py$
82+
files: >-
83+
^tests/[^_].*\.py$
84+
- id: check-added-large-files
85+
- id: check-byte-order-marker
86+
- id: check-case-conflict
87+
# disabled due to pre-commit/pre-commit-hooks#159
88+
#- id: check-docstring-first
89+
- id: check-json
90+
- id: check-symlinks
91+
- id: check-yaml
92+
# args:
93+
# - --unsafe
94+
- id: detect-private-key
95+
96+
# Heavy checks:
97+
- id: check-ast
98+
- id: debug-statements
99+
100+
- repo: https://github.com/PyCQA/pydocstyle.git
101+
rev: 6.1.1
102+
hooks:
103+
- id: pydocstyle
104+
additional_dependencies:
105+
- toml
106+
args:
107+
- |-
108+
--ignore=
109+
D101,
110+
D102,
111+
D103,
112+
D105,
113+
D106,
114+
D107,
115+
D203,
116+
D205,
117+
D208,
118+
D209,
119+
D212,
120+
D213,
121+
D300,
122+
D400,
123+
D401,
124+
D402,
125+
D403,
126+
D404,
127+
D405,
128+
D407,
129+
D412,
130+
D413,
131+
D415,
132+
133+
- repo: https://github.com/codespell-project/codespell
134+
rev: v2.1.0
135+
hooks:
136+
- id: codespell
137+
exclude: >-
138+
^.+\.min\.js$
139+
140+
- repo: https://github.com/adrienverge/yamllint.git
141+
rev: v1.26.2
142+
hooks:
143+
- id: yamllint
144+
exclude: |
145+
(?x)
146+
^
147+
\.pre-commit-config\.yaml|
148+
(
149+
\.github/(
150+
workflows/(
151+
codeql-analysis|test-(brew|dashboard|docker|library)
152+
)|
153+
FUNDING
154+
)|
155+
codecov
156+
)\.yml
157+
$
158+
args:
159+
- --strict
160+
types: [file, yaml]
161+
162+
- repo: https://github.com/PyCQA/flake8.git
163+
rev: 3.9.2
164+
hooks:
165+
- id: flake8
166+
language_version: python3
167+
additional_dependencies:
168+
- flake8-2020 >= 1.6.0
169+
- flake8-docstrings >= 1.5.0
170+
- flake8-pytest-style >= 1.2.2
171+
- wemake-python-styleguide ~= 0.15.0
172+
173+
- repo: https://github.com/pre-commit/mirrors-mypy.git
174+
rev: v0.910
175+
hooks:
176+
- id: mypy
177+
args:
178+
# FIXME: get rid of missing imports ignore
179+
- --ignore-missing-imports
180+
- --install-types
181+
- --namespace-packages
182+
- --non-interactive
183+
- --pretty
184+
- --show-column-numbers
185+
- --show-error-codes
186+
- --show-error-context
187+
- --strict
188+
- --strict-optional
189+
- examples/
190+
- proxy/
191+
- tests/
192+
pass_filenames: false
193+
194+
- repo: local
195+
hooks:
196+
- id: pylint
197+
language: system
198+
name: PyLint
199+
files: \.py$
200+
entry: python -m pylint
201+
args: []
202+
stages:
203+
- manual

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ lib-clean:
8989
rm -rf .hypothesis
9090

9191
lib-lint:
92-
flake8 --ignore=W504 --max-line-length=127 --max-complexity=19 examples/ proxy/ tests/
93-
mypy --strict --ignore-missing-imports examples/ proxy/ tests/
92+
python -m tox -e lint
9493

9594
lib-test: lib-clean lib-version lib-lint
9695
pytest -v tests/

tox.ini

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,29 @@ commands =
6767
{envpython} -m twine check \
6868
--strict \
6969
{env:PEP517_OUT_DIR}{/}*
70+
71+
72+
[testenv:lint]
73+
description =
74+
Enforce quality standards under `{basepython}` ({envpython})
75+
commands =
76+
{envpython} -m \
77+
pre_commit run \
78+
--show-diff-on-failure \
79+
--hook-stage manual \
80+
{posargs:--all-files}
81+
82+
# Print out the advice on how to install pre-commit from this env into Git:
83+
-{envpython} -c \
84+
'cmd = "{envpython} -m pre_commit install"; \
85+
scr_width = len(cmd) + 10; \
86+
sep = "=" * scr_width; \
87+
cmd_str = " $ \{cmd\}";' \
88+
'print(f"\n\{sep\}\nTo install pre-commit hooks into the Git repo, run:\n\n\{cmd_str\}\n\n\{sep\}\n")'
89+
deps =
90+
pre-commit
91+
pylint >= 2.5.3
92+
pylint-pytest < 1.1.0
93+
-r requirements-tunnel.txt
94+
isolated_build = true
95+
skip_install = true

0 commit comments

Comments
 (0)