31 from . import pycodestyle |
31 from . import pycodestyle |
32 |
32 |
33 from .Miscellaneous.MiscellaneousDefaults import ( |
33 from .Miscellaneous.MiscellaneousDefaults import ( |
34 MiscellaneousCheckerDefaultArgs |
34 MiscellaneousCheckerDefaultArgs |
35 ) |
35 ) |
36 |
36 from .Annotations.AnnotationsCheckerDefaults import ( |
37 try: |
37 AnnotationsCheckerDefaultArgs |
38 basestring # __IGNORE_WARNING__ |
38 ) |
39 except Exception: |
|
40 basestring = str # define for Python3 |
|
41 |
39 |
42 |
40 |
43 class CodeStyleCheckerDialog(QDialog, Ui_CodeStyleCheckerDialog): |
41 class CodeStyleCheckerDialog(QDialog, Ui_CodeStyleCheckerDialog): |
44 """ |
42 """ |
45 Class implementing a dialog to show the results of the code style check. |
43 Class implementing a dialog to show the results of the code style check. |
513 MiscellaneousCheckerDefaultArgs[ |
511 MiscellaneousCheckerDefaultArgs[ |
514 "CommentedCodeChecker"]["WhiteList"][:] |
512 "CommentedCodeChecker"]["WhiteList"][:] |
515 ) |
513 ) |
516 |
514 |
517 if "AnnotationsChecker" not in self.__data: |
515 if "AnnotationsChecker" not in self.__data: |
518 self.__data["AnnotationsChecker"] = { |
516 self.__data["AnnotationsChecker"] = copy.deepcopy( |
519 "MinimumCoverage": 75, |
517 AnnotationsCheckerDefaultArgs) |
520 "MaximumComplexity": 3, |
518 else: |
521 } |
519 # We are upgrading from an older data structure |
|
520 if "MaximumLength" not in self.__data["AnnotationsChecker"]: |
|
521 # MaximumLength is the sentinel for the first extension |
|
522 self.__data["AnnotationsChecker"].extend({ |
|
523 "MaximumLength": |
|
524 AnnotationsCheckerDefaultArgs["MaximumLength"], |
|
525 "SuppressNoneReturning": |
|
526 AnnotationsCheckerDefaultArgs["SuppressNoneReturning"], |
|
527 "SuppressDummyArgs": |
|
528 AnnotationsCheckerDefaultArgs["SuppressDummyArgs"], |
|
529 "AllowUntypedDefs": |
|
530 AnnotationsCheckerDefaultArgs["AllowUntypedDefs"], |
|
531 "AllowUntypedNested": |
|
532 AnnotationsCheckerDefaultArgs["AllowUntypedNested"], |
|
533 "MypyInitReturn": |
|
534 AnnotationsCheckerDefaultArgs["MypyInitReturn"], |
|
535 "DispatchDecorators": |
|
536 AnnotationsCheckerDefaultArgs["DispatchDecorators"], |
|
537 "OverloadDecorators": |
|
538 AnnotationsCheckerDefaultArgs["OverloadDecorators"], |
|
539 }) |
|
540 # TODO: add additional AnnotationsChecker parameters |
522 |
541 |
523 if "SecurityChecker" not in self.__data: |
542 if "SecurityChecker" not in self.__data: |
524 from .Security.SecurityDefaults import SecurityDefaults |
543 from .Security.SecurityDefaults import SecurityDefaults |
525 self.__data["SecurityChecker"] = { |
544 self.__data["SecurityChecker"] = { |
526 "HardcodedTmpDirectories": |
545 "HardcodedTmpDirectories": |
573 self.__initBuiltinsIgnoreList(self.__data["BuiltinsChecker"]) |
592 self.__initBuiltinsIgnoreList(self.__data["BuiltinsChecker"]) |
574 self.aggressiveCheckBox.setChecked( |
593 self.aggressiveCheckBox.setChecked( |
575 self.__data["CommentedCodeChecker"]["Aggressive"]) |
594 self.__data["CommentedCodeChecker"]["Aggressive"]) |
576 self.__initCommentedCodeCheckerWhiteList( |
595 self.__initCommentedCodeCheckerWhiteList( |
577 self.__data["CommentedCodeChecker"]["WhiteList"]) |
596 self.__data["CommentedCodeChecker"]["WhiteList"]) |
|
597 |
|
598 # type annotations |
578 self.minAnnotationsCoverageSpinBox.setValue( |
599 self.minAnnotationsCoverageSpinBox.setValue( |
579 self.__data["AnnotationsChecker"]["MinimumCoverage"]) |
600 self.__data["AnnotationsChecker"]["MinimumCoverage"]) |
580 self.maxAnnotationsComplexitySpinBox.setValue( |
601 self.maxAnnotationsComplexitySpinBox.setValue( |
581 self.__data["AnnotationsChecker"]["MaximumComplexity"]) |
602 self.__data["AnnotationsChecker"]["MaximumComplexity"]) |
|
603 self.maxAnnotationsLengthSpinBox.setValue( |
|
604 self.__data["AnnotationsChecker"]["MaximumLength"]) |
|
605 self.suppressNoneReturningCheckBox.setChecked( |
|
606 self.__data["AnnotationsChecker"]["SuppressNoneReturning"]) |
|
607 self.suppressDummyArgsCheckBox.setChecked( |
|
608 self.__data["AnnotationsChecker"]["SuppressDummyArgs"]) |
|
609 self.allowUntypedDefsCheckBox.setChecked( |
|
610 self.__data["AnnotationsChecker"]["AllowUntypedDefs"]) |
|
611 self.allowUntypedNestedCheckBox.setChecked( |
|
612 self.__data["AnnotationsChecker"]["AllowUntypedNested"]) |
|
613 self.mypyInitReturnCheckBox.setChecked( |
|
614 self.__data["AnnotationsChecker"]["MypyInitReturn"]) |
|
615 self.dispatchDecoratorEdit.setText( |
|
616 ", ".join( |
|
617 self.__data["AnnotationsChecker"]["DispatchDecorators"])) |
|
618 self.overloadDecoratorEdit.setText( |
|
619 ", ".join( |
|
620 self.__data["AnnotationsChecker"]["OverloadDecorators"])) |
|
621 # TODO: add additional AnnotationsChecker parameters |
582 |
622 |
583 # security |
623 # security |
584 self.tmpDirectoriesEdit.setPlainText("\n".join( |
624 self.tmpDirectoriesEdit.setPlainText("\n".join( |
585 self.__data["SecurityChecker"]["HardcodedTmpDirectories"])) |
625 self.__data["SecurityChecker"]["HardcodedTmpDirectories"])) |
586 self.hashesEdit.setText(", ".join( |
626 self.hashesEdit.setText(", ".join( |
728 "CommentedCodeChecker": { |
768 "CommentedCodeChecker": { |
729 "Aggressive": self.aggressiveCheckBox.isChecked(), |
769 "Aggressive": self.aggressiveCheckBox.isChecked(), |
730 "WhiteList": self.__getCommentedCodeCheckerWhiteList(), |
770 "WhiteList": self.__getCommentedCodeCheckerWhiteList(), |
731 } |
771 } |
732 } |
772 } |
|
773 |
733 annotationArgs = { |
774 annotationArgs = { |
734 "MinimumCoverage": |
775 "MinimumCoverage": |
735 self.minAnnotationsCoverageSpinBox.value(), |
776 self.minAnnotationsCoverageSpinBox.value(), |
736 "MaximumComplexity": |
777 "MaximumComplexity": |
737 self.maxAnnotationsComplexitySpinBox.value(), |
778 self.maxAnnotationsComplexitySpinBox.value(), |
|
779 "MaximumLength": |
|
780 self.maxAnnotationsLengthSpinBox.value(), |
|
781 "SuppressNoneReturning": |
|
782 self.suppressNoneReturningCheckBox.isChecked(), |
|
783 "SuppressDummyArgs": |
|
784 self.suppressDummyArgsCheckBox.isChecked(), |
|
785 "AllowUntypedDefs": |
|
786 self.allowUntypedDefsCheckBox.isChecked(), |
|
787 "AllowUntypedNested": |
|
788 self.allowUntypedNestedCheckBox.isChecked(), |
|
789 "MypyInitReturn": |
|
790 self.mypyInitReturnCheckBox.isChecked(), |
|
791 "DispatchDecorators": |
|
792 [d.strip() |
|
793 for d in self.dispatchDecoratorEdit.text().split(",")], |
|
794 "OverloadDecorators": |
|
795 [d.strip() |
|
796 for d in self.overloadDecoratorEdit.text().split(",")], |
738 } |
797 } |
|
798 # TODO: add additional AnnotationsChecker parameters |
739 |
799 |
740 securityArgs = { |
800 securityArgs = { |
741 "hardcoded_tmp_directories": [ |
801 "hardcoded_tmp_directories": [ |
742 t.strip() |
802 t.strip() |
743 for t in self.tmpDirectoriesEdit.toPlainText().splitlines() |
803 for t in self.tmpDirectoriesEdit.toPlainText().splitlines() |
801 @return list of checker options |
861 @return list of checker options |
802 @rtype list |
862 @rtype list |
803 """ |
863 """ |
804 options = self.__options[:] |
864 options = self.__options[:] |
805 flags = Utilities.extractFlags(source) |
865 flags = Utilities.extractFlags(source) |
806 if "noqa" in flags and isinstance(flags["noqa"], basestring): |
866 if "noqa" in flags and isinstance(flags["noqa"], str): |
807 excludeMessages = options[0].strip().rstrip(",") |
867 excludeMessages = options[0].strip().rstrip(",") |
808 if excludeMessages: |
868 if excludeMessages: |
809 excludeMessages += "," |
869 excludeMessages += "," |
810 excludeMessages += flags["noqa"] |
870 excludeMessages += flags["noqa"] |
811 options[0] = excludeMessages |
871 options[0] = excludeMessages |
1145 "AnnotationsChecker": { |
1205 "AnnotationsChecker": { |
1146 "MinimumCoverage": |
1206 "MinimumCoverage": |
1147 self.minAnnotationsCoverageSpinBox.value(), |
1207 self.minAnnotationsCoverageSpinBox.value(), |
1148 "MaximumComplexity": |
1208 "MaximumComplexity": |
1149 self.maxAnnotationsComplexitySpinBox.value(), |
1209 self.maxAnnotationsComplexitySpinBox.value(), |
|
1210 "MaximumLength": |
|
1211 self.maxAnnotationsLengthSpinBox.value(), |
|
1212 "SuppressNoneReturning": |
|
1213 self.suppressNoneReturningCheckBox.isChecked(), |
|
1214 "SuppressDummyArgs": |
|
1215 self.suppressDummyArgsCheckBox.isChecked(), |
|
1216 "AllowUntypedDefs": |
|
1217 self.allowUntypedDefsCheckBox.isChecked(), |
|
1218 "AllowUntypedNested": |
|
1219 self.allowUntypedNestedCheckBox.isChecked(), |
|
1220 "MypyInitReturn": |
|
1221 self.mypyInitReturnCheckBox.isChecked(), |
|
1222 "DispatchDecorators": |
|
1223 [d.strip() |
|
1224 for d in self.dispatchDecoratorEdit.text().split(",") |
|
1225 ], |
|
1226 "OverloadDecorators": |
|
1227 [d.strip() |
|
1228 for d in self.overloadDecoratorEdit.text().split(",") |
|
1229 ], |
1150 }, |
1230 }, |
|
1231 # TODO: add additional AnnotationsChecker parameters |
1151 "SecurityChecker": { |
1232 "SecurityChecker": { |
1152 "HardcodedTmpDirectories": [ |
1233 "HardcodedTmpDirectories": [ |
1153 t.strip() |
1234 t.strip() |
1154 for t in self.tmpDirectoriesEdit.toPlainText() |
1235 for t in self.tmpDirectoriesEdit.toPlainText() |
1155 .splitlines() |
1236 .splitlines() |
1432 "PEP8/CommentedCodeWhitelist", |
1513 "PEP8/CommentedCodeWhitelist", |
1433 MiscellaneousCheckerDefaultArgs[ |
1514 MiscellaneousCheckerDefaultArgs[ |
1434 "CommentedCodeChecker"]["WhiteList"] |
1515 "CommentedCodeChecker"]["WhiteList"] |
1435 ) |
1516 ) |
1436 )) |
1517 )) |
|
1518 |
|
1519 # type annotations |
1437 self.minAnnotationsCoverageSpinBox.setValue(int( |
1520 self.minAnnotationsCoverageSpinBox.setValue(int( |
1438 Preferences.Prefs.settings.value( |
1521 Preferences.Prefs.settings.value( |
1439 "PEP8/MinimumAnnotationsCoverage", 75))) |
1522 "PEP8/MinimumAnnotationsCoverage", |
|
1523 AnnotationsCheckerDefaultArgs["MinimumCoverage"]))) |
1440 self.maxAnnotationsComplexitySpinBox.setValue(int( |
1524 self.maxAnnotationsComplexitySpinBox.setValue(int( |
1441 Preferences.Prefs.settings.value( |
1525 Preferences.Prefs.settings.value( |
1442 "PEP8/MaximumAnnotationComplexity", 3))) |
1526 "PEP8/MaximumAnnotationComplexity", |
|
1527 AnnotationsCheckerDefaultArgs["MaximumComplexity"]))) |
|
1528 self.maxAnnotationsLengthSpinBox.setValue(int( |
|
1529 Preferences.Prefs.settings.value( |
|
1530 "PEP8/MaximumAnnotationLength", |
|
1531 AnnotationsCheckerDefaultArgs["MaximumLength"]))) |
|
1532 self.suppressNoneReturningCheckBox.setChecked(Preferences.toBool( |
|
1533 Preferences.Prefs.settings.value( |
|
1534 "PEP8/SuppressNoneReturning", |
|
1535 AnnotationsCheckerDefaultArgs["SuppressNoneReturning"]))) |
|
1536 self.suppressDummyArgsCheckBox.setChecked(Preferences.toBool( |
|
1537 Preferences.Prefs.settings.value( |
|
1538 "PEP8/SuppressDummyArgs", |
|
1539 AnnotationsCheckerDefaultArgs["SuppressDummyArgs"]))) |
|
1540 self.allowUntypedDefsCheckBox.setChecked(Preferences.toBool( |
|
1541 Preferences.Prefs.settings.value( |
|
1542 "PEP8/AllowUntypedDefs", |
|
1543 AnnotationsCheckerDefaultArgs["AllowUntypedDefs"]))) |
|
1544 self.allowUntypedNestedCheckBox.setChecked(Preferences.toBool( |
|
1545 Preferences.Prefs.settings.value( |
|
1546 "PEP8/AllowUntypedNested", |
|
1547 AnnotationsCheckerDefaultArgs["AllowUntypedNested"]))) |
|
1548 self.mypyInitReturnCheckBox.setChecked(Preferences.toBool( |
|
1549 Preferences.Prefs.settings.value( |
|
1550 "PEP8/MypyInitReturn", |
|
1551 AnnotationsCheckerDefaultArgs["MypyInitReturn"]))) |
|
1552 self.dispatchDecoratorEdit.setText(", ".join(Preferences.toList( |
|
1553 Preferences.Prefs.settings.value( |
|
1554 "PEP8/DispatchDecorators", |
|
1555 AnnotationsCheckerDefaultArgs["DispatchDecorators"])))) |
|
1556 self.overloadDecoratorEdit.setText(", ".join(Preferences.toList( |
|
1557 Preferences.Prefs.settings.value( |
|
1558 "PEP8/OverloadDecorators", |
|
1559 AnnotationsCheckerDefaultArgs["OverloadDecorators"])))) |
|
1560 # TODO: add additional AnnotationsChecker parameters |
1443 |
1561 |
1444 # security |
1562 # security |
1445 from .Security.SecurityDefaults import SecurityDefaults |
1563 from .Security.SecurityDefaults import SecurityDefaults |
1446 self.tmpDirectoriesEdit.setPlainText("\n".join( |
1564 self.tmpDirectoriesEdit.setPlainText("\n".join( |
1447 Preferences.toList(Preferences.Prefs.settings.value( |
1565 Preferences.toList(Preferences.Prefs.settings.value( |
1545 Preferences.Prefs.settings.setValue( |
1663 Preferences.Prefs.settings.setValue( |
1546 "PEP8/AggressiveSearch", self.aggressiveCheckBox.isChecked()) |
1664 "PEP8/AggressiveSearch", self.aggressiveCheckBox.isChecked()) |
1547 Preferences.Prefs.settings.setValue( |
1665 Preferences.Prefs.settings.setValue( |
1548 "PEP8/CommentedCodeWhitelist", |
1666 "PEP8/CommentedCodeWhitelist", |
1549 self.__getCommentedCodeCheckerWhiteList()) |
1667 self.__getCommentedCodeCheckerWhiteList()) |
|
1668 |
|
1669 # type annotations |
1550 Preferences.Prefs.settings.setValue( |
1670 Preferences.Prefs.settings.setValue( |
1551 "PEP8/MinimumAnnotationsCoverage", |
1671 "PEP8/MinimumAnnotationsCoverage", |
1552 self.minAnnotationsCoverageSpinBox.value()) |
1672 self.minAnnotationsCoverageSpinBox.value()) |
1553 Preferences.Prefs.settings.setValue( |
1673 Preferences.Prefs.settings.setValue( |
1554 "PEP8/MaximumAnnotationComplexity", |
1674 "PEP8/MaximumAnnotationComplexity", |
1555 self.maxAnnotationsComplexitySpinBox.value()) |
1675 self.maxAnnotationsComplexitySpinBox.value()) |
|
1676 Preferences.Prefs.settings.setValue( |
|
1677 "PEP8/MaximumAnnotationLength", |
|
1678 self.maxAnnotationsLengthSpinBox.value()) |
|
1679 Preferences.Prefs.settings.setValue( |
|
1680 "PEP8/SuppressNoneReturning", |
|
1681 self.suppressNoneReturningCheckBox.isChecked()) |
|
1682 Preferences.Prefs.settings.setValue( |
|
1683 "PEP8/SuppressDummyArgs", |
|
1684 self.suppressDummyArgsCheckBox.isChecked()) |
|
1685 Preferences.Prefs.settings.setValue( |
|
1686 "PEP8/AllowUntypedDefs", |
|
1687 self.allowUntypedDefsCheckBox.isChecked()) |
|
1688 Preferences.Prefs.settings.setValue( |
|
1689 "PEP8/AllowUntypedNested", |
|
1690 self.allowUntypedNestedCheckBox.isChecked()) |
|
1691 Preferences.Prefs.settings.setValue( |
|
1692 "PEP8/MypyInitReturn", |
|
1693 self.mypyInitReturnCheckBox.isChecked()) |
|
1694 Preferences.Prefs.settings.setValue( |
|
1695 "PEP8/DispatchDecorators", |
|
1696 [d.strip() |
|
1697 for d in self.dispatchDecoratorEdit.text().split(",")]) |
|
1698 Preferences.Prefs.settings.setValue( |
|
1699 "PEP8/OverloadDecorators", |
|
1700 [d.strip() |
|
1701 for d in self.overloadDecoratorEdit.text().split(",")]) |
|
1702 # TODO: add additional AnnotationsChecker parameters |
1556 |
1703 |
1557 # security |
1704 # security |
1558 Preferences.Prefs.settings.setValue( |
1705 Preferences.Prefs.settings.setValue( |
1559 "PEP8/HardcodedTmpDirectories", |
1706 "PEP8/HardcodedTmpDirectories", |
1560 [t.strip() |
1707 [t.strip() |
1648 Preferences.Prefs.settings.setValue( |
1795 Preferences.Prefs.settings.setValue( |
1649 "PEP8/CommentedCodeWhitelist", |
1796 "PEP8/CommentedCodeWhitelist", |
1650 MiscellaneousCheckerDefaultArgs[ |
1797 MiscellaneousCheckerDefaultArgs[ |
1651 "CommentedCodeChecker"]["WhiteList"] |
1798 "CommentedCodeChecker"]["WhiteList"] |
1652 ) |
1799 ) |
1653 Preferences.Prefs.settings.setValue( |
1800 |
1654 "PEP8/MinimumAnnotationsCoverage", 75) |
1801 # type annotations |
1655 Preferences.Prefs.settings.setValue( |
1802 Preferences.Prefs.settings.setValue( |
1656 "PEP8/MaximumAnnotationComplexity", 3) |
1803 "PEP8/MinimumAnnotationsCoverage", |
|
1804 AnnotationsCheckerDefaultArgs["MinimumCoverage"]) |
|
1805 Preferences.Prefs.settings.setValue( |
|
1806 "PEP8/MaximumAnnotationComplexity", |
|
1807 AnnotationsCheckerDefaultArgs["MaximumComplexity"]) |
|
1808 Preferences.Prefs.settings.setValue( |
|
1809 "PEP8/MaximumAnnotationLength", |
|
1810 AnnotationsCheckerDefaultArgs["MaximumLength"]) |
|
1811 Preferences.Prefs.settings.setValue( |
|
1812 "PEP8/SuppressNoneReturning", |
|
1813 AnnotationsCheckerDefaultArgs["SuppressNoneReturning"]) |
|
1814 Preferences.Prefs.settings.setValue( |
|
1815 "PEP8/SuppressDummyArgs", |
|
1816 AnnotationsCheckerDefaultArgs["SuppressDummyArgs"]) |
|
1817 Preferences.Prefs.settings.setValue( |
|
1818 "PEP8/AllowUntypedDefs", |
|
1819 AnnotationsCheckerDefaultArgs["AllowUntypedDefs"]) |
|
1820 Preferences.Prefs.settings.setValue( |
|
1821 "PEP8/AllowUntypedNested", |
|
1822 AnnotationsCheckerDefaultArgs["AllowUntypedNested"]) |
|
1823 Preferences.Prefs.settings.setValue( |
|
1824 "PEP8/MypyInitReturn", |
|
1825 AnnotationsCheckerDefaultArgs["MypyInitReturn"]) |
|
1826 Preferences.Prefs.settings.setValue( |
|
1827 "PEP8/DispatchDecorators", |
|
1828 AnnotationsCheckerDefaultArgs["DispatchDecorators"]) |
|
1829 Preferences.Prefs.settings.setValue( |
|
1830 "PEP8/OverloadDecorators", |
|
1831 AnnotationsCheckerDefaultArgs["OverloadDecorators"]) |
|
1832 # TODO: add additional AnnotationsChecker parameters |
1657 |
1833 |
1658 # security |
1834 # security |
1659 from .Security.SecurityDefaults import SecurityDefaults |
1835 from .Security.SecurityDefaults import SecurityDefaults |
1660 Preferences.Prefs.settings.setValue( |
1836 Preferences.Prefs.settings.setValue( |
1661 "PEP8/HardcodedTmpDirectories", |
1837 "PEP8/HardcodedTmpDirectories", |