src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Async/AsyncChecker.py

branch
eric7
changeset 11150
73d80859079c
parent 11145
d328a7b74fd8
diff -r fc45672fae42 -r 73d80859079c src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Async/AsyncChecker.py
--- a/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Async/AsyncChecker.py	Thu Feb 27 09:22:15 2025 +0100
+++ b/src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Async/AsyncChecker.py	Thu Feb 27 14:42:39 2025 +0100
@@ -7,24 +7,25 @@
 Module implementing a checker for "async" related issues.
 """
 
-
 import copy
 
+from CodeStyleTopicChecker import CodeStyleTopicChecker
 
-class AsyncChecker:
+
+class AsyncChecker(CodeStyleTopicChecker):
     """
     Class implementing a checker for "async" related issues.
     """
 
     Codes = [
-        "ASY100",
-        "ASY101",
-        "ASY102",
-        "ASY103",
-        "ASY104",
-        "ASY105",
+        "ASY-100",
+        "ASY-101",
+        "ASY-102",
+        "ASY-103",
+        "ASY-104",
+        "ASY-105",
     ]
-    Prefix = "ASY"
+    Category = "ASY"
 
     def __init__(self, source, filename, tree, select, ignore, expected, repeat, args):
         """
@@ -47,98 +48,25 @@
         @param args dictionary of arguments for the various checks
         @type dict
         """
-        self.__select = tuple(x for x in select if x.startswith(AsyncChecker.Prefix))
-        self.__ignore = tuple(x for x in ignore if x.startswith(AsyncChecker.Prefix))
-        self.__expected = expected[:]
-        self.__repeat = repeat
-        self.__filename = filename
-        self.__source = source[:]
-        self.__tree = copy.deepcopy(tree)
-        self.__args = args
-
-        # statistics counters
-        self.counters = {}
-
-        # collection of detected errors
-        self.errors = []
+        super().__init__(
+            AsyncChecker.Category,
+            source,
+            filename,
+            tree,
+            select,
+            ignore,
+            expected,
+            repeat,
+            args,
+        )
 
         checkersWithCodes = [
             (
                 self.__checkSyncUses,
-                ("ASY100", "ASY101", "ASY102", "ASY103", "ASY104", "ASY105"),
+                ("ASY-100", "ASY-101", "ASY-102", "ASY-103", "ASY-104", "ASY-105"),
             ),
         ]
-
-        self.__checkers = []
-        for checker, codes in checkersWithCodes:
-            if any(not (code and self.__ignoreCode(code)) for code in codes):
-                self.__checkers.append(checker)
-
-    def __ignoreCode(self, code):
-        """
-        Private method to check if the message code should be ignored.
-
-        @param code message code to check for
-        @type str
-        @return flag indicating to ignore the given code
-        @rtype bool
-        """
-        return code in self.__ignore or (
-            code.startswith(self.__ignore) and not code.startswith(self.__select)
-        )
-
-    def __error(self, lineNumber, offset, code, *args):
-        """
-        Private method to record an issue.
-
-        @param lineNumber line number of the issue
-        @type int
-        @param offset position within line of the issue
-        @type int
-        @param code message code
-        @type str
-        @param args arguments for the message
-        @type list
-        """
-        if self.__ignoreCode(code):
-            return
-
-        if code in self.counters:
-            self.counters[code] += 1
-        else:
-            self.counters[code] = 1
-
-        # Don't care about expected codes
-        if code in self.__expected:
-            return
-
-        if code and (self.counters[code] == 1 or self.__repeat):
-            # record the issue with one based line number
-            self.errors.append(
-                {
-                    "file": self.__filename,
-                    "line": lineNumber + 1,
-                    "offset": offset,
-                    "code": code,
-                    "args": args,
-                }
-            )
-
-    def run(self):
-        """
-        Public method to check the given source against miscellaneous
-        conditions.
-        """
-        if not self.__filename:
-            # don't do anything, if essential data is missing
-            return
-
-        if not self.__checkers:
-            # don't do anything, if no codes were selected
-            return
-
-        for check in self.__checkers:
-            check()
+        self._initializeCheckers(checkersWithCodes)
 
     def __checkSyncUses(self):
         """
@@ -146,10 +74,7 @@
         """
         from .AsyncVisitor import AsyncVisitor
 
-        visitor = AsyncVisitor(self.__args, self)
-        visitor.visit(copy.deepcopy(self.__tree))
+        visitor = AsyncVisitor(self.args, self)
+        visitor.visit(copy.deepcopy(self.tree))
         for violation in visitor.violations:
-            if not self.__ignoreCode(violation[1]):
-                node = violation[0]
-                reason = violation[1]
-                self.__error(node.lineno - 1, node.col_offset, reason)
+            self.addErrorFromNode(violation[0], violation[1])

eric ide

mercurial