12 |
12 |
13 from PyQt5.QtCore import pyqtSlot, Qt, QTimer, QCoreApplication |
13 from PyQt5.QtCore import pyqtSlot, Qt, QTimer, QCoreApplication |
14 from PyQt5.QtGui import QIcon |
14 from PyQt5.QtGui import QIcon |
15 from PyQt5.QtWidgets import ( |
15 from PyQt5.QtWidgets import ( |
16 QDialog, QTreeWidgetItem, QAbstractButton, QDialogButtonBox, QApplication, |
16 QDialog, QTreeWidgetItem, QAbstractButton, QDialogButtonBox, QApplication, |
17 QHeaderView, QListWidgetItem |
17 QHeaderView, QListWidgetItem, QInputDialog, QLineEdit |
18 ) |
18 ) |
19 |
19 |
20 from E5Gui.E5Application import e5App |
20 from E5Gui.E5Application import e5App |
21 |
21 |
22 from .Ui_CodeStyleCheckerDialog import Ui_CodeStyleCheckerDialog |
22 from .Ui_CodeStyleCheckerDialog import Ui_CodeStyleCheckerDialog |
461 if "BuiltinsChecker" not in self.__data: |
461 if "BuiltinsChecker" not in self.__data: |
462 self.__data["BuiltinsChecker"] = { |
462 self.__data["BuiltinsChecker"] = { |
463 "str": ["unicode", ], |
463 "str": ["unicode", ], |
464 "chr": ["unichr", ], |
464 "chr": ["unichr", ], |
465 } |
465 } |
|
466 |
466 if "CommentedCodeChecker" not in self.__data: |
467 if "CommentedCodeChecker" not in self.__data: |
467 self.__data["CommentedCodeChecker"] = { |
468 self.__data["CommentedCodeChecker"] = { |
468 "Aggressive": False, |
469 "Aggressive": False, |
469 } |
470 } |
|
471 if "WhiteList" not in self.__data["CommentedCodeChecker"]: |
|
472 self.__data["CommentedCodeChecker"]["WhiteList"] = [ |
|
473 r'pylint', |
|
474 r'pyright', |
|
475 r'noqa', |
|
476 r'type:\s*ignore', |
|
477 r'fmt:\s*(on|off)', |
|
478 r'TODO', |
|
479 r'FIXME', |
|
480 r'WARNING', |
|
481 r'NOTE', |
|
482 r'TEST', |
|
483 r'DOCU', |
|
484 r'XXX', |
|
485 r'~ ', |
|
486 r'- ', |
|
487 ] |
|
488 |
470 if "AnnotationsChecker" not in self.__data: |
489 if "AnnotationsChecker" not in self.__data: |
471 self.__data["AnnotationsChecker"] = { |
490 self.__data["AnnotationsChecker"] = { |
472 "MinimumCoverage": 75, |
491 "MinimumCoverage": 75, |
473 "MaximumComplexity": 3, |
492 "MaximumComplexity": 3, |
474 } |
493 } |
524 self.copyrightAuthorEdit.setText(self.__data["CopyrightAuthor"]) |
543 self.copyrightAuthorEdit.setText(self.__data["CopyrightAuthor"]) |
525 self.__initFuturesList(self.__data["FutureChecker"]) |
544 self.__initFuturesList(self.__data["FutureChecker"]) |
526 self.__initBuiltinsIgnoreList(self.__data["BuiltinsChecker"]) |
545 self.__initBuiltinsIgnoreList(self.__data["BuiltinsChecker"]) |
527 self.aggressiveCheckBox.setChecked( |
546 self.aggressiveCheckBox.setChecked( |
528 self.__data["CommentedCodeChecker"]["Aggressive"]) |
547 self.__data["CommentedCodeChecker"]["Aggressive"]) |
|
548 self.__initCommentedCodeCheckerWhiteList( |
|
549 self.__data["CommentedCodeChecker"]["WhiteList"]) |
529 self.minAnnotationsCoverageSpinBox.setValue( |
550 self.minAnnotationsCoverageSpinBox.setValue( |
530 self.__data["AnnotationsChecker"]["MinimumCoverage"]) |
551 self.__data["AnnotationsChecker"]["MinimumCoverage"]) |
531 self.maxAnnotationsComplexitySpinBox.setValue( |
552 self.maxAnnotationsComplexitySpinBox.setValue( |
532 self.__data["AnnotationsChecker"]["MaximumComplexity"]) |
553 self.__data["AnnotationsChecker"]["MaximumComplexity"]) |
533 |
554 |
675 }, |
696 }, |
676 "FutureChecker": self.__getSelectedFutureImports(), |
697 "FutureChecker": self.__getSelectedFutureImports(), |
677 "BuiltinsChecker": self.__getBuiltinsIgnoreList(), |
698 "BuiltinsChecker": self.__getBuiltinsIgnoreList(), |
678 "CommentedCodeChecker": { |
699 "CommentedCodeChecker": { |
679 "Aggressive": self.aggressiveCheckBox.isChecked(), |
700 "Aggressive": self.aggressiveCheckBox.isChecked(), |
|
701 "WhiteList": self.__getCommentedCodeCheckerWhiteList(), |
680 } |
702 } |
681 } |
703 } |
682 annotationArgs = { |
704 annotationArgs = { |
683 "MinimumCoverage": |
705 "MinimumCoverage": |
684 self.minAnnotationsCoverageSpinBox.value(), |
706 self.minAnnotationsCoverageSpinBox.value(), |
1080 "CopyrightAuthor": self.copyrightAuthorEdit.text(), |
1102 "CopyrightAuthor": self.copyrightAuthorEdit.text(), |
1081 "FutureChecker": self.__getSelectedFutureImports(), |
1103 "FutureChecker": self.__getSelectedFutureImports(), |
1082 "BuiltinsChecker": self.__getBuiltinsIgnoreList(), |
1104 "BuiltinsChecker": self.__getBuiltinsIgnoreList(), |
1083 "CommentedCodeChecker": { |
1105 "CommentedCodeChecker": { |
1084 "Aggressive": self.aggressiveCheckBox.isChecked(), |
1106 "Aggressive": self.aggressiveCheckBox.isChecked(), |
|
1107 "WhiteList": self.__getCommentedCodeCheckerWhiteList(), |
1085 }, |
1108 }, |
1086 "AnnotationsChecker": { |
1109 "AnnotationsChecker": { |
1087 "MinimumCoverage": |
1110 "MinimumCoverage": |
1088 self.minAnnotationsCoverageSpinBox.value(), |
1111 self.minAnnotationsCoverageSpinBox.value(), |
1089 "MaximumComplexity": |
1112 "MaximumComplexity": |
1880 if message[0] in disabledCheckers: |
1903 if message[0] in disabledCheckers: |
1881 excludedMessages.remove(message) |
1904 excludedMessages.remove(message) |
1882 |
1905 |
1883 self.excludeMessagesEdit.setText(",".join(excludedMessages)) |
1906 self.excludeMessagesEdit.setText(",".join(excludedMessages)) |
1884 self.__initCategoriesList(",".join(enabledCheckers)) |
1907 self.__initCategoriesList(",".join(enabledCheckers)) |
|
1908 |
|
1909 def __initCommentedCodeCheckerWhiteList(self, whitelist): |
|
1910 """ |
|
1911 Private method to populate the list of commented code whitelist |
|
1912 patterns. |
|
1913 |
|
1914 @param whitelist list of commented code whitelist patterns |
|
1915 @type list of str |
|
1916 """ |
|
1917 self.whitelistWidget.clear() |
|
1918 |
|
1919 for pattern in whitelist: |
|
1920 QListWidgetItem(pattern, self.whitelistWidget) |
|
1921 |
|
1922 self.on_whitelistWidget_itemSelectionChanged() |
|
1923 |
|
1924 def __getCommentedCodeCheckerWhiteList(self): |
|
1925 """ |
|
1926 Private method to get the list of commented code whitelist patterns. |
|
1927 |
|
1928 @return list of commented code whitelist patterns |
|
1929 @rtype list of str |
|
1930 """ |
|
1931 whitelist = [] |
|
1932 |
|
1933 for row in range(self.whitelistWidget.count()): |
|
1934 whitelist.append(self.whitelistWidget.item(row).text()) |
|
1935 |
|
1936 return whitelist |
|
1937 |
|
1938 @pyqtSlot() |
|
1939 def on_whitelistWidget_itemSelectionChanged(self): |
|
1940 """ |
|
1941 Private slot to react upon changes of the selected whitelist patterns. |
|
1942 """ |
|
1943 self.deleteWhitelistButton.setEnabled( |
|
1944 len(self.whitelistWidget.selectedItems()) > 0) |
|
1945 |
|
1946 @pyqtSlot() |
|
1947 def on_addWhitelistButton_clicked(self): |
|
1948 """ |
|
1949 Private slot to add a commented code whitelist pattern. |
|
1950 """ |
|
1951 pattern, ok = QInputDialog.getText( |
|
1952 self, |
|
1953 self.tr("Commented Code Whitelist Pattern"), |
|
1954 self.tr("Enter a Commented Code Whitelist Pattern"), |
|
1955 QLineEdit.Normal) |
|
1956 if ok and pattern: |
|
1957 QListWidgetItem(pattern, self.whitelistWidget) |
|
1958 |
|
1959 @pyqtSlot() |
|
1960 def on_deleteWhitelistButton_clicked(self): |
|
1961 """ |
|
1962 Private slot to delete the selected items from the list. |
|
1963 """ |
|
1964 for itm in self.whitelistWidget.selectedItems(): |
|
1965 index = self.whitelistWidget.indexOfTopLevelItem(itm) |
|
1966 self.whitelistWidget.takeTopLevelItem(index) |
|
1967 del itm |