diff --git a/flake8_idom_hooks/flake8_plugin.py b/flake8_idom_hooks/flake8_plugin.py index 02ec11b..8b5bc53 100644 --- a/flake8_idom_hooks/flake8_plugin.py +++ b/flake8_idom_hooks/flake8_plugin.py @@ -14,7 +14,7 @@ class Plugin: name = __name__ version = __version__ - options: Namespace = Namespace() + exhaustive_hook_deps: bool @classmethod def add_options(cls, option_manager: OptionManager) -> None: @@ -28,7 +28,7 @@ def add_options(cls, option_manager: OptionManager) -> None: @classmethod def parse_options(cls, options: Namespace) -> None: - cls.options = options + cls.exhaustive_hook_deps = getattr(options, "exhaustive_hook_deps", False) def __init__(self, tree: ast.Module) -> None: self._tree = tree @@ -36,7 +36,5 @@ def __init__(self, tree: ast.Module) -> None: def run(self) -> list[tuple[int, int, str, type[Plugin]]]: return [ error + (self.__class__,) - for error in run_checks( - self._tree, getattr(self.options, "exhaustive_hook_deps", False) - ) + for error in run_checks(self._tree, self.exhaustive_hook_deps) ] diff --git a/tests/test_flake8_idom_hooks.py b/tests/test_flake8_idom_hooks.py index 9c254f6..bcdda1d 100644 --- a/tests/test_flake8_idom_hooks.py +++ b/tests/test_flake8_idom_hooks.py @@ -1,7 +1,13 @@ import ast from pathlib import Path -from flake8_idom_hooks import run_checks +from flake8.options.manager import OptionManager + +from flake8_idom_hooks import Plugin + + +options_manager = OptionManager("test", "0.0.0") +Plugin.add_options(options_manager) def test_flake8_idom_hooks(): @@ -19,5 +25,9 @@ def test_flake8_idom_hooks(): lineno = index + 2 # use 2 since error should be on next line col_offset = len(line) - len(lstrip_line) message = line.replace("# error:", "", 1).strip() - expected_errors.add((lineno, col_offset, message)) - assert set(run_checks(tree, exhaustive_hook_deps=True)) == expected_errors + expected_errors.add((lineno, col_offset, message, Plugin)) + + options, filenames = options_manager.parse_args(["--exhaustive-hook-deps"]) + Plugin.parse_options(options) + + assert set(Plugin(tree).run()) == expected_errors