77 lineRole = Qt.UserRole + 2 |
77 lineRole = Qt.UserRole + 2 |
78 positionRole = Qt.UserRole + 3 |
78 positionRole = Qt.UserRole + 3 |
79 messageRole = Qt.UserRole + 4 |
79 messageRole = Qt.UserRole + 4 |
80 fixableRole = Qt.UserRole + 5 |
80 fixableRole = Qt.UserRole + 5 |
81 codeRole = Qt.UserRole + 6 |
81 codeRole = Qt.UserRole + 6 |
|
82 ignoredRole = Qt.UserRole + 7 |
82 |
83 |
83 def __init__(self, parent=None): |
84 def __init__(self, parent=None): |
84 """ |
85 """ |
85 Constructor |
86 Constructor |
86 |
87 |
139 """ |
140 """ |
140 self.resultList.sortItems(self.resultList.sortColumn(), |
141 self.resultList.sortItems(self.resultList.sortColumn(), |
141 self.resultList.header().sortIndicatorOrder() |
142 self.resultList.header().sortIndicatorOrder() |
142 ) |
143 ) |
143 |
144 |
144 def __createResultItem(self, file, line, pos, message, fixed, autofixing): |
145 def __createResultItem(self, file, line, pos, message, fixed, autofixing, |
|
146 ignored): |
145 """ |
147 """ |
146 Private method to create an entry in the result list. |
148 Private method to create an entry in the result list. |
147 |
149 |
148 @param file file name of the file (string) |
150 @param file file name of the file (string) |
149 @param line line number of issue (integer or string) |
151 @param line line number of issue (integer or string) |
150 @param pos character position of issue (integer or string) |
152 @param pos character position of issue (integer or string) |
151 @param message message text (string) |
153 @param message message text (string) |
152 @param fixed flag indicating a fixed issue (boolean) |
154 @param fixed flag indicating a fixed issue (boolean) |
153 @param autofixing flag indicating, that we are fixing issues |
155 @param autofixing flag indicating, that we are fixing issues |
154 automatically (boolean) |
156 automatically (boolean) |
|
157 @param ignored flag indicating an ignored issue (boolean) |
155 @return reference to the created item (QTreeWidgetItem) |
158 @return reference to the created item (QTreeWidgetItem) |
156 """ |
159 """ |
157 from .CodeStyleFixer import FixableCodeStyleIssues |
160 from .CodeStyleFixer import FixableCodeStyleIssues |
158 |
161 |
159 if self.__lastFileItem is None: |
162 if self.__lastFileItem is None: |
193 itm.setData(0, self.lineRole, int(line)) |
196 itm.setData(0, self.lineRole, int(line)) |
194 itm.setData(0, self.positionRole, int(pos)) |
197 itm.setData(0, self.positionRole, int(pos)) |
195 itm.setData(0, self.messageRole, message) |
198 itm.setData(0, self.messageRole, message) |
196 itm.setData(0, self.fixableRole, fixable) |
199 itm.setData(0, self.fixableRole, fixable) |
197 itm.setData(0, self.codeRole, code) |
200 itm.setData(0, self.codeRole, code) |
|
201 itm.setData(0, self.ignoredRole, ignored) |
|
202 |
|
203 if ignored: |
|
204 font = itm.font(0) |
|
205 font.setItalic(True) |
|
206 for col in range(itm.columnCount()): |
|
207 itm.setFont(col, font) |
198 |
208 |
199 return itm |
209 return itm |
200 |
210 |
201 def __modifyFixedResultItem(self, itm, text, fixed): |
211 def __modifyFixedResultItem(self, itm, text, fixed): |
202 """ |
212 """ |
215 itm.setData(0, self.messageRole, message) |
225 itm.setData(0, self.messageRole, message) |
216 else: |
226 else: |
217 itm.setIcon(0, QIcon()) |
227 itm.setIcon(0, QIcon()) |
218 itm.setData(0, self.fixableRole, False) |
228 itm.setData(0, self.fixableRole, False) |
219 |
229 |
220 def __updateStatistics(self, statistics, fixer): |
230 def __updateStatistics(self, statistics, fixer, ignoredErrors): |
221 """ |
231 """ |
222 Private method to update the collected statistics. |
232 Private method to update the collected statistics. |
223 |
233 |
224 @param statistics dictionary of statistical data with |
234 @param statistics dictionary of statistical data with |
225 message code as key and message count as value |
235 message code as key and message count as value |
226 @param fixer reference to the code style fixer (CodeStyleFixer) |
236 @param fixer reference to the code style fixer (CodeStyleFixer) |
|
237 @param ignoredErrors number of ignored errors (integer) |
227 """ |
238 """ |
228 self.__statistics["_FilesCount"] += 1 |
239 self.__statistics["_FilesCount"] += 1 |
229 stats = {v: k for v, k in statistics.items() if v[0].isupper()} |
240 stats = {v: k for v, k in statistics.items() if v[0].isupper()} |
230 if stats: |
241 if stats: |
231 self.__statistics["_FilesIssues"] += 1 |
242 self.__statistics["_FilesIssues"] += 1 |
234 self.__statistics[key] += statistics[key] |
245 self.__statistics[key] += statistics[key] |
235 else: |
246 else: |
236 self.__statistics[key] = statistics[key] |
247 self.__statistics[key] = statistics[key] |
237 if fixer: |
248 if fixer: |
238 self.__statistics["_IssuesFixed"] += fixer.fixed |
249 self.__statistics["_IssuesFixed"] += fixer.fixed |
|
250 self.__statistics["_IgnoredErrors"] += ignoredErrors |
239 |
251 |
240 def __updateFixerStatistics(self, fixer): |
252 def __updateFixerStatistics(self, fixer): |
241 """ |
253 """ |
242 Private method to update the collected fixer related statistics. |
254 Private method to update the collected fixer related statistics. |
243 |
255 |
251 """ |
263 """ |
252 self.__statistics = {} |
264 self.__statistics = {} |
253 self.__statistics["_FilesCount"] = 0 |
265 self.__statistics["_FilesCount"] = 0 |
254 self.__statistics["_FilesIssues"] = 0 |
266 self.__statistics["_FilesIssues"] = 0 |
255 self.__statistics["_IssuesFixed"] = 0 |
267 self.__statistics["_IssuesFixed"] = 0 |
|
268 self.__statistics["_IgnoredErrors"] = 0 |
256 |
269 |
257 def prepare(self, fileList, project): |
270 def prepare(self, fileList, project): |
258 """ |
271 """ |
259 Public method to prepare the dialog with a list of filenames. |
272 Public method to prepare the dialog with a list of filenames. |
260 |
273 |
287 self.__data["HangClosing"] = False |
300 self.__data["HangClosing"] = False |
288 if "NoFixCodes" not in self.__data: |
301 if "NoFixCodes" not in self.__data: |
289 self.__data["NoFixCodes"] = "E501" |
302 self.__data["NoFixCodes"] = "E501" |
290 if "DocstringType" not in self.__data: |
303 if "DocstringType" not in self.__data: |
291 self.__data["DocstringType"] = "pep257" |
304 self.__data["DocstringType"] = "pep257" |
|
305 if "ShowIgnored" not in self.__data: |
|
306 self.__data["ShowIgnored"] = False |
292 |
307 |
293 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
308 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
294 self.excludeMessagesEdit.setText(self.__data["ExcludeMessages"]) |
309 self.excludeMessagesEdit.setText(self.__data["ExcludeMessages"]) |
295 self.includeMessagesEdit.setText(self.__data["IncludeMessages"]) |
310 self.includeMessagesEdit.setText(self.__data["IncludeMessages"]) |
296 self.repeatCheckBox.setChecked(self.__data["RepeatMessages"]) |
311 self.repeatCheckBox.setChecked(self.__data["RepeatMessages"]) |
297 self.fixIssuesEdit.setText(self.__data["FixCodes"]) |
312 self.fixIssuesEdit.setText(self.__data["FixCodes"]) |
298 self.noFixIssuesEdit.setText(self.__data["NoFixCodes"]) |
313 self.noFixIssuesEdit.setText(self.__data["NoFixCodes"]) |
299 self.fixIssuesCheckBox.setChecked(self.__data["FixIssues"]) |
314 self.fixIssuesCheckBox.setChecked(self.__data["FixIssues"]) |
|
315 self.ignoredCheckBox.setChecked(self.__data["ShowIgnored"]) |
300 self.lineLengthSpinBox.setValue(self.__data["MaxLineLength"]) |
316 self.lineLengthSpinBox.setValue(self.__data["MaxLineLength"]) |
301 self.hangClosingCheckBox.setChecked(self.__data["HangClosing"]) |
317 self.hangClosingCheckBox.setChecked(self.__data["HangClosing"]) |
302 self.docTypeComboBox.setCurrentIndex( |
318 self.docTypeComboBox.setCurrentIndex( |
303 self.docTypeComboBox.findData(self.__data["DocstringType"])) |
319 self.docTypeComboBox.findData(self.__data["DocstringType"])) |
304 |
320 |
378 includeMessages = self.includeMessagesEdit.text() |
394 includeMessages = self.includeMessagesEdit.text() |
379 repeatMessages = self.repeatCheckBox.isChecked() |
395 repeatMessages = self.repeatCheckBox.isChecked() |
380 fixCodes = self.fixIssuesEdit.text() |
396 fixCodes = self.fixIssuesEdit.text() |
381 noFixCodes = self.noFixIssuesEdit.text() |
397 noFixCodes = self.noFixIssuesEdit.text() |
382 fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages |
398 fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages |
|
399 showIgnored = self.ignoredCheckBox.isChecked() and repeatMessages |
383 maxLineLength = self.lineLengthSpinBox.value() |
400 maxLineLength = self.lineLengthSpinBox.value() |
384 hangClosing = self.hangClosingCheckBox.isChecked() |
401 hangClosing = self.hangClosingCheckBox.isChecked() |
385 docType = self.docTypeComboBox.itemData( |
402 docType = self.docTypeComboBox.itemData( |
386 self.docTypeComboBox.currentIndex()) |
403 self.docTypeComboBox.currentIndex()) |
387 |
404 |
409 except (UnicodeError, IOError) as msg: |
426 except (UnicodeError, IOError) as msg: |
410 self.noResults = False |
427 self.noResults = False |
411 self.__createResultItem( |
428 self.__createResultItem( |
412 file, "1", "1", |
429 file, "1", "1", |
413 self.tr("Error: {0}").format(str(msg)) |
430 self.tr("Error: {0}").format(str(msg)) |
414 .rstrip()[1:-1], False, False) |
431 .rstrip()[1:-1], False, False, False) |
415 progress += 1 |
432 progress += 1 |
416 continue |
433 continue |
417 |
434 |
418 stats = {} |
435 stats = {} |
419 flags = Utilities.extractFlags(source) |
436 flags = Utilities.extractFlags(source) |
478 stats.update(docStyleChecker.counters) |
495 stats.update(docStyleChecker.counters) |
479 |
496 |
480 errors = report.errors + docStyleChecker.errors |
497 errors = report.errors + docStyleChecker.errors |
481 |
498 |
482 deferredFixes = {} |
499 deferredFixes = {} |
|
500 ignoredErrors = 0 |
483 for error in errors: |
501 for error in errors: |
484 fname, lineno, position, text = error |
502 fname, lineno, position, text = error |
485 if lineno > len(source): |
503 if lineno > len(source): |
486 lineno = len(source) |
504 lineno = len(source) |
487 if "__IGNORE_WARNING__" not in \ |
505 if "__IGNORE_WARNING__" not in \ |
494 if res == 1: |
512 if res == 1: |
495 text += "\n" + \ |
513 text += "\n" + \ |
496 self.tr("Fix: {0}").format(msg) |
514 self.tr("Fix: {0}").format(msg) |
497 self.__createResultItem( |
515 self.__createResultItem( |
498 fname, lineno, position, text, True, |
516 fname, lineno, position, text, True, |
499 True) |
517 True, False) |
500 elif res == 0: |
518 elif res == 0: |
501 self.__createResultItem( |
519 self.__createResultItem( |
502 fname, lineno, position, text, False, |
520 fname, lineno, position, text, False, |
503 True) |
521 True, False) |
504 else: |
522 else: |
505 itm = self.__createResultItem( |
523 itm = self.__createResultItem( |
506 fname, lineno, position, |
524 fname, lineno, position, |
507 text, False, False) |
525 text, False, False, False) |
508 deferredFixes[id_] = itm |
526 deferredFixes[id_] = itm |
509 else: |
527 else: |
510 self.__createResultItem( |
528 self.__createResultItem( |
511 fname, lineno, position, text, False, |
529 fname, lineno, position, text, False, |
512 False) |
530 False, False) |
|
531 else: |
|
532 ignoredErrors += 1 |
|
533 if showIgnored: |
|
534 self.noResults = False |
|
535 self.__createResultItem( |
|
536 fname, lineno, position, |
|
537 self.tr("{0} (ignored)").format(text), |
|
538 False, False, True) |
513 if fixer: |
539 if fixer: |
514 deferredResults = fixer.finalize() |
540 deferredResults = fixer.finalize() |
515 for id_ in deferredResults: |
541 for id_ in deferredResults: |
516 fixed, msg = deferredResults[id_] |
542 fixed, msg = deferredResults[id_] |
517 itm = deferredFixes[id_] |
543 itm = deferredFixes[id_] |
520 self.tr("Fix: {0}").format(msg) |
546 self.tr("Fix: {0}").format(msg) |
521 self.__modifyFixedResultItem(itm, text, True) |
547 self.__modifyFixedResultItem(itm, text, True) |
522 else: |
548 else: |
523 self.__modifyFixedResultItem(itm, "", False) |
549 self.__modifyFixedResultItem(itm, "", False) |
524 fixer.saveFile(encoding) |
550 fixer.saveFile(encoding) |
525 self.__updateStatistics(stats, fixer) |
551 self.__updateStatistics(stats, fixer, ignoredErrors) |
526 progress += 1 |
552 progress += 1 |
527 finally: |
553 finally: |
528 # reenable updates of the list |
554 # reenable updates of the list |
529 self.resultList.setSortingEnabled(True) |
555 self.resultList.setSortingEnabled(True) |
530 self.resultList.setUpdatesEnabled(True) |
556 self.resultList.setUpdatesEnabled(True) |
576 "IncludeMessages": self.includeMessagesEdit.text(), |
602 "IncludeMessages": self.includeMessagesEdit.text(), |
577 "RepeatMessages": self.repeatCheckBox.isChecked(), |
603 "RepeatMessages": self.repeatCheckBox.isChecked(), |
578 "FixCodes": self.fixIssuesEdit.text(), |
604 "FixCodes": self.fixIssuesEdit.text(), |
579 "NoFixCodes": self.noFixIssuesEdit.text(), |
605 "NoFixCodes": self.noFixIssuesEdit.text(), |
580 "FixIssues": self.fixIssuesCheckBox.isChecked(), |
606 "FixIssues": self.fixIssuesCheckBox.isChecked(), |
|
607 "ShowIgnored": self.ignoredCheckBox.isChecked(), |
581 "MaxLineLength": self.lineLengthSpinBox.value(), |
608 "MaxLineLength": self.lineLengthSpinBox.value(), |
582 "HangClosing": self.hangClosingCheckBox.isChecked(), |
609 "HangClosing": self.hangClosingCheckBox.isChecked(), |
583 "DocstringType": self.docTypeComboBox.itemData( |
610 "DocstringType": self.docTypeComboBox.itemData( |
584 self.docTypeComboBox.currentIndex()), |
611 self.docTypeComboBox.currentIndex()), |
585 } |
612 } |
738 "PEP8/FixCodes")) |
765 "PEP8/FixCodes")) |
739 self.noFixIssuesEdit.setText(Preferences.Prefs.settings.value( |
766 self.noFixIssuesEdit.setText(Preferences.Prefs.settings.value( |
740 "PEP8/NoFixCodes", "E501")) |
767 "PEP8/NoFixCodes", "E501")) |
741 self.fixIssuesCheckBox.setChecked(Preferences.toBool( |
768 self.fixIssuesCheckBox.setChecked(Preferences.toBool( |
742 Preferences.Prefs.settings.value("PEP8/FixIssues"))) |
769 Preferences.Prefs.settings.value("PEP8/FixIssues"))) |
|
770 self.ignoredCheckBox.setChecked(Preferences.toBool( |
|
771 Preferences.Prefs.settings.value("PEP8/ShowIgnored"))) |
743 self.lineLengthSpinBox.setValue(int(Preferences.Prefs.settings.value( |
772 self.lineLengthSpinBox.setValue(int(Preferences.Prefs.settings.value( |
744 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH))) |
773 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH))) |
745 self.hangClosingCheckBox.setChecked(Preferences.toBool( |
774 self.hangClosingCheckBox.setChecked(Preferences.toBool( |
746 Preferences.Prefs.settings.value("PEP8/HangClosing"))) |
775 Preferences.Prefs.settings.value("PEP8/HangClosing"))) |
747 self.docTypeComboBox.setCurrentIndex(self.docTypeComboBox.findData( |
776 self.docTypeComboBox.setCurrentIndex(self.docTypeComboBox.findData( |
766 Preferences.Prefs.settings.setValue( |
795 Preferences.Prefs.settings.setValue( |
767 "PEP8/NoFixCodes", self.noFixIssuesEdit.text()) |
796 "PEP8/NoFixCodes", self.noFixIssuesEdit.text()) |
768 Preferences.Prefs.settings.setValue( |
797 Preferences.Prefs.settings.setValue( |
769 "PEP8/FixIssues", self.fixIssuesCheckBox.isChecked()) |
798 "PEP8/FixIssues", self.fixIssuesCheckBox.isChecked()) |
770 Preferences.Prefs.settings.setValue( |
799 Preferences.Prefs.settings.setValue( |
|
800 "PEP8/ShowIgnored", self.ignoredCheckBox.isChecked()) |
|
801 Preferences.Prefs.settings.setValue( |
771 "PEP8/MaxLineLength", self.lineLengthSpinBox.value()) |
802 "PEP8/MaxLineLength", self.lineLengthSpinBox.value()) |
772 Preferences.Prefs.settings.setValue( |
803 Preferences.Prefs.settings.setValue( |
773 "PEP8/HangClosing", self.hangClosingCheckBox.isChecked()) |
804 "PEP8/HangClosing", self.hangClosingCheckBox.isChecked()) |
774 Preferences.Prefs.settings.setValue( |
805 Preferences.Prefs.settings.setValue( |
775 "PEP8/DocstringType", self.docTypeComboBox.itemData( |
806 "PEP8/DocstringType", self.docTypeComboBox.itemData( |
786 Preferences.Prefs.settings.setValue("PEP8/IncludeMessages", "") |
817 Preferences.Prefs.settings.setValue("PEP8/IncludeMessages", "") |
787 Preferences.Prefs.settings.setValue("PEP8/RepeatMessages", False) |
818 Preferences.Prefs.settings.setValue("PEP8/RepeatMessages", False) |
788 Preferences.Prefs.settings.setValue("PEP8/FixCodes", "") |
819 Preferences.Prefs.settings.setValue("PEP8/FixCodes", "") |
789 Preferences.Prefs.settings.setValue("PEP8/NoFixCodes", "E501") |
820 Preferences.Prefs.settings.setValue("PEP8/NoFixCodes", "E501") |
790 Preferences.Prefs.settings.setValue("PEP8/FixIssues", False) |
821 Preferences.Prefs.settings.setValue("PEP8/FixIssues", False) |
|
822 Preferences.Prefs.settings.setValue("PEP8/ShowIgnored", False) |
791 Preferences.Prefs.settings.setValue( |
823 Preferences.Prefs.settings.setValue( |
792 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH) |
824 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH) |
793 Preferences.Prefs.settings.setValue("PEP8/HangClosing", False) |
825 Preferences.Prefs.settings.setValue("PEP8/HangClosing", False) |
794 Preferences.Prefs.settings.setValue("PEP8/DocstringType", "pep257") |
826 Preferences.Prefs.settings.setValue("PEP8/DocstringType", "pep257") |
795 |
827 |
925 Private method to check, if an item has a fixable issue. |
957 Private method to check, if an item has a fixable issue. |
926 |
958 |
927 @param itm item to be checked (QTreeWidgetItem) |
959 @param itm item to be checked (QTreeWidgetItem) |
928 @return flag indicating a fixable issue (boolean) |
960 @return flag indicating a fixable issue (boolean) |
929 """ |
961 """ |
930 return itm.data(0, self.fixableRole) |
962 return (itm.data(0, self.fixableRole) and |
|
963 not itm.data(0, self.ignoredRole)) |