summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2022-04-19 14:32:07 +0200
committerDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2022-04-19 17:30:40 +0200
commitc550cce659a4341923cf28cdb167ae89d1c85a74 (patch)
treec12cc732866f44ca2770a6453681e54ea898899a
parent1664202ba5de84149d0a2eeb078b1731d1782fbb (diff)
downloadpylint-git-c550cce659a4341923cf28cdb167ae89d1c85a74.tar.gz
Add base Checker classes mirroring interfaces
-rw-r--r--.coveragerc3
-rw-r--r--pylint/checkers/__init__.py7
-rw-r--r--pylint/checkers/base_checker.py18
3 files changed, 25 insertions, 3 deletions
diff --git a/.coveragerc b/.coveragerc
index 871b6077e..faa494f8e 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -23,3 +23,6 @@ exclude_lines =
# Type checking code not executed during pytest runs
if TYPE_CHECKING:
@overload
+
+ # Abstract methods are not exectued during pytest runs
+ raise NotImplementedError()
diff --git a/pylint/checkers/__init__.py b/pylint/checkers/__init__.py
index f0e679374..51393c400 100644
--- a/pylint/checkers/__init__.py
+++ b/pylint/checkers/__init__.py
@@ -45,7 +45,11 @@ from __future__ import annotations
import sys
-from pylint.checkers.base_checker import BaseChecker, BaseTokenChecker
+from pylint.checkers.base_checker import (
+ BaseChecker,
+ BaseRawFileChecker,
+ BaseTokenChecker,
+)
from pylint.checkers.deprecated import DeprecatedMixin
from pylint.checkers.mapreduce_checker import MapReduceMixin
from pylint.utils import LinterStats, diff_string, register_plugins
@@ -132,6 +136,7 @@ def initialize(linter):
__all__ = [
"BaseChecker",
"BaseTokenChecker",
+ "BaseRawFileChecker",
"initialize",
"MapReduceMixin",
"DeprecatedMixin",
diff --git a/pylint/checkers/base_checker.py b/pylint/checkers/base_checker.py
index fd01bfaa1..94b45ef48 100644
--- a/pylint/checkers/base_checker.py
+++ b/pylint/checkers/base_checker.py
@@ -4,6 +4,7 @@
from __future__ import annotations
+import abc
import functools
import warnings
from inspect import cleandoc
@@ -201,16 +202,29 @@ class BaseChecker(_ArgumentsProvider):
error_msg += f"Choose from {[m.msgid for m in self.messages]}."
raise InvalidMessageError(error_msg)
- def open(self):
+ def open(self) -> None:
"""Called before visiting project (i.e. set of modules)."""
- def close(self):
+ def close(self) -> None:
"""Called after visiting project (i.e set of modules)."""
class BaseTokenChecker(BaseChecker):
"""Base class for checkers that want to have access to the token stream."""
+ @abc.abstractmethod
def process_tokens(self, tokens: list[TokenInfo]) -> None:
"""Should be overridden by subclasses."""
raise NotImplementedError()
+
+
+class BaseRawFileChecker(BaseChecker):
+ """Base class for checkers which need to parse the raw file."""
+
+ @abc.abstractmethod
+ def process_module(self, node: nodes.Module) -> None:
+ """Process a module.
+
+ The module's content is accessible via ``astroid.stream``
+ """
+ raise NotImplementedError()