|
2 | 2 | #
|
3 | 3 | # __init__.py
|
4 | 4 | """
|
5 |
| -A flake8 plugin which checks for use of platform specific strftime codes. |
| 5 | +A Flake8 plugin which checks for use of platform specific strftime codes. |
6 | 6 | """
|
7 | 7 | #
|
8 | 8 | # Copyright (c) 2020 Dominic Davis-Foster <[email protected]>
|
|
33 | 33 | import ast
|
34 | 34 | import re
|
35 | 35 | import sys
|
36 |
| -from typing import Any, Dict, Generator, List, Tuple, Type, Union |
| 36 | +from typing import Dict, Union |
| 37 | + |
| 38 | +# 3rd party |
| 39 | +import flake8_helper |
37 | 40 |
|
38 | 41 | __all__ = ["Visitor", "Plugin", "STRFTIME001", "STRFTIME002"]
|
39 | 42 |
|
40 | 43 | __author__ = "Dominic Davis-Foster"
|
41 |
| -__copyright__ = "2020 Dominic Davis-Foster" |
| 44 | +__copyright__ = "2020-2021 Dominic Davis-Foster" |
42 | 45 | __license__ = "MIT"
|
43 | 46 | __version__ = "0.2.1"
|
44 | 47 |
|
|
47 | 50 | STRFTIME002 = "STRFTIME002 Windows-specific strftime code used." # noqa: E501
|
48 | 51 |
|
49 | 52 |
|
50 |
| -class Visitor(ast.NodeVisitor): # noqa: D101 |
| 53 | +class Visitor(flake8_helper.Visitor): # noqa: D101 |
51 | 54 |
|
52 | 55 | def __init__(self) -> None:
|
53 |
| - self.errors: List[Tuple[int, int, str]] = [] |
| 56 | + super().__init__() |
54 | 57 | self._from_imports: Dict[str, str] = {}
|
55 | 58 |
|
56 | 59 | if sys.version_info < (3, 8): # pragma: no cover (PY38+)
|
@@ -109,26 +112,13 @@ def _check_windows(self, node: Union[ast.Str, ast.Constant]):
|
109 | 112 | ))
|
110 | 113 |
|
111 | 114 |
|
112 |
| -class Plugin: |
| 115 | +class Plugin(flake8_helper.Plugin[Visitor]): |
113 | 116 | """
|
114 |
| - The flake8 plugin. |
| 117 | + A Flake8 plugin which checks for use of platform specific strftime codes. |
115 | 118 |
|
116 |
| - :param tree: |
| 119 | + :param tree: The abstract syntax tree (AST) to check. |
117 | 120 | """
|
118 | 121 |
|
119 | 122 | name: str = __name__
|
120 |
| - version: str = __version__ |
121 |
| - |
122 |
| - def __init__(self, tree: ast.AST): |
123 |
| - self._tree = tree |
124 |
| - |
125 |
| - def run(self) -> Generator[Tuple[int, int, str, Type[Any]], None, None]: |
126 |
| - """ |
127 |
| - Run the plugin. |
128 |
| - """ |
129 |
| - |
130 |
| - visitor = Visitor() |
131 |
| - visitor.visit(self._tree) |
132 |
| - |
133 |
| - for line, col, msg in visitor.errors: |
134 |
| - yield line, col, msg, type(self) |
| 123 | + version: str = __version__ #: The plugin version |
| 124 | + visitor_class = Visitor |
0 commit comments