Skip to content

Commit ee79ac2

Browse files
committed
Refactor using new flake8-helper library.
1 parent 8eb6c22 commit ee79ac2

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

flake8_strftime/__init__.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# __init__.py
44
"""
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.
66
"""
77
#
88
# Copyright (c) 2020 Dominic Davis-Foster <[email protected]>
@@ -33,12 +33,15 @@
3333
import ast
3434
import re
3535
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
3740

3841
__all__ = ["Visitor", "Plugin", "STRFTIME001", "STRFTIME002"]
3942

4043
__author__ = "Dominic Davis-Foster"
41-
__copyright__ = "2020 Dominic Davis-Foster"
44+
__copyright__ = "2020-2021 Dominic Davis-Foster"
4245
__license__ = "MIT"
4346
__version__ = "0.2.1"
4447
__email__ = "[email protected]"
@@ -47,10 +50,10 @@
4750
STRFTIME002 = "STRFTIME002 Windows-specific strftime code used." # noqa: E501
4851

4952

50-
class Visitor(ast.NodeVisitor): # noqa: D101
53+
class Visitor(flake8_helper.Visitor): # noqa: D101
5154

5255
def __init__(self) -> None:
53-
self.errors: List[Tuple[int, int, str]] = []
56+
super().__init__()
5457
self._from_imports: Dict[str, str] = {}
5558

5659
if sys.version_info < (3, 8): # pragma: no cover (PY38+)
@@ -109,26 +112,13 @@ def _check_windows(self, node: Union[ast.Str, ast.Constant]):
109112
))
110113

111114

112-
class Plugin:
115+
class Plugin(flake8_helper.Plugin[Visitor]):
113116
"""
114-
The flake8 plugin.
117+
A Flake8 plugin which checks for use of platform specific strftime codes.
115118
116-
:param tree:
119+
:param tree: The abstract syntax tree (AST) to check.
117120
"""
118121

119122
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

repo_helper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
---
33
modname: flake8_strftime
44
repo_name: flake8_strftime
5-
copyright_years: "2020"
5+
copyright_years: "2020-2021"
66
author: "Dominic Davis-Foster"
77
88
version: "0.2.1"

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

0 commit comments

Comments
 (0)