35 lineRole = Qt.UserRole + 2 |
35 lineRole = Qt.UserRole + 2 |
36 positionRole = Qt.UserRole + 3 |
36 positionRole = Qt.UserRole + 3 |
37 messageRole = Qt.UserRole + 4 |
37 messageRole = Qt.UserRole + 4 |
38 fixableRole = Qt.UserRole + 5 |
38 fixableRole = Qt.UserRole + 5 |
39 codeRole = Qt.UserRole + 6 |
39 codeRole = Qt.UserRole + 6 |
|
40 ignoredRole = Qt.UserRole + 7 |
40 |
41 |
41 def __init__(self, styleCheckService, parent=None): |
42 def __init__(self, styleCheckService, parent=None): |
42 """ |
43 """ |
43 Constructor |
44 Constructor |
44 |
45 |
103 """ |
104 """ |
104 self.resultList.sortItems(self.resultList.sortColumn(), |
105 self.resultList.sortItems(self.resultList.sortColumn(), |
105 self.resultList.header().sortIndicatorOrder() |
106 self.resultList.header().sortIndicatorOrder() |
106 ) |
107 ) |
107 |
108 |
108 def __createResultItem(self, file, line, pos, message, fixed, autofixing): |
109 def __createResultItem(self, file, line, pos, message, fixed, autofixing, |
|
110 ignored): |
109 """ |
111 """ |
110 Private method to create an entry in the result list. |
112 Private method to create an entry in the result list. |
111 |
113 |
112 @param file file name of the file (string) |
114 @param file file name of the file (string) |
113 @param line line number of issue (integer or string) |
115 @param line line number of issue (integer or string) |
114 @param pos character position of issue (integer or string) |
116 @param pos character position of issue (integer or string) |
115 @param message message text (string) |
117 @param message message text (string) |
116 @param fixed flag indicating a fixed issue (boolean) |
118 @param fixed flag indicating a fixed issue (boolean) |
117 @param autofixing flag indicating, that we are fixing issues |
119 @param autofixing flag indicating, that we are fixing issues |
118 automatically (boolean) |
120 automatically (boolean) |
|
121 @param ignored flag indicating an ignored issue (boolean) |
119 @return reference to the created item (QTreeWidgetItem) |
122 @return reference to the created item (QTreeWidgetItem) |
120 """ |
123 """ |
121 from .CodeStyleFixer import FixableCodeStyleIssues |
124 from .CodeStyleFixer import FixableCodeStyleIssues |
122 |
125 |
123 if self.__lastFileItem is None: |
126 if self.__lastFileItem is None: |
157 itm.setData(0, self.lineRole, int(line)) |
160 itm.setData(0, self.lineRole, int(line)) |
158 itm.setData(0, self.positionRole, int(pos)) |
161 itm.setData(0, self.positionRole, int(pos)) |
159 itm.setData(0, self.messageRole, message) |
162 itm.setData(0, self.messageRole, message) |
160 itm.setData(0, self.fixableRole, fixable) |
163 itm.setData(0, self.fixableRole, fixable) |
161 itm.setData(0, self.codeRole, code) |
164 itm.setData(0, self.codeRole, code) |
|
165 itm.setData(0, self.ignoredRole, ignored) |
|
166 |
|
167 if ignored: |
|
168 font = itm.font(0) |
|
169 font.setItalic(True) |
|
170 for col in range(itm.columnCount()): |
|
171 itm.setFont(col, font) |
162 |
172 |
163 return itm |
173 return itm |
164 |
174 |
165 def __modifyFixedResultItem(self, itm, text, fixed): |
175 def __modifyFixedResultItem(self, itm, text, fixed): |
166 """ |
176 """ |
179 itm.setData(0, self.messageRole, message) |
189 itm.setData(0, self.messageRole, message) |
180 else: |
190 else: |
181 itm.setIcon(0, QIcon()) |
191 itm.setIcon(0, QIcon()) |
182 itm.setData(0, self.fixableRole, False) |
192 itm.setData(0, self.fixableRole, False) |
183 |
193 |
184 def __updateStatistics(self, statistics, fixer): |
194 def __updateStatistics(self, statistics, fixer, ignoredErrors): |
185 """ |
195 """ |
186 Private method to update the collected statistics. |
196 Private method to update the collected statistics. |
187 |
197 |
188 @param statistics dictionary of statistical data with |
198 @param statistics dictionary of statistical data with |
189 message code as key and message count as value |
199 message code as key and message count as value |
190 @param fixer reference to the code style fixer (CodeStyleFixer) |
200 @param fixer reference to the code style fixer (CodeStyleFixer) |
|
201 @param ignoredErrors number of ignored errors (integer) |
191 """ |
202 """ |
192 self.__statistics["_FilesCount"] += 1 |
203 self.__statistics["_FilesCount"] += 1 |
193 stats = [k for k in statistics.keys() if k[0].isupper()] |
204 stats = [k for k in statistics.keys() if k[0].isupper()] |
194 if stats: |
205 if stats: |
195 self.__statistics["_FilesIssues"] += 1 |
206 self.__statistics["_FilesIssues"] += 1 |
197 if key in self.__statistics: |
208 if key in self.__statistics: |
198 self.__statistics[key] += statistics[key] |
209 self.__statistics[key] += statistics[key] |
199 else: |
210 else: |
200 self.__statistics[key] = statistics[key] |
211 self.__statistics[key] = statistics[key] |
201 self.__statistics["_IssuesFixed"] += fixer |
212 self.__statistics["_IssuesFixed"] += fixer |
|
213 self.__statistics["_IgnoredErrors"] += ignoredErrors |
202 |
214 |
203 def __updateFixerStatistics(self, fixer): |
215 def __updateFixerStatistics(self, fixer): |
204 """ |
216 """ |
205 Private method to update the collected fixer related statistics. |
217 Private method to update the collected fixer related statistics. |
206 |
218 |
214 """ |
226 """ |
215 self.__statistics = {} |
227 self.__statistics = {} |
216 self.__statistics["_FilesCount"] = 0 |
228 self.__statistics["_FilesCount"] = 0 |
217 self.__statistics["_FilesIssues"] = 0 |
229 self.__statistics["_FilesIssues"] = 0 |
218 self.__statistics["_IssuesFixed"] = 0 |
230 self.__statistics["_IssuesFixed"] = 0 |
|
231 self.__statistics["_IgnoredErrors"] = 0 |
219 |
232 |
220 def prepare(self, fileList, project): |
233 def prepare(self, fileList, project): |
221 """ |
234 """ |
222 Public method to prepare the dialog with a list of filenames. |
235 Public method to prepare the dialog with a list of filenames. |
223 |
236 |
250 self.__data["HangClosing"] = False |
263 self.__data["HangClosing"] = False |
251 if "NoFixCodes" not in self.__data: |
264 if "NoFixCodes" not in self.__data: |
252 self.__data["NoFixCodes"] = "E501" |
265 self.__data["NoFixCodes"] = "E501" |
253 if "DocstringType" not in self.__data: |
266 if "DocstringType" not in self.__data: |
254 self.__data["DocstringType"] = "pep257" |
267 self.__data["DocstringType"] = "pep257" |
|
268 if "ShowIgnored" not in self.__data: |
|
269 self.__data["ShowIgnored"] = False |
255 |
270 |
256 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
271 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
257 self.excludeMessagesEdit.setText(self.__data["ExcludeMessages"]) |
272 self.excludeMessagesEdit.setText(self.__data["ExcludeMessages"]) |
258 self.includeMessagesEdit.setText(self.__data["IncludeMessages"]) |
273 self.includeMessagesEdit.setText(self.__data["IncludeMessages"]) |
259 self.repeatCheckBox.setChecked(self.__data["RepeatMessages"]) |
274 self.repeatCheckBox.setChecked(self.__data["RepeatMessages"]) |
260 self.fixIssuesEdit.setText(self.__data["FixCodes"]) |
275 self.fixIssuesEdit.setText(self.__data["FixCodes"]) |
261 self.noFixIssuesEdit.setText(self.__data["NoFixCodes"]) |
276 self.noFixIssuesEdit.setText(self.__data["NoFixCodes"]) |
262 self.fixIssuesCheckBox.setChecked(self.__data["FixIssues"]) |
277 self.fixIssuesCheckBox.setChecked(self.__data["FixIssues"]) |
|
278 self.ignoredCheckBox.setChecked(self.__data["ShowIgnored"]) |
263 self.lineLengthSpinBox.setValue(self.__data["MaxLineLength"]) |
279 self.lineLengthSpinBox.setValue(self.__data["MaxLineLength"]) |
264 self.hangClosingCheckBox.setChecked(self.__data["HangClosing"]) |
280 self.hangClosingCheckBox.setChecked(self.__data["HangClosing"]) |
265 self.docTypeComboBox.setCurrentIndex( |
281 self.docTypeComboBox.setCurrentIndex( |
266 self.docTypeComboBox.findData(self.__data["DocstringType"])) |
282 self.docTypeComboBox.findData(self.__data["DocstringType"])) |
267 |
283 |
331 includeMessages = self.includeMessagesEdit.text() |
347 includeMessages = self.includeMessagesEdit.text() |
332 repeatMessages = self.repeatCheckBox.isChecked() |
348 repeatMessages = self.repeatCheckBox.isChecked() |
333 fixCodes = self.fixIssuesEdit.text() |
349 fixCodes = self.fixIssuesEdit.text() |
334 noFixCodes = self.noFixIssuesEdit.text() |
350 noFixCodes = self.noFixIssuesEdit.text() |
335 fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages |
351 fixIssues = self.fixIssuesCheckBox.isChecked() and repeatMessages |
|
352 self.showIgnored = self.ignoredCheckBox.isChecked() and \ |
|
353 repeatMessages |
336 maxLineLength = self.lineLengthSpinBox.value() |
354 maxLineLength = self.lineLengthSpinBox.value() |
337 hangClosing = self.hangClosingCheckBox.isChecked() |
355 hangClosing = self.hangClosingCheckBox.isChecked() |
338 docType = self.docTypeComboBox.itemData( |
356 docType = self.docTypeComboBox.itemData( |
339 self.docTypeComboBox.currentIndex()) |
357 self.docTypeComboBox.currentIndex()) |
340 |
358 |
387 except (UnicodeError, IOError) as msg: |
405 except (UnicodeError, IOError) as msg: |
388 self.noResults = False |
406 self.noResults = False |
389 self.__createResultItem( |
407 self.__createResultItem( |
390 self.filename, 1, 1, |
408 self.filename, 1, 1, |
391 self.tr("Error: {0}").format(str(msg)) |
409 self.tr("Error: {0}").format(str(msg)) |
392 .rstrip()[1:-1], False, False) |
410 .rstrip()[1:-1], False, False, False) |
393 self.progress += 1 |
411 self.progress += 1 |
394 # Continue with next file |
412 # Continue with next file |
395 self.check() |
413 self.check() |
396 return |
414 return |
397 |
415 |
412 |
430 |
413 @param fn filename of the just checked file (str) |
431 @param fn filename of the just checked file (str) |
414 @param codeStyleCheckerStats stats of style and name check (dict) |
432 @param codeStyleCheckerStats stats of style and name check (dict) |
415 @param fixes number of applied fixes (int) |
433 @param fixes number of applied fixes (int) |
416 @param results tuple for each found violation of style (tuple of |
434 @param results tuple for each found violation of style (tuple of |
417 lineno (int), position (int), text (str), fixed (bool), |
435 lineno (int), position (int), text (str), ignored (bool), |
418 autofixing (bool)) |
436 fixed (bool), autofixing (bool)) |
419 """ |
437 """ |
420 # Check if it's the requested file, otherwise ignore signal |
438 # Check if it's the requested file, otherwise ignore signal |
421 if fn != self.filename: |
439 if fn != self.filename: |
422 return |
440 return |
423 |
441 |
424 # disable updates of the list for speed |
442 # disable updates of the list for speed |
425 self.resultList.setUpdatesEnabled(False) |
443 self.resultList.setUpdatesEnabled(False) |
426 self.resultList.setSortingEnabled(False) |
444 self.resultList.setSortingEnabled(False) |
427 |
445 |
428 fixed = None |
446 fixed = None |
|
447 ignoredErrors = 0 |
429 if self.__itms: |
448 if self.__itms: |
430 for itm, (lineno, position, text, fixed, autofixing) in zip( |
449 for itm, (lineno, position, text, ignored, fixed, autofixing) in \ |
431 self.__itms, results): |
450 zip(self.__itms, results): |
432 self.__modifyFixedResultItem(itm, text, fixed) |
451 self.__modifyFixedResultItem(itm, text, fixed) |
433 self.__updateFixerStatistics(fixes) |
452 self.__updateFixerStatistics(fixes) |
434 else: |
453 else: |
435 for lineno, position, text, fixed, autofixing in results: |
454 for lineno, position, text, ignored, fixed, autofixing in results: |
|
455 if ignored: |
|
456 ignoredErrors += 1 |
|
457 if self.showIgnored: |
|
458 text = self.tr("{0} (ignored)").format(text) |
|
459 else: |
|
460 continue |
436 self.noResults = False |
461 self.noResults = False |
437 self.__createResultItem( |
462 self.__createResultItem( |
438 fn, lineno, position, text, fixed, autofixing) |
463 fn, lineno, position, text, fixed, autofixing, ignored) |
439 |
464 |
440 self.__updateStatistics(codeStyleCheckerStats, fixes) |
465 self.__updateStatistics( |
|
466 codeStyleCheckerStats, fixes, ignoredErrors) |
441 |
467 |
442 if fixed: |
468 if fixed: |
443 vm = e5App().getObject("ViewManager") |
469 vm = e5App().getObject("ViewManager") |
444 editor = vm.getOpenEditor(fn) |
470 editor = vm.getOpenEditor(fn) |
445 if editor: |
471 if editor: |
509 "IncludeMessages": self.includeMessagesEdit.text(), |
535 "IncludeMessages": self.includeMessagesEdit.text(), |
510 "RepeatMessages": self.repeatCheckBox.isChecked(), |
536 "RepeatMessages": self.repeatCheckBox.isChecked(), |
511 "FixCodes": self.fixIssuesEdit.text(), |
537 "FixCodes": self.fixIssuesEdit.text(), |
512 "NoFixCodes": self.noFixIssuesEdit.text(), |
538 "NoFixCodes": self.noFixIssuesEdit.text(), |
513 "FixIssues": self.fixIssuesCheckBox.isChecked(), |
539 "FixIssues": self.fixIssuesCheckBox.isChecked(), |
|
540 "ShowIgnored": self.ignoredCheckBox.isChecked(), |
514 "MaxLineLength": self.lineLengthSpinBox.value(), |
541 "MaxLineLength": self.lineLengthSpinBox.value(), |
515 "HangClosing": self.hangClosingCheckBox.isChecked(), |
542 "HangClosing": self.hangClosingCheckBox.isChecked(), |
516 "DocstringType": self.docTypeComboBox.itemData( |
543 "DocstringType": self.docTypeComboBox.itemData( |
517 self.docTypeComboBox.currentIndex()), |
544 self.docTypeComboBox.currentIndex()), |
518 } |
545 } |
671 "PEP8/FixCodes")) |
698 "PEP8/FixCodes")) |
672 self.noFixIssuesEdit.setText(Preferences.Prefs.settings.value( |
699 self.noFixIssuesEdit.setText(Preferences.Prefs.settings.value( |
673 "PEP8/NoFixCodes", "E501")) |
700 "PEP8/NoFixCodes", "E501")) |
674 self.fixIssuesCheckBox.setChecked(Preferences.toBool( |
701 self.fixIssuesCheckBox.setChecked(Preferences.toBool( |
675 Preferences.Prefs.settings.value("PEP8/FixIssues"))) |
702 Preferences.Prefs.settings.value("PEP8/FixIssues"))) |
|
703 self.ignoredCheckBox.setChecked(Preferences.toBool( |
|
704 Preferences.Prefs.settings.value("PEP8/ShowIgnored"))) |
676 self.lineLengthSpinBox.setValue(int(Preferences.Prefs.settings.value( |
705 self.lineLengthSpinBox.setValue(int(Preferences.Prefs.settings.value( |
677 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH))) |
706 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH))) |
678 self.hangClosingCheckBox.setChecked(Preferences.toBool( |
707 self.hangClosingCheckBox.setChecked(Preferences.toBool( |
679 Preferences.Prefs.settings.value("PEP8/HangClosing"))) |
708 Preferences.Prefs.settings.value("PEP8/HangClosing"))) |
680 self.docTypeComboBox.setCurrentIndex(self.docTypeComboBox.findData( |
709 self.docTypeComboBox.setCurrentIndex(self.docTypeComboBox.findData( |
699 Preferences.Prefs.settings.setValue( |
728 Preferences.Prefs.settings.setValue( |
700 "PEP8/NoFixCodes", self.noFixIssuesEdit.text()) |
729 "PEP8/NoFixCodes", self.noFixIssuesEdit.text()) |
701 Preferences.Prefs.settings.setValue( |
730 Preferences.Prefs.settings.setValue( |
702 "PEP8/FixIssues", self.fixIssuesCheckBox.isChecked()) |
731 "PEP8/FixIssues", self.fixIssuesCheckBox.isChecked()) |
703 Preferences.Prefs.settings.setValue( |
732 Preferences.Prefs.settings.setValue( |
|
733 "PEP8/ShowIgnored", self.ignoredCheckBox.isChecked()) |
|
734 Preferences.Prefs.settings.setValue( |
704 "PEP8/MaxLineLength", self.lineLengthSpinBox.value()) |
735 "PEP8/MaxLineLength", self.lineLengthSpinBox.value()) |
705 Preferences.Prefs.settings.setValue( |
736 Preferences.Prefs.settings.setValue( |
706 "PEP8/HangClosing", self.hangClosingCheckBox.isChecked()) |
737 "PEP8/HangClosing", self.hangClosingCheckBox.isChecked()) |
707 Preferences.Prefs.settings.setValue( |
738 Preferences.Prefs.settings.setValue( |
708 "PEP8/DocstringType", self.docTypeComboBox.itemData( |
739 "PEP8/DocstringType", self.docTypeComboBox.itemData( |
719 Preferences.Prefs.settings.setValue("PEP8/IncludeMessages", "") |
750 Preferences.Prefs.settings.setValue("PEP8/IncludeMessages", "") |
720 Preferences.Prefs.settings.setValue("PEP8/RepeatMessages", False) |
751 Preferences.Prefs.settings.setValue("PEP8/RepeatMessages", False) |
721 Preferences.Prefs.settings.setValue("PEP8/FixCodes", "") |
752 Preferences.Prefs.settings.setValue("PEP8/FixCodes", "") |
722 Preferences.Prefs.settings.setValue("PEP8/NoFixCodes", "E501") |
753 Preferences.Prefs.settings.setValue("PEP8/NoFixCodes", "E501") |
723 Preferences.Prefs.settings.setValue("PEP8/FixIssues", False) |
754 Preferences.Prefs.settings.setValue("PEP8/FixIssues", False) |
|
755 Preferences.Prefs.settings.setValue("PEP8/ShowIgnored", False) |
724 Preferences.Prefs.settings.setValue( |
756 Preferences.Prefs.settings.setValue( |
725 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH) |
757 "PEP8/MaxLineLength", pep8.MAX_LINE_LENGTH) |
726 Preferences.Prefs.settings.setValue("PEP8/HangClosing", False) |
758 Preferences.Prefs.settings.setValue("PEP8/HangClosing", False) |
727 Preferences.Prefs.settings.setValue("PEP8/DocstringType", "pep257") |
759 Preferences.Prefs.settings.setValue("PEP8/DocstringType", "pep257") |
728 |
760 |
775 itm.data(0, self.positionRole), |
807 itm.data(0, self.positionRole), |
776 "{0} {1}".format(itm.data(0, self.codeRole), |
808 "{0} {1}".format(itm.data(0, self.codeRole), |
777 itm.data(0, self.messageRole))), |
809 itm.data(0, self.messageRole))), |
778 itm |
810 itm |
779 )) |
811 )) |
780 |
812 ##! |
781 # update the configuration values (3: fixCodes, 4: noFixCodes, |
813 # update the configuration values (3: fixCodes, 4: noFixCodes, |
782 # 5: fixIssues, 6: maxLineLength) |
814 # 5: fixIssues, 6: maxLineLength) |
783 self.__options[3] = self.fixIssuesEdit.text() |
815 self.__options[3] = self.fixIssuesEdit.text() |
784 self.__options[4] = self.noFixIssuesEdit.text() |
816 self.__options[4] = self.noFixIssuesEdit.text() |
785 self.__options[5] = True |
817 self.__options[5] = True |