658 newText = self.__source[line].rstrip() + "." + self.__eol |
673 newText = self.__source[line].rstrip() + "." + self.__eol |
659 |
674 |
660 if newText: |
675 if newText: |
661 self.__source[line] = newText |
676 self.__source[line] = newText |
662 # Period added to summary line. |
677 # Period added to summary line. |
663 return (1, "FIXD131", 0) |
678 return (1, "FIXD131", [], 0) |
664 else: |
679 else: |
665 return (0, "", 0) |
680 return (0, "", [], 0) |
666 |
681 |
667 def __fixD141(self, code, line, pos, apply=False): |
682 def __fixD141(self, code, line, pos, apply=False): |
668 """ |
683 """ |
669 Private method to fix a function/method docstring preceded by a |
684 Private method to fix a function/method docstring preceded by a |
670 blank line. |
685 blank line. |
671 |
686 |
672 Codes: D141 |
687 Codes: D141 |
673 |
688 |
674 @param code code of the issue (string) |
689 @param code code of the issue |
675 @param line line number of the issue (integer) |
690 @type str |
676 @param pos position inside line (integer) |
691 @param line line number of the issue |
677 @keyparam apply flag indicating, that the fix should be applied |
692 @type int |
678 (boolean) |
693 @param pos position inside line |
679 @return value indicating an applied/deferred fix (-1, 0, 1), |
694 @type int |
680 a message for the fix (string) and an ID for a deferred |
695 @param apply flag indicating, that the fix should be applied |
681 fix (integer) |
696 @type bool |
|
697 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
698 a message code for the fix, a list of arguments for the |
|
699 message and an ID for a deferred fix |
|
700 @rtype tuple of (int, str, list or int, int) |
682 """ |
701 """ |
683 if apply: |
702 if apply: |
684 line = line - 1 |
703 line = line - 1 |
685 self.__source[line - 1] = "" |
704 self.__source[line - 1] = "" |
686 # Blank line before function/method docstring removed. |
705 # Blank line before function/method docstring removed. |
687 return (1, "FIXD141", 0) |
706 return (1, "FIXD141", [], 0) |
688 else: |
707 else: |
689 fixId = self.__getID() |
708 fixId = self.__getID() |
690 self.__stack.append((fixId, code, line, pos)) |
709 self.__stack.append((fixId, code, line, pos)) |
691 return (-1, "", fixId) |
710 return (-1, "", [], fixId) |
692 |
711 |
693 def __fixD142(self, code, line, pos, apply=False): |
712 def __fixD142(self, code, line, pos, apply=False): |
694 """ |
713 """ |
695 Private method to fix a class docstring not preceded by a |
714 Private method to fix a class docstring not preceded by a |
696 blank line. |
715 blank line. |
697 |
716 |
698 Codes: D142 |
717 Codes: D142 |
699 |
718 |
700 @param code code of the issue (string) |
719 @param code code of the issue |
701 @param line line number of the issue (integer) |
720 @type str |
702 @param pos position inside line (integer) |
721 @param line line number of the issue |
703 @keyparam apply flag indicating, that the fix should be applied |
722 @type int |
704 (boolean) |
723 @param pos position inside line |
705 @return value indicating an applied/deferred fix (-1, 0, 1), |
724 @type int |
706 a message for the fix (string) and an ID for a deferred |
725 @param apply flag indicating, that the fix should be applied |
707 fix (integer) |
726 @type bool |
|
727 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
728 a message code for the fix, a list of arguments for the |
|
729 message and an ID for a deferred fix |
|
730 @rtype tuple of (int, str, list or int, int) |
708 """ |
731 """ |
709 if apply: |
732 if apply: |
710 line = line - 1 |
733 line = line - 1 |
711 self.__source[line] = self.__eol + self.__source[line] |
734 self.__source[line] = self.__eol + self.__source[line] |
712 # Blank line inserted before class docstring. |
735 # Blank line inserted before class docstring. |
713 return (1, "FIXD142", 0) |
736 return (1, "FIXD142", [], 0) |
714 else: |
737 else: |
715 fixId = self.__getID() |
738 fixId = self.__getID() |
716 self.__stack.append((fixId, code, line, pos)) |
739 self.__stack.append((fixId, code, line, pos)) |
717 return (-1, "", fixId) |
740 return (-1, "", [], fixId) |
718 |
741 |
719 def __fixD143(self, code, line, pos, apply=False): |
742 def __fixD143(self, code, line, pos, apply=False): |
720 """ |
743 """ |
721 Private method to fix a class docstring not followed by a |
744 Private method to fix a class docstring not followed by a |
722 blank line. |
745 blank line. |
723 |
746 |
724 Codes: D143 |
747 Codes: D143 |
725 |
748 |
726 @param code code of the issue (string) |
749 @param code code of the issue |
727 @param line line number of the issue (integer) |
750 @type str |
728 @param pos position inside line (integer) |
751 @param line line number of the issue |
729 @keyparam apply flag indicating, that the fix should be applied |
752 @type int |
730 (boolean) |
753 @param pos position inside line |
731 @return value indicating an applied/deferred fix (-1, 0, 1), |
754 @type int |
732 a message for the fix (string) and an ID for a deferred |
755 @param apply flag indicating, that the fix should be applied |
733 fix (integer) |
756 @type bool |
|
757 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
758 a message code for the fix, a list of arguments for the |
|
759 message and an ID for a deferred fix |
|
760 @rtype tuple of (int, str, list or int, int) |
734 """ |
761 """ |
735 if apply: |
762 if apply: |
736 line = line - 1 |
763 line = line - 1 |
737 self.__source[line] += self.__eol |
764 self.__source[line] += self.__eol |
738 # Blank line inserted after class docstring. |
765 # Blank line inserted after class docstring. |
739 return (1, "FIXD143", 0) |
766 return (1, "FIXD143", [], 0) |
740 else: |
767 else: |
741 fixId = self.__getID() |
768 fixId = self.__getID() |
742 self.__stack.append((fixId, code, line, pos)) |
769 self.__stack.append((fixId, code, line, pos)) |
743 return (-1, "", fixId) |
770 return (-1, "", [], fixId) |
744 |
771 |
745 def __fixD144(self, code, line, pos, apply=False): |
772 def __fixD144(self, code, line, pos, apply=False): |
746 """ |
773 """ |
747 Private method to fix a docstring summary not followed by a |
774 Private method to fix a docstring summary not followed by a |
748 blank line. |
775 blank line. |
749 |
776 |
750 Codes: D144 |
777 Codes: D144 |
751 |
778 |
752 @param code code of the issue (string) |
779 @param code code of the issue |
753 @param line line number of the issue (integer) |
780 @type str |
754 @param pos position inside line (integer) |
781 @param line line number of the issue |
755 @keyparam apply flag indicating, that the fix should be applied |
782 @type int |
756 (boolean) |
783 @param pos position inside line |
757 @return value indicating an applied/deferred fix (-1, 0, 1), |
784 @type int |
758 a message for the fix (string) and an ID for a deferred |
785 @param apply flag indicating, that the fix should be applied |
759 fix (integer) |
786 @type bool |
|
787 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
788 a message code for the fix, a list of arguments for the |
|
789 message and an ID for a deferred fix |
|
790 @rtype tuple of (int, str, list or int, int) |
760 """ |
791 """ |
761 if apply: |
792 if apply: |
762 line = line - 1 |
793 line = line - 1 |
763 if not self.__source[line].rstrip().endswith("."): |
794 if not self.__source[line].rstrip().endswith("."): |
764 # only correct summary lines can be fixed here |
795 # only correct summary lines can be fixed here |
765 return (0, "", 0) |
796 return (0, "", 0) |
766 |
797 |
767 self.__source[line] += self.__eol |
798 self.__source[line] += self.__eol |
768 # Blank line inserted after docstring summary. |
799 # Blank line inserted after docstring summary. |
769 return (1, "FIXD144", 0) |
800 return (1, "FIXD144", [], 0) |
770 else: |
801 else: |
771 fixId = self.__getID() |
802 fixId = self.__getID() |
772 self.__stack.append((fixId, code, line, pos)) |
803 self.__stack.append((fixId, code, line, pos)) |
773 return (-1, "", fixId) |
804 return (-1, "", [], fixId) |
774 |
805 |
775 def __fixD145(self, code, line, pos, apply=False): |
806 def __fixD145(self, code, line, pos, apply=False): |
776 """ |
807 """ |
777 Private method to fix the last paragraph of a multi-line docstring |
808 Private method to fix the last paragraph of a multi-line docstring |
778 not followed by a blank line. |
809 not followed by a blank line. |
779 |
810 |
780 Codes: D143 |
811 Codes: D143 |
781 |
812 |
782 @param code code of the issue (string) |
813 @param code code of the issue |
783 @param line line number of the issue (integer) |
814 @type str |
784 @param pos position inside line (integer) |
815 @param line line number of the issue |
785 @keyparam apply flag indicating, that the fix should be applied |
816 @type int |
786 (boolean) |
817 @param pos position inside line |
787 @return value indicating an applied/deferred fix (-1, 0, 1), |
818 @type int |
788 a message for the fix (string) and an ID for a deferred |
819 @param apply flag indicating, that the fix should be applied |
789 fix (integer) |
820 @type bool |
|
821 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
822 a message code for the fix, a list of arguments for the |
|
823 message and an ID for a deferred fix |
|
824 @rtype tuple of (int, str, list or int, int) |
790 """ |
825 """ |
791 if apply: |
826 if apply: |
792 line = line - 1 |
827 line = line - 1 |
793 self.__source[line] = self.__eol + self.__source[line] |
828 self.__source[line] = self.__eol + self.__source[line] |
794 # Blank line inserted after last paragraph of docstring. |
829 # Blank line inserted after last paragraph of docstring. |
795 return (1, "FIXD145", 0) |
830 return (1, "FIXD145", [], 0) |
796 else: |
831 else: |
797 fixId = self.__getID() |
832 fixId = self.__getID() |
798 self.__stack.append((fixId, code, line, pos)) |
833 self.__stack.append((fixId, code, line, pos)) |
799 return (-1, "", fixId) |
834 return (-1, "", [], fixId) |
800 |
835 |
801 def __fixD221(self, code, line, pos, apply=False): |
836 def __fixD221(self, code, line, pos, apply=False): |
802 """ |
837 """ |
803 Private method to fix leading and trailing quotes of docstring |
838 Private method to fix leading and trailing quotes of docstring |
804 not on separate lines. |
839 not on separate lines. |
805 |
840 |
806 Codes: D221, D222 |
841 Codes: D221, D222 |
807 |
842 |
808 @param code code of the issue (string) |
843 @param code code of the issue |
809 @param line line number of the issue (integer) |
844 @type str |
810 @param pos position inside line (integer) |
845 @param line line number of the issue |
811 @keyparam apply flag indicating, that the fix should be applied |
846 @type int |
812 (boolean) |
847 @param pos position inside line |
813 @return value indicating an applied/deferred fix (-1, 0, 1), |
848 @type int |
814 a message for the fix (string) and an ID for a deferred |
849 @param apply flag indicating, that the fix should be applied |
815 fix (integer) |
850 @type bool |
|
851 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
852 a message code for the fix, a list of arguments for the |
|
853 message and an ID for a deferred fix |
|
854 @rtype tuple of (int, str, list or int, int) |
816 """ |
855 """ |
817 if apply: |
856 if apply: |
818 line = line - 1 |
857 line = line - 1 |
819 indent = self.__getIndent(self.__source[line]) |
858 indent = self.__getIndent(self.__source[line]) |
820 source = self.__source[line].strip() |
859 source = self.__source[line].strip() |
840 # Leading quotes put on separate line. |
879 # Leading quotes put on separate line. |
841 msg = "FIXD221" |
880 msg = "FIXD221" |
842 else: |
881 else: |
843 # Trailing quotes put on separate line. |
882 # Trailing quotes put on separate line. |
844 msg = "FIXD222" |
883 msg = "FIXD222" |
845 return (1, msg, 0) |
884 return (1, msg, [], 0) |
846 else: |
885 else: |
847 fixId = self.__getID() |
886 fixId = self.__getID() |
848 self.__stack.append((fixId, code, line, pos)) |
887 self.__stack.append((fixId, code, line, pos)) |
849 return (-1, "", fixId) |
888 return (-1, "", [], fixId) |
850 |
889 |
851 def __fixD242(self, code, line, pos, apply=False): |
890 def __fixD242(self, code, line, pos, apply=False): |
852 """ |
891 """ |
853 Private method to fix a class or function/method docstring preceded |
892 Private method to fix a class or function/method docstring preceded |
854 by a blank line. |
893 by a blank line. |
855 |
894 |
856 Codes: D242, D244 |
895 Codes: D242, D244 |
857 |
896 |
858 @param code code of the issue (string) |
897 @param code code of the issue |
859 @param line line number of the issue (integer) |
898 @type str |
860 @param pos position inside line (integer) |
899 @param line line number of the issue |
861 @keyparam apply flag indicating, that the fix should be applied |
900 @type int |
862 (boolean) |
901 @param pos position inside line |
863 @return value indicating an applied/deferred fix (-1, 0, 1), |
902 @type int |
864 a message for the fix (string) and an ID for a deferred |
903 @param apply flag indicating, that the fix should be applied |
865 fix (integer) |
904 @type bool |
|
905 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
906 a message code for the fix, a list of arguments for the |
|
907 message and an ID for a deferred fix |
|
908 @rtype tuple of (int, str, list or int, int) |
866 """ |
909 """ |
867 if apply: |
910 if apply: |
868 line = line - 1 |
911 line = line - 1 |
869 self.__source[line - 1] = "" |
912 self.__source[line - 1] = "" |
870 if code == "D242": |
913 if code == "D242": |
871 # Blank line before class docstring removed. |
914 # Blank line before class docstring removed. |
872 msg = "FIXD242" |
915 msg = "FIXD242" |
873 else: |
916 else: |
874 # Blank line before function/method docstring removed. |
917 # Blank line before function/method docstring removed. |
875 msg = "FIXD244" |
918 msg = "FIXD244" |
876 return (1, msg, 0) |
919 return (1, msg, [], 0) |
877 else: |
920 else: |
878 fixId = self.__getID() |
921 fixId = self.__getID() |
879 self.__stack.append((fixId, code, line, pos)) |
922 self.__stack.append((fixId, code, line, pos)) |
880 return (-1, "", fixId) |
923 return (-1, "", [], fixId) |
881 |
924 |
882 def __fixD243(self, code, line, pos, apply=False): |
925 def __fixD243(self, code, line, pos, apply=False): |
883 """ |
926 """ |
884 Private method to fix a class or function/method docstring followed |
927 Private method to fix a class or function/method docstring followed |
885 by a blank line. |
928 by a blank line. |
886 |
929 |
887 Codes: D243, D245 |
930 Codes: D243, D245 |
888 |
931 |
889 @param code code of the issue (string) |
932 @param code code of the issue |
890 @param line line number of the issue (integer) |
933 @type str |
891 @param pos position inside line (integer) |
934 @param line line number of the issue |
892 @keyparam apply flag indicating, that the fix should be applied |
935 @type int |
893 (boolean) |
936 @param pos position inside line |
894 @return value indicating an applied/deferred fix (-1, 0, 1), |
937 @type int |
895 a message for the fix (string) and an ID for a deferred |
938 @param apply flag indicating, that the fix should be applied |
896 fix (integer) |
939 @type bool |
|
940 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
941 a message code for the fix, a list of arguments for the |
|
942 message and an ID for a deferred fix |
|
943 @rtype tuple of (int, str, list or int, int) |
897 """ |
944 """ |
898 if apply: |
945 if apply: |
899 line = line - 1 |
946 line = line - 1 |
900 self.__source[line + 1] = "" |
947 self.__source[line + 1] = "" |
901 if code == "D243": |
948 if code == "D243": |
902 # Blank line after class docstring removed. |
949 # Blank line after class docstring removed. |
903 msg = "FIXD243" |
950 msg = "FIXD243" |
904 else: |
951 else: |
905 # Blank line after function/method docstring removed. |
952 # Blank line after function/method docstring removed. |
906 msg = "FIXD245" |
953 msg = "FIXD245" |
907 return (1, msg, 0) |
954 return (1, msg, [], 0) |
908 else: |
955 else: |
909 fixId = self.__getID() |
956 fixId = self.__getID() |
910 self.__stack.append((fixId, code, line, pos)) |
957 self.__stack.append((fixId, code, line, pos)) |
911 return (-1, "", fixId) |
958 return (-1, "", [], fixId) |
912 |
959 |
913 def __fixD247(self, code, line, pos, apply=False): |
960 def __fixD247(self, code, line, pos, apply=False): |
914 """ |
961 """ |
915 Private method to fix a last paragraph of a docstring followed |
962 Private method to fix a last paragraph of a docstring followed |
916 by a blank line. |
963 by a blank line. |
917 |
964 |
918 Codes: D247 |
965 Codes: D247 |
919 |
966 |
920 @param code code of the issue (string) |
967 @param code code of the issue |
921 @param line line number of the issue (integer) |
968 @type str |
922 @param pos position inside line (integer) |
969 @param line line number of the issue |
923 @keyparam apply flag indicating, that the fix should be applied |
970 @type int |
924 (boolean) |
971 @param pos position inside line |
925 @return value indicating an applied/deferred fix (-1, 0, 1), |
972 @type int |
926 a message for the fix (string) and an ID for a deferred |
973 @param apply flag indicating, that the fix should be applied |
927 fix (integer) |
974 @type bool |
|
975 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
976 a message code for the fix, a list of arguments for the |
|
977 message and an ID for a deferred fix |
|
978 @rtype tuple of (int, str, list or int, int) |
928 """ |
979 """ |
929 if apply: |
980 if apply: |
930 line = line - 1 |
981 line = line - 1 |
931 self.__source[line - 1] = "" |
982 self.__source[line - 1] = "" |
932 # Blank line after last paragraph removed. |
983 # Blank line after last paragraph removed. |
933 return (1, "FIXD247", 0) |
984 return (1, "FIXD247", [], 0) |
934 else: |
985 else: |
935 fixId = self.__getID() |
986 fixId = self.__getID() |
936 self.__stack.append((fixId, code, line, pos)) |
987 self.__stack.append((fixId, code, line, pos)) |
937 return (-1, "", fixId) |
988 return (-1, "", [], fixId) |
938 |
989 |
939 def __fixE101(self, code, line, pos): |
990 def __fixE101(self, code, line, pos): |
940 """ |
991 """ |
941 Private method to fix obsolete tab usage and indentation errors. |
992 Private method to fix obsolete tab usage and indentation errors. |
942 |
993 |
943 Codes: E101, E111, W191 |
994 Codes: E101, E111, W191 |
944 |
995 |
945 @param code code of the issue (string) |
996 @param code code of the issue |
946 @param line line number of the issue (integer) |
997 @type str |
947 @param pos position inside line (integer) |
998 @param line line number of the issue |
948 @return value indicating an applied/deferred fix (-1, 0, 1), |
999 @type int |
949 a message for the fix (string) and an ID for a deferred |
1000 @param pos position inside line |
950 fix (integer) |
1001 @type int |
|
1002 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1003 a message code for the fix, a list of arguments for the |
|
1004 message and an ID for a deferred fix |
|
1005 @rtype tuple of (int, str, list or int, int) |
951 """ |
1006 """ |
952 if self.__reindenter is None: |
1007 if self.__reindenter is None: |
953 self.__reindenter = Reindenter(self.__source) |
1008 self.__reindenter = Reindenter(self.__source) |
954 self.__reindenter.run() |
1009 self.__reindenter.run() |
955 fixedLine = self.__reindenter.fixedLine(line - 1) |
1010 fixedLine = self.__reindenter.fixedLine(line - 1) |
1202 else: |
1281 else: |
1203 self.__source[row] = newText |
1282 self.__source[row] = newText |
1204 changed = True |
1283 changed = True |
1205 if changed: |
1284 if changed: |
1206 # Visual indentation corrected. |
1285 # Visual indentation corrected. |
1207 return (1, "FIXE127", 0) |
1286 return (1, "FIXE127", [], 0) |
1208 return (0, "", 0) |
1287 return (0, "", [], 0) |
1209 else: |
1288 else: |
1210 fixId = self.__getID() |
1289 fixId = self.__getID() |
1211 self.__stackLogical.append((fixId, code, line, pos)) |
1290 self.__stackLogical.append((fixId, code, line, pos)) |
1212 return (-1, "", fixId) |
1291 return (-1, "", [], fixId) |
1213 |
1292 |
1214 def __fixE201(self, code, line, pos): |
1293 def __fixE201(self, code, line, pos): |
1215 """ |
1294 """ |
1216 Private method to fix extraneous whitespace. |
1295 Private method to fix extraneous whitespace. |
1217 |
1296 |
1218 Codes: E201, E202, E203, E211 |
1297 Codes: E201, E202, E203, E211 |
1219 |
1298 |
1220 @param code code of the issue (string) |
1299 @param code code of the issue |
1221 @param line line number of the issue (integer) |
1300 @type str |
1222 @param pos position inside line (integer) |
1301 @param line line number of the issue |
1223 @return value indicating an applied/deferred fix (-1, 0, 1), |
1302 @type int |
1224 a message for the fix (string) and an ID for a deferred |
1303 @param pos position inside line |
1225 fix (integer) |
1304 @type int |
|
1305 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1306 a message code for the fix, a list of arguments for the |
|
1307 message and an ID for a deferred fix |
|
1308 @rtype tuple of (int, str, list or int, int) |
1226 """ |
1309 """ |
1227 line = line - 1 |
1310 line = line - 1 |
1228 text = self.__source[line] |
1311 text = self.__source[line] |
1229 |
1312 |
1230 if '"""' in text or "'''" in text or text.rstrip().endswith('\\'): |
1313 if '"""' in text or "'''" in text or text.rstrip().endswith('\\'): |
1231 return (0, "", 0) |
1314 return (0, "", [], 0) |
1232 |
1315 |
1233 newText = self.__fixWhitespace(text, pos, '') |
1316 newText = self.__fixWhitespace(text, pos, '') |
1234 if newText == text: |
1317 if newText == text: |
1235 return (0, "", 0) |
1318 return (0, "", [], 0) |
1236 |
1319 |
1237 self.__source[line] = newText |
1320 self.__source[line] = newText |
1238 # Extraneous whitespace removed. |
1321 # Extraneous whitespace removed. |
1239 return (1, "FIXE201", 0) |
1322 return (1, "FIXE201", [], 0) |
1240 |
1323 |
1241 def __fixE221(self, code, line, pos): |
1324 def __fixE221(self, code, line, pos): |
1242 """ |
1325 """ |
1243 Private method to fix extraneous whitespace around operator or |
1326 Private method to fix extraneous whitespace around operator or |
1244 keyword. |
1327 keyword. |
1245 |
1328 |
1246 Codes: E221, E222, E223, E224, E241, E242, E271, E272, E273, E274 |
1329 Codes: E221, E222, E223, E224, E241, E242, E271, E272, E273, E274 |
1247 |
1330 |
1248 @param code code of the issue (string) |
1331 @param code code of the issue |
1249 @param line line number of the issue (integer) |
1332 @type str |
1250 @param pos position inside line (integer) |
1333 @param line line number of the issue |
1251 @return value indicating an applied/deferred fix (-1, 0, 1), |
1334 @type int |
1252 a message for the fix (string) and an ID for a deferred |
1335 @param pos position inside line |
1253 fix (integer) |
1336 @type int |
|
1337 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1338 a message code for the fix, a list of arguments for the |
|
1339 message and an ID for a deferred fix |
|
1340 @rtype tuple of (int, str, list or int, int) |
1254 """ |
1341 """ |
1255 line = line - 1 |
1342 line = line - 1 |
1256 text = self.__source[line] |
1343 text = self.__source[line] |
1257 |
1344 |
1258 if '"""' in text or "'''" in text or text.rstrip().endswith('\\'): |
1345 if '"""' in text or "'''" in text or text.rstrip().endswith('\\'): |
1259 return (0, "", 0) |
1346 return (0, "", [], 0) |
1260 |
1347 |
1261 newText = self.__fixWhitespace(text, pos, ' ') |
1348 newText = self.__fixWhitespace(text, pos, ' ') |
1262 if newText == text: |
1349 if newText == text: |
1263 return (0, "", 0) |
1350 return (0, "", [], 0) |
1264 |
1351 |
1265 self.__source[line] = newText |
1352 self.__source[line] = newText |
1266 return (1, "FIXE221", 0) |
1353 return (1, "FIXE221", [], 0) |
1267 |
1354 |
1268 def __fixE225(self, code, line, pos): |
1355 def __fixE225(self, code, line, pos): |
1269 """ |
1356 """ |
1270 Private method to fix extraneous whitespaces around operator. |
1357 Private method to fix extraneous whitespaces around operator. |
1271 |
1358 |
1272 Codes: E225, E226, E227, E228 |
1359 Codes: E225, E226, E227, E228 |
1273 |
1360 |
1274 @param code code of the issue (string) |
1361 @param code code of the issue |
1275 @param line line number of the issue (integer) |
1362 @type str |
1276 @param pos position inside line (integer) |
1363 @param line line number of the issue |
1277 @return value indicating an applied/deferred fix (-1, 0, 1), |
1364 @type int |
1278 a message for the fix (string) and an ID for a deferred |
1365 @param pos position inside line |
1279 fix (integer) |
1366 @type int |
|
1367 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1368 a message code for the fix, a list of arguments for the |
|
1369 message and an ID for a deferred fix |
|
1370 @rtype tuple of (int, str, list or int, int) |
1280 """ |
1371 """ |
1281 line = line - 1 |
1372 line = line - 1 |
1282 text = self.__source[line] |
1373 text = self.__source[line] |
1283 |
1374 |
1284 if '"""' in text or "'''" in text or text.rstrip().endswith('\\'): |
1375 if '"""' in text or "'''" in text or text.rstrip().endswith('\\'): |
1285 return (0, "", 0) |
1376 return (0, "", [], 0) |
1286 |
1377 |
1287 newText = text |
1378 newText = text |
1288 # determine length of operator |
1379 # determine length of operator |
1289 tokens = '<>*/=^&|%!+-' |
1380 tokens = '<>*/=^&|%!+-' |
1290 pos2 = pos |
1381 pos2 = pos |
1298 break |
1389 break |
1299 if pos2 < len(text) and text[pos2] not in ' \t': |
1390 if pos2 < len(text) and text[pos2] not in ' \t': |
1300 newText = self.__fixWhitespace(newText, pos2, ' ') |
1391 newText = self.__fixWhitespace(newText, pos2, ' ') |
1301 newText = self.__fixWhitespace(newText, pos, ' ') |
1392 newText = self.__fixWhitespace(newText, pos, ' ') |
1302 if newText == text: |
1393 if newText == text: |
1303 return (0, "", 0) |
1394 return (0, "", [], 0) |
1304 |
1395 |
1305 self.__source[line] = newText |
1396 self.__source[line] = newText |
1306 # Missing whitespaces added. |
1397 # Missing whitespaces added. |
1307 return (1, "FIXE225", 0) |
1398 return (1, "FIXE225", [], 0) |
1308 |
1399 |
1309 def __fixE231(self, code, line, pos): |
1400 def __fixE231(self, code, line, pos): |
1310 """ |
1401 """ |
1311 Private method to fix missing whitespace after ',;:'. |
1402 Private method to fix missing whitespace after ',;:'. |
1312 |
1403 |
1313 Codes: E231 |
1404 Codes: E231 |
1314 |
1405 |
1315 @param code code of the issue (string) |
1406 @param code code of the issue |
1316 @param line line number of the issue (integer) |
1407 @type str |
1317 @param pos position inside line (integer) |
1408 @param line line number of the issue |
1318 @return value indicating an applied/deferred fix (-1, 0, 1), |
1409 @type int |
1319 a message for the fix (string) and an ID for a deferred |
1410 @param pos position inside line |
1320 fix (integer) |
1411 @type int |
|
1412 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1413 a message code for the fix, a list of arguments for the |
|
1414 message and an ID for a deferred fix |
|
1415 @rtype tuple of (int, str, list or int, int) |
1321 """ |
1416 """ |
1322 line = line - 1 |
1417 line = line - 1 |
1323 pos = pos + 1 |
1418 pos = pos + 1 |
1324 self.__source[line] = ( |
1419 self.__source[line] = ( |
1325 self.__source[line][:pos] + |
1420 self.__source[line][:pos] + |
1326 " " + |
1421 " " + |
1327 self.__source[line][pos:] |
1422 self.__source[line][pos:] |
1328 ) |
1423 ) |
1329 # Missing whitespace added. |
1424 # Missing whitespace added. |
1330 return (1, "FIXE231", 0) |
1425 return (1, "FIXE231", [], 0) |
1331 |
1426 |
1332 def __fixE251(self, code, line, pos): |
1427 def __fixE251(self, code, line, pos): |
1333 """ |
1428 """ |
1334 Private method to fix extraneous whitespace around keyword and |
1429 Private method to fix extraneous whitespace around keyword and |
1335 default parameter equals. |
1430 default parameter equals. |
1336 |
1431 |
1337 Codes: E251 |
1432 Codes: E251 |
1338 |
1433 |
1339 @param code code of the issue (string) |
1434 @param code code of the issue |
1340 @param line line number of the issue (integer) |
1435 @type str |
1341 @param pos position inside line (integer) |
1436 @param line line number of the issue |
1342 @return value indicating an applied/deferred fix (-1, 0, 1), |
1437 @type int |
1343 a message for the fix (string) and an ID for a deferred |
1438 @param pos position inside line |
1344 fix (integer) |
1439 @type int |
|
1440 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1441 a message code for the fix, a list of arguments for the |
|
1442 message and an ID for a deferred fix |
|
1443 @rtype tuple of (int, str, list or int, int) |
1345 """ |
1444 """ |
1346 line = line - 1 |
1445 line = line - 1 |
1347 text = self.__source[line] |
1446 text = self.__source[line] |
1348 |
1447 |
1349 # This is necessary since pycodestyle sometimes reports columns that |
1448 # This is necessary since pycodestyle sometimes reports columns that |
1360 self.__source[line] = newText.rstrip("\n\r \t\\") |
1459 self.__source[line] = newText.rstrip("\n\r \t\\") |
1361 self.__source[line + 1] = self.__source[line + 1].lstrip() |
1460 self.__source[line + 1] = self.__source[line + 1].lstrip() |
1362 else: |
1461 else: |
1363 self.__source[line] = newText |
1462 self.__source[line] = newText |
1364 # Extraneous whitespace removed. |
1463 # Extraneous whitespace removed. |
1365 return (1, "FIXE251", 0) |
1464 return (1, "FIXE251", [], 0) |
1366 |
1465 |
1367 def __fixE261(self, code, line, pos): |
1466 def __fixE261(self, code, line, pos): |
1368 """ |
1467 """ |
1369 Private method to fix whitespace before or after inline comment. |
1468 Private method to fix whitespace before or after inline comment. |
1370 |
1469 |
1371 Codes: E261, E262 |
1470 Codes: E261, E262 |
1372 |
1471 |
1373 @param code code of the issue (string) |
1472 @param code code of the issue |
1374 @param line line number of the issue (integer) |
1473 @type str |
1375 @param pos position inside line (integer) |
1474 @param line line number of the issue |
1376 @return value indicating an applied/deferred fix (-1, 0, 1), |
1475 @type int |
1377 a message for the fix (string) and an ID for a deferred |
1476 @param pos position inside line |
1378 fix (integer) |
1477 @type int |
|
1478 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1479 a message code for the fix, a list of arguments for the |
|
1480 message and an ID for a deferred fix |
|
1481 @rtype tuple of (int, str, list or int, int) |
1379 """ |
1482 """ |
1380 line = line - 1 |
1483 line = line - 1 |
1381 text = self.__source[line] |
1484 text = self.__source[line] |
1382 left = text[:pos].rstrip(' \t#') |
1485 left = text[:pos].rstrip(' \t#') |
1383 right = text[pos:].lstrip(' \t#') |
1486 right = text[pos:].lstrip(' \t#') |
1384 newText = left + (" # " + right if right.strip() else right) |
1487 newText = left + (" # " + right if right.strip() else right) |
1385 self.__source[line] = newText |
1488 self.__source[line] = newText |
1386 # Whitespace around comment sign corrected. |
1489 # Whitespace around comment sign corrected. |
1387 return (1, "FIXE261", 0) |
1490 return (1, "FIXE261", [], 0) |
1388 |
1491 |
1389 def __fixBlankLinesBefore(self, code, line, pos, apply=False): |
1492 def __fixBlankLinesBefore(self, code, line, pos, apply=False): |
1390 """ |
1493 """ |
1391 Private method to fix the need for blank lines before class, function |
1494 Private method to fix the need for blank lines before class, function |
1392 and method definitions. |
1495 and method definitions. |
1393 |
1496 |
1394 Codes: E301, E302, E303, E305, E306, E307, E308 |
1497 Codes: E301, E302, E303, E305, E306, E307, E308 |
1395 |
1498 |
1396 @param code code of the issue (string) |
1499 @param code code of the issue |
1397 @param line line number of the issue (integer) |
1500 @type str |
1398 @param pos position inside line (integer) |
1501 @param line line number of the issue |
1399 @keyparam apply flag indicating, that the fix should be applied |
1502 @type int |
1400 (boolean) |
1503 @param pos position inside line |
1401 @return value indicating an applied/deferred fix (-1, 0, 1), |
1504 @type int |
1402 a message for the fix (string) and an ID for a deferred |
1505 @param apply flag indicating, that the fix should be applied |
1403 fix (integer) |
1506 @type bool |
|
1507 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1508 a message code for the fix, a list of arguments for the |
|
1509 message and an ID for a deferred fix |
|
1510 @rtype tuple of (int, str, list or int, int) |
1404 """ |
1511 """ |
1405 if apply: |
1512 if apply: |
1406 if code in ["E301", "E306", "E307"]: |
1513 if code in ["E301", "E306", "E307"]: |
1407 blankLinesBefore = self.__blankLines["method"] |
1514 blankLinesBefore = self.__blankLines["method"] |
1408 elif code == "E308": |
1515 elif code == "E308": |
1426 # insert blank lines (one or two) |
1533 # insert blank lines (one or two) |
1427 while delta < 0: |
1534 while delta < 0: |
1428 self.__source.insert(line, self.__eol) |
1535 self.__source.insert(line, self.__eol) |
1429 delta += 1 |
1536 delta += 1 |
1430 # %n blank line(s) inserted. |
1537 # %n blank line(s) inserted. |
1431 return (1, ("FIXE302+", blankLinesBefore - blanks), 0) |
1538 return (1, "FIXE302+", blankLinesBefore - blanks, 0) |
1432 elif delta > 0: |
1539 elif delta > 0: |
1433 # delete superfluous blank lines |
1540 # delete superfluous blank lines |
1434 while delta > 0: |
1541 while delta > 0: |
1435 del self.__source[line - 1] |
1542 del self.__source[line - 1] |
1436 line -= 1 |
1543 line -= 1 |
1437 delta -= 1 |
1544 delta -= 1 |
1438 # %n superfluous line(s) removed. |
1545 # %n superfluous line(s) removed. |
1439 return (1, ("FIXE302-", blanks - blankLinesBefore), 0) |
1546 return (1, "FIXE302-", blanks - blankLinesBefore, 0) |
1440 else: |
1547 else: |
1441 return (0, "", 0) |
1548 return (0, "", [], 0) |
1442 else: |
1549 else: |
1443 fixId = self.__getID() |
1550 fixId = self.__getID() |
1444 self.__stack.append((fixId, code, line, pos)) |
1551 self.__stack.append((fixId, code, line, pos)) |
1445 return (-1, "", fixId) |
1552 return (-1, "", [], fixId) |
1446 |
1553 |
1447 def __fixE304(self, code, line, pos, apply=False): |
1554 def __fixE304(self, code, line, pos, apply=False): |
1448 """ |
1555 """ |
1449 Private method to fix superfluous blank lines after a function |
1556 Private method to fix superfluous blank lines after a function |
1450 decorator. |
1557 decorator. |
1451 |
1558 |
1452 Codes: E304 |
1559 Codes: E304 |
1453 |
1560 |
1454 @param code code of the issue (string) |
1561 @param code code of the issue |
1455 @param line line number of the issue (integer) |
1562 @type str |
1456 @param pos position inside line (integer) |
1563 @param line line number of the issue |
1457 @keyparam apply flag indicating, that the fix should be applied |
1564 @type int |
1458 (boolean) |
1565 @param pos position inside line |
1459 @return value indicating an applied/deferred fix (-1, 0, 1), |
1566 @type int |
1460 a message for the fix (string) and an ID for a deferred |
1567 @param apply flag indicating, that the fix should be applied |
1461 fix (integer) |
1568 @type bool |
|
1569 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1570 a message code for the fix, a list of arguments for the |
|
1571 message and an ID for a deferred fix |
|
1572 @rtype tuple of (int, str, list or int, int) |
1462 """ |
1573 """ |
1463 if apply: |
1574 if apply: |
1464 index = line - 2 |
1575 index = line - 2 |
1465 while index: |
1576 while index: |
1466 if self.__source[index].strip() == "": |
1577 if self.__source[index].strip() == "": |
1467 del self.__source[index] |
1578 del self.__source[index] |
1468 index -= 1 |
1579 index -= 1 |
1469 else: |
1580 else: |
1470 break |
1581 break |
1471 # Superfluous blank lines after function decorator removed. |
1582 # Superfluous blank lines after function decorator removed. |
1472 return (1, "FIXE304", 0) |
1583 return (1, "FIXE304", [], 0) |
1473 else: |
1584 else: |
1474 fixId = self.__getID() |
1585 fixId = self.__getID() |
1475 self.__stack.append((fixId, code, line, pos)) |
1586 self.__stack.append((fixId, code, line, pos)) |
1476 return (-1, "", fixId) |
1587 return (-1, "", [], fixId) |
1477 |
1588 |
1478 def __fixE401(self, code, line, pos, apply=False): |
1589 def __fixE401(self, code, line, pos, apply=False): |
1479 """ |
1590 """ |
1480 Private method to fix multiple imports on one line. |
1591 Private method to fix multiple imports on one line. |
1481 |
1592 |
1482 Codes: E401 |
1593 Codes: E401 |
1483 |
1594 |
1484 @param code code of the issue (string) |
1595 @param code code of the issue |
1485 @param line line number of the issue (integer) |
1596 @type str |
1486 @param pos position inside line (integer) |
1597 @param line line number of the issue |
1487 @keyparam apply flag indicating, that the fix should be applied |
1598 @type int |
1488 (boolean) |
1599 @param pos position inside line |
1489 @return value indicating an applied/deferred fix (-1, 0, 1), |
1600 @type int |
1490 a message for the fix (string) and an ID for a deferred |
1601 @param apply flag indicating, that the fix should be applied |
1491 fix (integer) |
1602 @type bool |
|
1603 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1604 a message code for the fix, a list of arguments for the |
|
1605 message and an ID for a deferred fix |
|
1606 @rtype tuple of (int, str, list or int, int) |
1492 """ |
1607 """ |
1493 if apply: |
1608 if apply: |
1494 line = line - 1 |
1609 line = line - 1 |
1495 text = self.__source[line] |
1610 text = self.__source[line] |
1496 if not text.lstrip().startswith("import"): |
1611 if not text.lstrip().startswith("import"): |
1497 return (0, "", 0) |
1612 return (0, "", [], 0) |
1498 |
1613 |
1499 # pycodestyle (1.3.1) reports false positive if there is an import |
1614 # pycodestyle (1.3.1) reports false positive if there is an import |
1500 # statement followed by a semicolon and some unrelated |
1615 # statement followed by a semicolon and some unrelated |
1501 # statement with commas in it. |
1616 # statement with commas in it. |
1502 if ';' in text: |
1617 if ';' in text: |
1503 return (0, "", 0) |
1618 return (0, "", [], 0) |
1504 |
1619 |
1505 newText = ( |
1620 newText = ( |
1506 text[:pos].rstrip("\t ,") + |
1621 text[:pos].rstrip("\t ,") + |
1507 self.__eol + |
1622 self.__eol + |
1508 self.__getIndent(text) + |
1623 self.__getIndent(text) + |
1509 "import " + |
1624 "import " + |
1510 text[pos:].lstrip("\t ,") |
1625 text[pos:].lstrip("\t ,") |
1511 ) |
1626 ) |
1512 self.__source[line] = newText |
1627 self.__source[line] = newText |
1513 # Imports were put on separate lines. |
1628 # Imports were put on separate lines. |
1514 return (1, "FIXE401", 0) |
1629 return (1, "FIXE401", [], 0) |
1515 else: |
1630 else: |
1516 fixId = self.__getID() |
1631 fixId = self.__getID() |
1517 self.__stack.append((fixId, code, line, pos)) |
1632 self.__stack.append((fixId, code, line, pos)) |
1518 return (-1, "", fixId) |
1633 return (-1, "", [], fixId) |
1519 |
1634 |
1520 def __fixE501(self, code, line, pos, apply=False): |
1635 def __fixE501(self, code, line, pos, apply=False): |
1521 """ |
1636 """ |
1522 Private method to fix the long lines by breaking them. |
1637 Private method to fix the long lines by breaking them. |
1523 |
1638 |
1524 Codes: E501 |
1639 Codes: E501 |
1525 |
1640 |
1526 @param code code of the issue (string) |
1641 @param code code of the issue |
1527 @param line line number of the issue (integer) |
1642 @type str |
1528 @param pos position inside line (integer) |
1643 @param line line number of the issue |
1529 @keyparam apply flag indicating, that the fix should be applied |
1644 @type int |
1530 (boolean) |
1645 @param pos position inside line |
1531 @return value indicating an applied/deferred fix (-1, 0, 1), |
1646 @type int |
1532 a message for the fix (string) and an ID for a deferred |
1647 @param apply flag indicating, that the fix should be applied |
1533 fix (integer) |
1648 @type bool |
|
1649 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1650 a message code for the fix, a list of arguments for the |
|
1651 message and an ID for a deferred fix |
|
1652 @rtype tuple of (int, str, list or int, int) |
1534 """ |
1653 """ |
1535 if apply: |
1654 if apply: |
1536 multilineStringLines, docStringLines = ( |
1655 multilineStringLines, docStringLines = ( |
1537 self.__multilineStringLines() |
1656 self.__multilineStringLines() |
1538 ) |
1657 ) |
1558 if newNextText and newNextText != nextText: |
1677 if newNextText and newNextText != nextText: |
1559 if newNextText == " ": |
1678 if newNextText == " ": |
1560 newNextText = "" |
1679 newNextText = "" |
1561 self.__source[line + 1] = newNextText |
1680 self.__source[line + 1] = newNextText |
1562 # Long lines have been shortened. |
1681 # Long lines have been shortened. |
1563 return (1, "FIXE501", 0) |
1682 return (1, "FIXE501", [], 0) |
1564 else: |
1683 else: |
1565 return (0, "", 0) |
1684 return (0, "", [], 0) |
1566 else: |
1685 else: |
1567 fixId = self.__getID() |
1686 fixId = self.__getID() |
1568 self.__stack.append((fixId, code, line, pos)) |
1687 self.__stack.append((fixId, code, line, pos)) |
1569 return (-1, "", fixId) |
1688 return (-1, "", [], fixId) |
1570 |
1689 |
1571 def __fixE502(self, code, line, pos): |
1690 def __fixE502(self, code, line, pos): |
1572 """ |
1691 """ |
1573 Private method to fix redundant backslash within brackets. |
1692 Private method to fix redundant backslash within brackets. |
1574 |
1693 |
1575 Codes: E502 |
1694 Codes: E502 |
1576 |
1695 |
1577 @param code code of the issue (string) |
1696 @param code code of the issue |
1578 @param line line number of the issue (integer) |
1697 @type str |
1579 @param pos position inside line (integer) |
1698 @param line line number of the issue |
1580 @return value indicating an applied/deferred fix (-1, 0, 1), |
1699 @type int |
1581 a message for the fix (string) and an ID for a deferred |
1700 @param pos position inside line |
1582 fix (integer) |
1701 @type int |
|
1702 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1703 a message code for the fix, a list of arguments for the |
|
1704 message and an ID for a deferred fix |
|
1705 @rtype tuple of (int, str, list or int, int) |
1583 """ |
1706 """ |
1584 self.__source[line - 1] = ( |
1707 self.__source[line - 1] = ( |
1585 self.__source[line - 1].rstrip("\n\r \t\\") + |
1708 self.__source[line - 1].rstrip("\n\r \t\\") + |
1586 self.__eol |
1709 self.__eol |
1587 ) |
1710 ) |
1588 # Redundant backslash in brackets removed. |
1711 # Redundant backslash in brackets removed. |
1589 return (1, "FIXE502", 0) |
1712 return (1, "FIXE502", [], 0) |
1590 |
1713 |
1591 def __fixE701(self, code, line, pos, apply=False): |
1714 def __fixE701(self, code, line, pos, apply=False): |
1592 """ |
1715 """ |
1593 Private method to fix colon-separated compound statements. |
1716 Private method to fix colon-separated compound statements. |
1594 |
1717 |
1595 Codes: E701 |
1718 Codes: E701 |
1596 |
1719 |
1597 @param code code of the issue (string) |
1720 @param code code of the issue |
1598 @param line line number of the issue (integer) |
1721 @type str |
1599 @param pos position inside line (integer) |
1722 @param line line number of the issue |
1600 @keyparam apply flag indicating, that the fix should be applied |
1723 @type int |
1601 (boolean) |
1724 @param pos position inside line |
1602 @return value indicating an applied/deferred fix (-1, 0, 1), |
1725 @type int |
1603 a message for the fix (string) and an ID for a deferred |
1726 @param apply flag indicating, that the fix should be applied |
1604 fix (integer) |
1727 @type bool |
|
1728 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1729 a message code for the fix, a list of arguments for the |
|
1730 message and an ID for a deferred fix |
|
1731 @rtype tuple of (int, str, list or int, int) |
1605 """ |
1732 """ |
1606 if apply: |
1733 if apply: |
1607 line = line - 1 |
1734 line = line - 1 |
1608 text = self.__source[line] |
1735 text = self.__source[line] |
1609 pos = pos + 1 |
1736 pos = pos + 1 |
1802 self.__source[line] = "" |
1945 self.__source[line] = "" |
1803 else: |
1946 else: |
1804 self.__source[line] = indent + right |
1947 self.__source[line] = indent + right |
1805 |
1948 |
1806 # '{0}' argument removed. |
1949 # '{0}' argument removed. |
1807 return (1, ("FIXN806", arg), 0) |
1950 return (1, "FIXN806", [arg], 0) |
1808 else: |
1951 else: |
1809 fixId = self.__getID() |
1952 fixId = self.__getID() |
1810 self.__stack.append((fixId, code, line, pos)) |
1953 self.__stack.append((fixId, code, line, pos)) |
1811 return (-1, "", fixId) |
1954 return (-1, "", [], fixId) |
1812 |
1955 |
1813 def __fixW291(self, code, line, pos): |
1956 def __fixW291(self, code, line, pos): |
1814 """ |
1957 """ |
1815 Private method to fix trailing whitespace. |
1958 Private method to fix trailing whitespace. |
1816 |
1959 |
1817 Codes: W291, W293 |
1960 Codes: W291, W293 |
1818 |
1961 |
1819 @param code code of the issue (string) |
1962 @param code code of the issue |
1820 @param line line number of the issue (integer) |
1963 @type str |
1821 @param pos position inside line (integer) |
1964 @param line line number of the issue |
1822 @return value indicating an applied/deferred fix (-1, 0, 1), |
1965 @type int |
1823 a message for the fix (string) and an ID for a deferred |
1966 @param pos position inside line |
1824 fix (integer) |
1967 @type int |
|
1968 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1969 a message code for the fix, a list of arguments for the |
|
1970 message and an ID for a deferred fix |
|
1971 @rtype tuple of (int, str, list or int, int) |
1825 """ |
1972 """ |
1826 self.__source[line - 1] = re.sub(r'[\t ]+(\r?)$', r"\1", |
1973 self.__source[line - 1] = re.sub(r'[\t ]+(\r?)$', r"\1", |
1827 self.__source[line - 1]) |
1974 self.__source[line - 1]) |
1828 # Whitespace stripped from end of line. |
1975 # Whitespace stripped from end of line. |
1829 return (1, "FIXW291", 0) |
1976 return (1, "FIXW291", [], 0) |
1830 |
1977 |
1831 def __fixW292(self, code, line, pos): |
1978 def __fixW292(self, code, line, pos): |
1832 """ |
1979 """ |
1833 Private method to fix a missing newline at the end of file. |
1980 Private method to fix a missing newline at the end of file. |
1834 |
1981 |
1835 Codes: W292 |
1982 Codes: W292 |
1836 |
1983 |
1837 @param code code of the issue (string) |
1984 @param code code of the issue |
1838 @param line line number of the issue (integer) |
1985 @type str |
1839 @param pos position inside line (integer) |
1986 @param line line number of the issue |
1840 @return value indicating an applied/deferred fix (-1, 0, 1), |
1987 @type int |
1841 a message for the fix (string) and an ID for a deferred |
1988 @param pos position inside line |
1842 fix (integer) |
1989 @type int |
|
1990 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
1991 a message code for the fix, a list of arguments for the |
|
1992 message and an ID for a deferred fix |
|
1993 @rtype tuple of (int, str, list or int, int) |
1843 """ |
1994 """ |
1844 self.__source[line - 1] += self.__eol |
1995 self.__source[line - 1] += self.__eol |
1845 # newline added to end of file. |
1996 # newline added to end of file. |
1846 return (1, "FIXW292", 0) |
1997 return (1, "FIXW292", [], 0) |
1847 |
1998 |
1848 def __fixW391(self, code, line, pos): |
1999 def __fixW391(self, code, line, pos): |
1849 """ |
2000 """ |
1850 Private method to fix trailing blank lines. |
2001 Private method to fix trailing blank lines. |
1851 |
2002 |
1852 Codes: W391 |
2003 Codes: W391 |
1853 |
2004 |
1854 @param code code of the issue (string) |
2005 @param code code of the issue |
1855 @param line line number of the issue (integer) |
2006 @type str |
1856 @param pos position inside line (integer) |
2007 @param line line number of the issue |
1857 @return value indicating an applied/deferred fix (-1, 0, 1), |
2008 @type int |
1858 a message for the fix (string) and an ID for a deferred |
2009 @param pos position inside line |
1859 fix (integer) |
2010 @type int |
|
2011 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
2012 a message code for the fix, a list of arguments for the |
|
2013 message and an ID for a deferred fix |
|
2014 @rtype tuple of (int, str, list or int, int) |
1860 """ |
2015 """ |
1861 index = line - 1 |
2016 index = line - 1 |
1862 while index: |
2017 while index: |
1863 if self.__source[index].strip() == "": |
2018 if self.__source[index].strip() == "": |
1864 del self.__source[index] |
2019 del self.__source[index] |
1865 index -= 1 |
2020 index -= 1 |
1866 else: |
2021 else: |
1867 break |
2022 break |
1868 # Superfluous trailing blank lines removed from end of file. |
2023 # Superfluous trailing blank lines removed from end of file. |
1869 return (1, "FIXW391", 0) |
2024 return (1, "FIXW391", [], 0) |
1870 |
2025 |
1871 def __fixW603(self, code, line, pos): |
2026 def __fixW603(self, code, line, pos): |
1872 """ |
2027 """ |
1873 Private method to fix the not equal notation. |
2028 Private method to fix the not equal notation. |
1874 |
2029 |
1875 Codes: W603 |
2030 Codes: W603 |
1876 |
2031 |
1877 @param code code of the issue (string) |
2032 @param code code of the issue |
1878 @param line line number of the issue (integer) |
2033 @type str |
1879 @param pos position inside line (integer) |
2034 @param line line number of the issue |
1880 @return value indicating an applied/deferred fix (-1, 0, 1), |
2035 @type int |
1881 a message for the fix (string) and an ID for a deferred |
2036 @param pos position inside line |
1882 fix (integer) |
2037 @type int |
|
2038 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
2039 a message code for the fix, a list of arguments for the |
|
2040 message and an ID for a deferred fix |
|
2041 @rtype tuple of (int, str, list or int, int) |
1883 """ |
2042 """ |
1884 self.__source[line - 1] = self.__source[line - 1].replace("<>", "!=") |
2043 self.__source[line - 1] = self.__source[line - 1].replace("<>", "!=") |
1885 # '<>' replaced by '!='. |
2044 # '<>' replaced by '!='. |
1886 return (1, "FIXW603", 0) |
2045 return (1, "FIXW603", [], 0) |
1887 |
2046 |
1888 |
2047 |
1889 class Reindenter(object): |
2048 class Reindenter(object): |
1890 """ |
2049 """ |
1891 Class to reindent badly-indented code to uniformly use four-space |
2050 Class to reindent badly-indented code to uniformly use four-space |