143 @param fixed flag indicating a fixed issue (boolean) |
143 @param fixed flag indicating a fixed issue (boolean) |
144 @param autofixing flag indicating, that we are fixing issues |
144 @param autofixing flag indicating, that we are fixing issues |
145 automatically (boolean) |
145 automatically (boolean) |
146 @return reference to the created item (QTreeWidgetItem) |
146 @return reference to the created item (QTreeWidgetItem) |
147 """ |
147 """ |
148 from .Pep8Fixer import Pep8FixableIssues |
148 from .CodeStyleFixer import FixableCodeStyleIssues |
149 |
149 |
150 if self.__lastFileItem is None: |
150 if self.__lastFileItem is None: |
151 # It's a new file |
151 # It's a new file |
152 self.__lastFileItem = QTreeWidgetItem(self.resultList, [file]) |
152 self.__lastFileItem = QTreeWidgetItem(self.resultList, [file]) |
153 self.__lastFileItem.setFirstColumnSpanned(True) |
153 self.__lastFileItem.setFirstColumnSpanned(True) |
166 itm.setIcon(1, UI.PixmapCache.getIcon("docstringError.png")) |
166 itm.setIcon(1, UI.PixmapCache.getIcon("docstringError.png")) |
167 else: |
167 else: |
168 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png")) |
168 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png")) |
169 if fixed: |
169 if fixed: |
170 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixed.png")) |
170 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixed.png")) |
171 elif code in Pep8FixableIssues and not autofixing: |
171 elif code in FixableCodeStyleIssues and not autofixing: |
172 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixable.png")) |
172 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixable.png")) |
173 fixable = True |
173 fixable = True |
174 |
174 |
175 itm.setTextAlignment(0, Qt.AlignRight) |
175 itm.setTextAlignment(0, Qt.AlignRight) |
176 itm.setTextAlignment(1, Qt.AlignHCenter) |
176 itm.setTextAlignment(1, Qt.AlignHCenter) |
211 """ |
211 """ |
212 Private method to update the collected statistics. |
212 Private method to update the collected statistics. |
213 |
213 |
214 @param statistics dictionary of statistical data with |
214 @param statistics dictionary of statistical data with |
215 message code as key and message count as value |
215 message code as key and message count as value |
216 @param fixer reference to the PEP 8 fixer (Pep8Fixer) |
216 @param fixer reference to the PEP 8 fixer (CodeStyleFixer) |
217 """ |
217 """ |
218 self.__statistics["_FilesCount"] += 1 |
218 self.__statistics["_FilesCount"] += 1 |
219 stats = {v: k for v, k in statistics.items() if v[0].isupper()} |
219 stats = {v: k for v, k in statistics.items() if v[0].isupper()} |
220 if stats: |
220 if stats: |
221 self.__statistics["_FilesIssues"] += 1 |
221 self.__statistics["_FilesIssues"] += 1 |
229 |
229 |
230 def __updateFixerStatistics(self, fixer): |
230 def __updateFixerStatistics(self, fixer): |
231 """ |
231 """ |
232 Private method to update the collected fixer related statistics. |
232 Private method to update the collected fixer related statistics. |
233 |
233 |
234 @param fixer reference to the PEP 8 fixer (Pep8Fixer) |
234 @param fixer reference to the PEP 8 fixer (CodeStyleFixer) |
235 """ |
235 """ |
236 self.__statistics["_IssuesFixed"] += fixer.fixed |
236 self.__statistics["_IssuesFixed"] += fixer.fixed |
237 |
237 |
238 def __resetStatistics(self): |
238 def __resetStatistics(self): |
239 """ |
239 """ |
403 |
403 |
404 stats = {} |
404 stats = {} |
405 flags = Utilities.extractFlags(source) |
405 flags = Utilities.extractFlags(source) |
406 ext = os.path.splitext(file)[1] |
406 ext = os.path.splitext(file)[1] |
407 if fixIssues: |
407 if fixIssues: |
408 from .Pep8Fixer import Pep8Fixer |
408 from .CodeStyleFixer import CodeStyleFixer |
409 fixer = Pep8Fixer(self.__project, file, source, |
409 fixer = CodeStyleFixer(self.__project, file, source, |
410 fixCodes, noFixCodes, maxLineLength, |
410 fixCodes, noFixCodes, maxLineLength, |
411 True) # always fix in place |
411 True) # always fix in place |
412 else: |
412 else: |
413 fixer = None |
413 fixer = None |
414 if ("FileType" in flags and |
414 if ("FileType" in flags and |
801 @pyqtSlot() |
801 @pyqtSlot() |
802 def on_fixButton_clicked(self): |
802 def on_fixButton_clicked(self): |
803 """ |
803 """ |
804 Private slot to fix selected issues. |
804 Private slot to fix selected issues. |
805 """ |
805 """ |
806 from .Pep8Fixer import Pep8Fixer |
806 from .CodeStyleFixer import CodeStyleFixer |
807 |
807 |
808 # build a dictionary of issues to fix |
808 # build a dictionary of issues to fix |
809 fixableItems = self.__getSelectedFixableItems() |
809 fixableItems = self.__getSelectedFixableItems() |
810 fixesDict = {} # dictionary of lists of tuples containing |
810 fixesDict = {} # dictionary of lists of tuples containing |
811 # the issue and the item |
811 # the issue and the item |
841 # skip silently because that should not happen |
841 # skip silently because that should not happen |
842 progress += 1 |
842 progress += 1 |
843 continue |
843 continue |
844 |
844 |
845 deferredFixes = {} |
845 deferredFixes = {} |
846 fixer = Pep8Fixer(self.__project, file, source, |
846 fixer = CodeStyleFixer(self.__project, file, source, |
847 fixCodes, noFixCodes, maxLineLength, |
847 fixCodes, noFixCodes, maxLineLength, |
848 True) # always fix in place |
848 True) # always fix in place |
849 errors = fixesDict[file] |
849 errors = fixesDict[file] |
850 errors.sort(key=lambda a: a[0][0]) |
850 errors.sort(key=lambda a: a[0][0]) |
851 for error in errors: |
851 for error in errors: |