eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py

changeset 7610
df7025fe26a3
parent 7609
d5aff4fd0ef8
child 7611
d546c4e72f52
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py	Thu Jun 04 17:57:20 2020 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py	Sat Jun 06 19:42:15 2020 +0200
@@ -45,6 +45,7 @@
     fixableRole = Qt.UserRole + 5
     codeRole = Qt.UserRole + 6
     ignoredRole = Qt.UserRole + 7
+    argsRole = Qt.UserRole + 8
     
     availableFutures = [
         'division', 'absolute_import', 'with_statement',
@@ -199,26 +200,36 @@
             itm.setForeground(0, Qt.red)
             itm.setFirstColumnSpanned(True)
     
-    def __createResultItem(self, filename, line, pos, message, fixed,
-                           autofixing, ignored):
+    def __createFileErrorItem(self, filename, message):
+        """
+        Private method to create an error entry for a given file.
+        
+        @param filename file name of the file
+        @type str
+        @param message error message text
+        @type str
+        """
+        result = {
+            "file": filename,
+            "line": 1,
+            "offset": 1,
+            "code": "",
+            "args": [],
+            "display": self.tr("Error: {0}").format(message).rstrip(),
+            "fixed": False,
+            "autofixing": False,
+            "ignored": False,
+        }
+        self.__createResultItem(filename, result)
+    
+    def __createResultItem(self, filename, result):
         """
         Private method to create an entry in the result list.
         
         @param filename file name of the file
         @type str
-        @param line line number of issue
-        @type int or str
-        @param pos character position of issue
-        @type int or str
-        @param message message text
-        @type str
-        @param fixed flag indicating a fixed issue
-        @type bool
-        @param autofixing flag indicating, that we are fixing issues
-            automatically
-        @type bool
-        @param ignored flag indicating an ignored issue
-        @type bool
+        @param result dictionary containing check result data
+        @type dict
         @return reference to the created item
         @rtype QTreeWidgetItem
         """
@@ -233,23 +244,24 @@
             self.__lastFileItem.setData(0, self.filenameRole, filename)
         
         fixable = False
-        code, message = message.split(None, 1)
         itm = QTreeWidgetItem(
             self.__lastFileItem,
-            ["{0:6}".format(line), code, message])
-        if code.startswith(("W", "-", "C", "M")):
+            ["{0:6}".format(result["line"]), result["code"],
+             result["display"]])
+        if result["code"].startswith(("W", "-", "C", "M")):
             itm.setIcon(1, UI.PixmapCache.getIcon("warning"))
-        elif code.startswith(("A", "N")):
+        elif result["code"].startswith(("A", "N")):
             itm.setIcon(1, UI.PixmapCache.getIcon("namingError"))
-        elif code.startswith("D"):
+        elif result["code"].startswith("D"):
             itm.setIcon(1, UI.PixmapCache.getIcon("docstringError"))
         else:
             itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError"))
-        if fixed:
+        if result["fixed"]:
             itm.setIcon(0, UI.PixmapCache.getIcon("issueFixed"))
         elif (
-            code in FixableCodeStyleIssues and not autofixing and
-            code not in self.__noFixCodesList
+            result["code"] in FixableCodeStyleIssues and
+            not result["autofixing"] and
+            result["code"] not in self.__noFixCodesList
         ):
             itm.setIcon(0, UI.PixmapCache.getIcon("issueFixable"))
             fixable = True
@@ -262,14 +274,15 @@
         itm.setTextAlignment(2, Qt.AlignVCenter)
         
         itm.setData(0, self.filenameRole, filename)
-        itm.setData(0, self.lineRole, int(line))
-        itm.setData(0, self.positionRole, int(pos))
-        itm.setData(0, self.messageRole, message)
+        itm.setData(0, self.lineRole, int(result["line"]))
+        itm.setData(0, self.positionRole, int(result["offset"]))
+        itm.setData(0, self.messageRole, result["display"])
         itm.setData(0, self.fixableRole, fixable)
-        itm.setData(0, self.codeRole, code)
-        itm.setData(0, self.ignoredRole, ignored)
+        itm.setData(0, self.codeRole, result["code"])
+        itm.setData(0, self.ignoredRole, result["ignored"])
+        itm.setData(0, self.argsRole, result["args"])
         
