summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2022-03-24 20:50:23 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-03-24 22:40:30 +0100
commit84d22cf24202bf6006fc179541e1853d145d33e0 (patch)
treea4174266e36fd0148fd25fffe102dbb1ea2a6ae2
parent977b08d160e81aaecebf871d2b8ba2f9a96ef9d6 (diff)
downloadpylint-git-84d22cf24202bf6006fc179541e1853d145d33e0.tar.gz
[refactor] Create a file for the PassChecker in pylint.checker.base
-rw-r--r--pylint/checkers/base/__init__.py21
-rw-r--r--pylint/checkers/base/pass_checker.py28
2 files changed, 29 insertions, 20 deletions
diff --git a/pylint/checkers/base/__init__.py b/pylint/checkers/base/__init__.py
index bf0be8566..92e8a9ce3 100644
--- a/pylint/checkers/base/__init__.py
+++ b/pylint/checkers/base/__init__.py
@@ -17,6 +17,7 @@ from pylint import utils as lint_utils
from pylint.checkers import utils
from pylint.checkers.base.basic_checker import _BasicChecker
from pylint.checkers.base.comparison_checker import ComparisonChecker
+from pylint.checkers.base.pass_checker import PassChecker
from pylint.checkers.utils import (
infer_all,
is_overload_stub,
@@ -2311,26 +2312,6 @@ class DocStringChecker(_BasicChecker):
)
-class PassChecker(_BasicChecker):
- """Check if the pass statement is really necessary."""
-
- msgs = {
- "W0107": (
- "Unnecessary pass statement",
- "unnecessary-pass",
- 'Used when a "pass" statement that can be avoided is encountered.',
- )
- }
-
- @utils.check_messages("unnecessary-pass")
- def visit_pass(self, node: nodes.Pass) -> None:
- if len(node.parent.child_sequence(node)) > 1 or (
- isinstance(node.parent, (nodes.ClassDef, nodes.FunctionDef))
- and node.parent.doc_node
- ):
- self.add_message("unnecessary-pass", node=node)
-
-
def _infer_dunder_doc_attribute(node):
# Try to see if we have a `__doc__` attribute.
try:
diff --git a/pylint/checkers/base/pass_checker.py b/pylint/checkers/base/pass_checker.py
new file mode 100644
index 000000000..26b915bc4
--- /dev/null
+++ b/pylint/checkers/base/pass_checker.py
@@ -0,0 +1,28 @@
+# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
+# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
+
+from astroid import nodes
+
+from pylint.checkers import utils
+from pylint.checkers.base.basic_checker import _BasicChecker
+
+
+class PassChecker(_BasicChecker):
+ """Check if the pass statement is really necessary."""
+
+ msgs = {
+ "W0107": (
+ "Unnecessary pass statement",
+ "unnecessary-pass",
+ 'Used when a "pass" statement that can be avoided is encountered.',
+ )
+ }
+
+ @utils.check_messages("unnecessary-pass")
+ def visit_pass(self, node: nodes.Pass) -> None:
+ if len(node.parent.child_sequence(node)) > 1 or (
+ isinstance(node.parent, (nodes.ClassDef, nodes.FunctionDef))
+ and node.parent.doc_node
+ ):
+ self.add_message("unnecessary-pass", node=node)