Skip to content

Commit 7ce540e

Browse files
committed
Refactor using the new flake8-helper library.
1 parent 6cf98af commit 7ce540e

File tree

5 files changed

+43
-51
lines changed

5 files changed

+43
-51
lines changed

flake8_sphinx_links/__init__.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@
3535
import platform
3636
import re
3737
import sys
38-
from typing import Any, Dict, Generator, List, Pattern, Tuple, Type, Union
38+
from typing import Dict, List, Pattern, Union
39+
40+
# 3rd party
41+
import flake8_helper
3942

4043
__author__: str = "Dominic Davis-Foster"
41-
__copyright__: str = "2020 Dominic Davis-Foster"
44+
__copyright__: str = "2020-2021 Dominic Davis-Foster"
4245
__license__: str = "MIT"
4346
__version__: str = "0.1.0"
4447
__email__: str = "dominic@davis-foster.co.uk"
@@ -56,7 +59,7 @@
5659

5760
SXL001: str = "SXL001 Double backticked strings should be a link to Python documentation." # noqa: E501
5861

59-
#: List of keywords that should become :file:`:py:obj:\`{<keyword>}\``
62+
#: List of keywords which should become :file:`:py:obj:\`{<keyword>}\``
6063
py_obj: List[str] = [
6164
"True",
6265
"False",
@@ -76,7 +79,7 @@
7679
to prevent conflict with Sphinx objects.
7780
"""
7881

79-
#: List of keywords that should become :file:`:py:exc:\`{<keyword>}\``
82+
#: List of keywords which should become :file:`:py:exc:\`{<keyword>}\``
8083
exc: List[str] = [
8184
"BaseException",
8285
"Exception",
@@ -174,14 +177,14 @@
174177
regex: Pattern = re.compile(fr"(``)({all_objs})(``)")
175178

176179

177-
class Visitor(ast.NodeVisitor):
180+
class Visitor(flake8_helper.Visitor):
178181
"""
179-
A Flake8 plugin to check docstrings for double backticked strings
182+
AST visitor to check docstrings for double backticked strings
180183
which should be links to the Python documentation.
181184
""" # noqa: D400
182185

183186
def __init__(self) -> None:
184-
self.errors: List[Tuple[int, int, str]] = []
187+
super().__init__()
185188
self._from_imports: Dict[str, str] = {}
186189

187190
def _check_docstring(self, node: Union[ast.ClassDef, ast.FunctionDef, ast.Module]) -> None:
@@ -242,26 +245,12 @@ def visit_Module(self, node: ast.Module) -> None: # noqa: D102
242245
super().generic_visit(node)
243246

244247

245-
class Plugin:
246-
"""
247-
Flake8 plugin which checks for use of platform specific sphinx_links codes.
248+
class Plugin(flake8_helper.Plugin[Visitor]):
248249
"""
250+
Flake8 plugin to check docstrings for double backticked strings
251+
which should be links to the Python documentation.
252+
""" # noqa: D400
249253

250254
name: str = __name__
251255
version: str = __version__
252-
253-
def __init__(self, tree: ast.AST):
254-
self._tree = tree
255-
256-
def run(self) -> Generator[Tuple[int, int, str, Type[Any]], None, None]:
257-
"""
258-
Traverse the Abstract Syntax Tree, extract docstrings and check them.
259-
260-
Yields a tuple of (line number, column offset, error message, type(self))
261-
"""
262-
263-
visitor = Visitor()
264-
visitor.visit(self._tree)
265-
266-
for line, col, msg in visitor.errors:
267-
yield line, col, msg, type(self)
256+
visitor_class = Visitor

formate.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ known_third_party = [
3737
"coverage_pyver_pragma",
3838
"domdf_python_tools",
3939
"flake8",
40+
"flake8_helper",
4041
"github",
4142
"pytest",
4243
"pytest_cov",

repo_helper.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ min_coverage: 100
4141

4242
sphinx_conf_epilogue:
4343
- nitpicky = True
44+
45+
tox_unmanaged:
46+
- testenv:lint

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
flake8>=3.7
2+
flake8-helper>=0.1.1

tox.ini

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# * testenv
66
# * testenv:docs
77
# * testenv:build
8-
# * testenv:lint
98
# * testenv:mypy
109
# * testenv:pyup
1110
# * testenv:coverage
@@ -56,30 +55,6 @@ commands =
5655
twine check dist/*.tar.gz dist/*.whl
5756
check-wheel-contents dist/
5857

59-
[testenv:lint]
60-
basepython = python3.6
61-
changedir = {toxinidir}
62-
ignore_errors = True
63-
skip_install = True
64-
deps =
65-
flake8 >=3.8.2
66-
flake8-2020 >= 1.6.0
67-
flake8-builtins>=1.5.3
68-
flake8-docstrings>=1.5.0
69-
flake8-dunder-all>=0.1.1
70-
flake8-github-actions>=0.1.0
71-
flake8-pyi>=20.10.0
72-
flake8-pytest-style>=1.3.0
73-
flake8-sphinx-links>=0.0.4
74-
flake8-strftime>=0.1.1
75-
flake8-typing-imports>=1.10.0
76-
git+https://github.com/PyCQA/pydocstyle@5118faa7173b0e5bbc230c4adf628758e13605bf
77-
git+https://github.com/domdfcoding/flake8-quotes.git
78-
git+https://github.com/domdfcoding/flake8-rst-docstrings.git
79-
git+https://github.com/domdfcoding/flake8-rst-docstrings-sphinx.git
80-
pygments>=2.7.1
81-
commands = python3 -m flake8_rst_docstrings_sphinx flake8_sphinx_links tests --allow-toolbox {posargs}
82-
8358
[testenv:mypy]
8459
basepython = python3.6
8560
ignore_errors = True
@@ -151,5 +126,28 @@ package = flake8_sphinx_links
151126
addopts = --color yes --durations 25
152127
timeout = 300
153128
129+
[testenv:lint]
130+
basepython = python3.6
131+
changedir = {toxinidir}
132+
ignore_errors = True
133+
deps =
134+
flake8 >=3.8.2
135+
flake8-2020 >= 1.6.0
136+
flake8-builtins>=1.5.3
137+
flake8-docstrings>=1.5.0
138+
flake8-dunder-all>=0.1.1
139+
flake8-github-actions>=0.1.0
140+
flake8-pyi>=20.10.0
141+
flake8-pytest-style>=1.3.0
142+
flake8-sphinx-links>=0.0.4
143+
flake8-strftime>=0.1.1
144+
flake8-typing-imports>=1.10.0
145+
git+https://github.com/PyCQA/pydocstyle@5118faa7173b0e5bbc230c4adf628758e13605bf
146+
git+https://github.com/domdfcoding/flake8-quotes.git
147+
git+https://github.com/domdfcoding/flake8-rst-docstrings.git
148+
git+https://github.com/domdfcoding/flake8-rst-docstrings-sphinx.git
149+
pygments>=2.7.1
150+
commands = python3 -m flake8_rst_docstrings_sphinx flake8_sphinx_links tests --allow-toolbox {posargs}
151+
154152
[dep_checker]
155153
allowed_unused = flake8

0 commit comments

Comments
 (0)