Fri, 09 Apr 2021 18:13:36 +0200
Code Style Checker: improved the statistics handling.
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py Thu Apr 08 18:27:47 2021 +0200 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py Fri Apr 09 18:13:36 2021 +0200 @@ -10,6 +10,7 @@ import os import fnmatch import copy +import collections from PyQt5.QtCore import pyqtSlot, Qt, QTimer, QCoreApplication from PyQt5.QtGui import QIcon @@ -195,7 +196,7 @@ self.__project = None self.__forProject = False self.__data = {} - self.__statistics = {} + self.__statistics = collections.defaultdict(self.__defaultStatistics) self.__onlyFixes = {} self.__noFixCodesList = [] self.__detectedCodes = [] @@ -205,6 +206,18 @@ self.mainWidget.setCurrentWidget(self.configureTab) self.optionsTabWidget.setCurrentWidget(self.globalOptionsTab) + def __defaultStatistics(self): + """ + Private method to return the default statistics entry. + + @return dictionary with default statistics entry + @rtype dict + """ + return { + "total": 0, + "ignored": 0, + } + def __resort(self): """ Private method to resort the tree. @@ -381,16 +394,14 @@ @type int """ self.__statistics["_FilesCount"] += 1 - stats = [k for k in statistics.keys() if k[0].isupper()] + stats = [k for k in statistics if k[0].isupper()] if stats: self.__statistics["_FilesIssues"] += 1 - for key in statistics: - if key in self.__statistics: - self.__statistics[key] += statistics[key] - else: - self.__statistics[key] = statistics[key] + for key in stats: + self.__statistics[key]["total"] += statistics[key] + for key in ignoredErrors: + self.__statistics[key]["ignored"] += ignoredErrors[key] self.__statistics["_IssuesFixed"] += fixer - self.__statistics["_IgnoredErrors"] += ignoredErrors self.__statistics["_SecurityOK"] += securityOk def __updateFixerStatistics(self, fixer): @@ -406,11 +417,10 @@ """ Private slot to reset the statistics data. """ - self.__statistics = {} + self.__statistics.clear() self.__statistics["_FilesCount"] = 0 self.__statistics["_FilesIssues"] = 0 self.__statistics["_IssuesFixed"] = 0 - self.__statistics["_IgnoredErrors"] = 0 self.__statistics["_SecurityOK"] = 0 def prepare(self, fileList, project): @@ -964,7 +974,7 @@ self.resultList.setSortingEnabled(False) fixed = None - ignoredErrors = 0 + ignoredErrors = collections.defaultdict(int) securityOk = 0 if self.__itms: for itm, result in zip(self.__itms, results): @@ -975,7 +985,7 @@ for result in results: if result["ignored"]: - ignoredErrors += 1 + ignoredErrors[result["code"]] += 1 if self.showIgnored: result["display"] = self.tr( "{0} (ignored)"
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleStatisticsDialog.py Thu Apr 08 18:27:47 2021 +0200 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleStatisticsDialog.py Fri Apr 09 18:13:36 2021 +0200 @@ -30,7 +30,9 @@ Constructor @param statistics dictionary with the statistical data - @param parent reference to the parent widget (QWidget) + @type dict + @param parent reference to the parent widget + @type QWidget """ super(CodeStyleStatisticsDialog, self).__init__(parent) self.setupUi(self) @@ -39,15 +41,14 @@ filesCount = stats["_FilesCount"] filesIssues = stats["_FilesIssues"] fixesCount = stats["_IssuesFixed"] - ignoresCount = stats["_IgnoredErrors"] securityOk = stats["_SecurityOK"] del stats["_FilesCount"] del stats["_FilesIssues"] del stats["_IssuesFixed"] - del stats["_IgnoredErrors"] del stats["_SecurityOK"] totalIssues = 0 + ignoresCount = 0 textWrapper = textwrap.TextWrapper(width=80) @@ -58,7 +59,8 @@ self.__createItem(stats[code], code, "\n".join(textWrapper.wrap(message))) - totalIssues += stats[code] + totalIssues += stats[code]["total"] + ignoresCount += stats[code]["ignored"] self.totalIssues.setText( self.tr("%n issue(s) found", "", totalIssues)) @@ -75,33 +77,41 @@ self.statisticsList.resizeColumnToContents(0) self.statisticsList.resizeColumnToContents(1) + self.statisticsList.resizeColumnToContents(2) - def __createItem(self, count, code, message): + def __createItem(self, counts, code, message): """ Private method to create an entry in the result list. - @param count occurrences of the issue (integer) - @param code of a code style issue message (string) - @param message code style issue message to be shown (string) + @param counts dictionary containing the total and ignored occurrences + of the issue + @type dict + @param code of a code style issue message + @type str + @param message code style issue message to be shown + @type str """ itm = QTreeWidgetItem(self.statisticsList, [ - "{0:6d}".format(count), code, message]) + code, "{0:6d}".format(counts["total"] - counts["ignored"]), + "{0:6d}".format(counts["ignored"]), message]) if code.startswith(("W", "C", "M")): - itm.setIcon(1, UI.PixmapCache.getIcon("warning")) + itm.setIcon(0, UI.PixmapCache.getIcon("warning")) elif code.startswith("E"): - itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError")) + itm.setIcon(0, UI.PixmapCache.getIcon("syntaxError")) elif code.startswith("N"): - itm.setIcon(1, UI.PixmapCache.getIcon("namingError")) + itm.setIcon(0, UI.PixmapCache.getIcon("namingError")) elif code.startswith("D"): - itm.setIcon(1, UI.PixmapCache.getIcon("docstringError")) + itm.setIcon(0, UI.PixmapCache.getIcon("docstringError")) elif code.startswith("S"): - itm.setIcon(1, UI.PixmapCache.getIcon("securityLow")) + itm.setIcon(0, UI.PixmapCache.getIcon("securityLow")) elif code.startswith("P"): - itm.setIcon(1, UI.PixmapCache.getIcon("dirClosed")) + itm.setIcon(0, UI.PixmapCache.getIcon("dirClosed")) elif code.startswith("Y"): - itm.setIcon(1, UI.PixmapCache.getIcon("filePython")) + itm.setIcon(0, UI.PixmapCache.getIcon("filePython")) itm.setTextAlignment( - 0, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter) + 0, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter) itm.setTextAlignment( - 1, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter) + 1, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter) + itm.setTextAlignment( + 2, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleStatisticsDialog.ui Thu Apr 08 18:27:47 2021 +0200 +++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleStatisticsDialog.ui Fri Apr 09 18:13:36 2021 +0200 @@ -27,12 +27,17 @@ </property> <column> <property name="text"> - <string>Count</string> + <string>Code</string> </property> </column> <column> <property name="text"> - <string>Code</string> + <string>Open</string> + </property> + </column> + <column> + <property name="text"> + <string>Ignored</string> </property> </column> <column>