-        if ignored:
+        if result["ignored"]:
             font = itm.font(0)
             font.setItalic(True)
             for col in range(itm.columnCount()):
@@ -277,24 +290,21 @@
         
         return itm
     
-    def __modifyFixedResultItem(self, itm, text, fixed):
+    def __modifyFixedResultItem(self, itm, result):
         """
         Private method to modify a result list entry to show its
         positive fixed state.
         
         @param itm reference to the item to modify
         @type QTreeWidgetItem
-        @param text text to be appended
-        @type str
-        @param fixed flag indicating a fixed issue
-        @type bool
+        @param result dictionary containing check result data
+        @type dict
         """
-        if fixed:
-            code, message = text.split(None, 1)
-            itm.setText(2, message)
+        if result["fixed"]:
+            itm.setText(2, result["display"])
             itm.setIcon(0, UI.PixmapCache.getIcon("issueFixed"))
             
-            itm.setData(0, self.messageRole, message)
+            itm.setData(0, self.messageRole, result["display"])
         else:
             itm.setIcon(0, QIcon())
         itm.setData(0, self.fixableRole, False)
@@ -651,10 +661,7 @@
                 source = source.splitlines(True)
             except (UnicodeError, IOError) as msg:
                 self.results = CodeStyleCheckerDialog.hasResults
-                self.__createResultItem(
-                    self.filename, 1, 1,
-                    self.tr("Error: {0}").format(str(msg))
-                        .rstrip(), False, False, False)
+                self.__createFileErrorItem(self.filename, str(msg))
                 self.progress += 1
                 # Continue with next file
                 self.check()
@@ -702,10 +709,7 @@
                 source = source.splitlines(True)
             except (UnicodeError, IOError) as msg:
                 self.results = CodeStyleCheckerDialog.hasResults
-                self.__createResultItem(
-                    filename, 1, 1,
-                    self.tr("Error: {0}").format(str(msg))
-                        .rstrip(), False, False, False)
+                self.__createFileErrorItem(filename, str(msg))
                 continue
             
             if encoding.endswith(
@@ -768,9 +772,8 @@
         @type dict
         @param fixes number of applied fixes
         @type int
-        @param results tuple for each found violation of style (tuple of
-            lineno, position, text, ignored, fixed, autofixing)
-        @type tuplt of tuple of (int, int, str, bool, bool, bool)
+        @param results dictionary containing check result data
+        @type dict
         """
         if self.__finished:
             return
@@ -787,23 +790,23 @@
         fixed = None
         ignoredErrors = 0
         if self.__itms:
-            for itm, (_lineno, _position, text, _ignored, fixed,
-                      _autofixing) in zip(self.__itms, results):
-                self.__modifyFixedResultItem(itm, text, fixed)
+            for itm, result in zip(self.__itms, results):
+                self.__modifyFixedResultItem(itm, result)
             self.__updateFixerStatistics(fixes)
         else:
             self.__lastFileItem = None
             
-            for lineno, position, text, ignored, fixed, autofixing in results:
-                if ignored:
+            for result in results:
+                if result["ignored"]:
                     ignoredErrors += 1
                     if self.showIgnored:
-                        text = self.tr("{0} (ignored)").format(text)
+                        result["display"] = self.tr(
+                            "{0} (ignored)"
+                        ).format(result["display"])
                     else:
                         continue
                 self.results = CodeStyleCheckerDialog.hasResults
-                self.__createResultItem(
-                    fn, lineno, position, text, fixed, autofixing, ignored)
+                self.__createResultItem(fn, result)
 
             self.__updateStatistics(
                 codeStyleCheckerStats, fixes, ignoredErrors)
@@ -1323,10 +1326,14 @@
             if filename not in fixesDict:
                 fixesDict[filename] = []
             fixesDict[filename].append((
-                (filename, itm.data(0, self.lineRole),
-                 itm.data(0, self.positionRole),
-                 "{0} {1}".format(itm.data(0, self.codeRole),
-                                  itm.data(0, self.messageRole))),
+                {
+                    "file": filename,
+                    "line": itm.data(0, self.lineRole),
+                    "offset": itm.data(0, self.positionRole),
+                    "code": itm.data(0, self.codeRole),
+                    "display": itm.data(0, self.messageRole),
+                    "args": itm.data(0, self.argsRole),
+                },
                 itm
             ))
     

eric ide

mercurial