Plugins/CheckerPlugins/Pep8/Pep8Fixer.py

changeset 2936
2ff273068a10
parent 2925
04896af1b0e1
child 2937
de26bc76d6ee
equal deleted inserted replaced
2935:e4c0b6e46ea3 2936:2ff273068a10
18 18
19 from . import pep8 19 from . import pep8
20 20
21 import Utilities 21 import Utilities
22 22
23 # TODO: add fixers for these issues
24 # D221, D231, D246,
25
23 Pep8FixableIssues = ["D111", "D112", "D113", "D121", "D131", "D141", 26 Pep8FixableIssues = ["D111", "D112", "D113", "D121", "D131", "D141",
24 "D142", "D143", "D144", "D145", 27 "D142", "D143", "D144", "D145",
28 "D242", "D243", "D244", "D245", "D247",
25 "E101", "E111", "E121", "E122", "E123", "E124", 29 "E101", "E111", "E121", "E122", "E123", "E124",
26 "E125", "E126", "E127", "E128", "E133", "E201", 30 "E125", "E126", "E127", "E128", "E133", "E201",
27 "E202", "E203", "E211", "E221", "E222", "E223", 31 "E202", "E203", "E211", "E221", "E222", "E223",
28 "E224", "E225", "E226", "E227", "E228", "E231", 32 "E224", "E225", "E226", "E227", "E228", "E231",
29 "E241", "E242", "E251", "E261", "E262", "E271", 33 "E241", "E242", "E251", "E261", "E262", "E271",
86 "D141": self.__fixD141, 90 "D141": self.__fixD141,
87 "D142": self.__fixD142, 91 "D142": self.__fixD142,
88 "D143": self.__fixD143, 92 "D143": self.__fixD143,
89 "D144": self.__fixD144, 93 "D144": self.__fixD144,
90 "D145": self.__fixD145, 94 "D145": self.__fixD145,
95 "D242": self.__fixD242,
96 "D243": self.__fixD243,
97 "D244": self.__fixD242,
98 "D245": self.__fixD243,
99 "D247": self.__fixD247,
91 "E101": self.__fixE101, 100 "E101": self.__fixE101,
92 "E111": self.__fixE101, 101 "E111": self.__fixE101,
93 "E121": self.__fixE121, 102 "E121": self.__fixE121,
94 "E122": self.__fixE122, 103 "E122": self.__fixE122,
95 "E123": self.__fixE123, 104 "E123": self.__fixE123,
724 self.__source[line] = self.__getEol() + self.__source[line] 733 self.__source[line] = self.__getEol() + self.__source[line]
725 return ( 734 return (
726 1, 735 1,
727 self.trUtf8("Blank line inserted after last paragraph" 736 self.trUtf8("Blank line inserted after last paragraph"
728 " of docstring."), 737 " of docstring."),
738 0)
739 else:
740 id = self.__getID()
741 self.__stack.append((id, code, line, pos))
742 return (-1, "", id)
743
744 def __fixD242(self, code, line, pos, apply=False):
745 """
746 Private method to fix a class or function/method docstring preceded
747 by a blank line (D242, D244).
748
749 @param code code of the issue (string)
750 @param line line number of the issue (integer)
751 @param pos position inside line (integer)
752 @keyparam apply flag indicating, that the fix should be applied
753 (boolean)
754 @return value indicating an applied/deferred fix (-1, 0, 1),
755 a message for the fix (string) and an ID for a deferred
756 fix (integer)
757 """
758 if apply:
759 line = line - 1
760 self.__source[line - 1] = ""
761 if code == "D242":
762 msg = self.trUtf8("Blank line before class docstring removed.")
763 else:
764 msg = self.trUtf8(
765 "Blank line before function/method docstring removed.")
766 return (1, msg, 0)
767 else:
768 id = self.__getID()
769 self.__stack.append((id, code, line, pos))
770 return (-1, "", id)
771
772 def __fixD243(self, code, line, pos, apply=False):
773 """
774 Private method to fix a class or function/method docstring followed
775 by a blank line (D243, D245).
776
777 @param code code of the issue (string)
778 @param line line number of the issue (integer)
779 @param pos position inside line (integer)
780 @keyparam apply flag indicating, that the fix should be applied
781 (boolean)
782 @return value indicating an applied/deferred fix (-1, 0, 1),
783 a message for the fix (string) and an ID for a deferred
784 fix (integer)
785 """
786 if apply:
787 line = line - 1
788 self.__source[line + 1] = ""
789 if code == "D243":
790 msg = self.trUtf8("Blank line after class docstring removed.")
791 else:
792 msg = self.trUtf8(
793 "Blank line after function/method docstring removed.")
794 return (1, msg, 0)
795 else:
796 id = self.__getID()
797 self.__stack.append((id, code, line, pos))
798 return (-1, "", id)
799
800 def __fixD247(self, code, line, pos, apply=False):
801 """
802 Private method to fix a last paragraph of a docstring followed
803 by a blank line (D247).
804
805 @param code code of the issue (string)
806 @param line line number of the issue (integer)
807 @param pos position inside line (integer)
808 @keyparam apply flag indicating, that the fix should be applied
809 (boolean)
810 @return value indicating an applied/deferred fix (-1, 0, 1),
811 a message for the fix (string) and an ID for a deferred
812 fix (integer)
813 """
814 if apply:
815 line = line - 1
816 self.__source[line - 1] = ""
817 return (
818 1,
819 self.trUtf8("Blank line after last paragraph removed."),
729 0) 820 0)
730 else: 821 else:
731 id = self.__getID() 822 id = self.__getID()
732 self.__stack.append((id, code, line, pos)) 823 self.__stack.append((id, code, line, pos))
733 return (-1, "", id) 824 return (-1, "", id)

eric ide

mercurial