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 |
|
26 Pep8FixableIssues = ["D111", "D112", "D113", "D121", "D131", "D141", |
23 Pep8FixableIssues = ["D111", "D112", "D113", "D121", "D131", "D141", |
27 "D142", "D143", "D144", "D145", |
24 "D142", "D143", "D144", "D145", |
28 "D242", "D243", "D244", "D245", "D247", |
25 "D221", "D222", "D231", "D242", "D243", "D244", |
|
26 "D245", "D246", "D247", |
29 "E101", "E111", "E121", "E122", "E123", "E124", |
27 "E101", "E111", "E121", "E122", "E123", "E124", |
30 "E125", "E126", "E127", "E128", "E133", "E201", |
28 "E125", "E126", "E127", "E128", "E133", "E201", |
31 "E202", "E203", "E211", "E221", "E222", "E223", |
29 "E202", "E203", "E211", "E221", "E222", "E223", |
32 "E224", "E225", "E226", "E227", "E228", "E231", |
30 "E224", "E225", "E226", "E227", "E228", "E231", |
33 "E241", "E242", "E251", "E261", "E262", "E271", |
31 "E241", "E242", "E251", "E261", "E262", "E271", |
90 "D141": self.__fixD141, |
88 "D141": self.__fixD141, |
91 "D142": self.__fixD142, |
89 "D142": self.__fixD142, |
92 "D143": self.__fixD143, |
90 "D143": self.__fixD143, |
93 "D144": self.__fixD144, |
91 "D144": self.__fixD144, |
94 "D145": self.__fixD145, |
92 "D145": self.__fixD145, |
|
93 "D221": self.__fixD221, |
|
94 "D222": self.__fixD221, |
|
95 "D231": self.__fixD131, |
95 "D242": self.__fixD242, |
96 "D242": self.__fixD242, |
96 "D243": self.__fixD243, |
97 "D243": self.__fixD243, |
97 "D244": self.__fixD242, |
98 "D244": self.__fixD242, |
98 "D245": self.__fixD243, |
99 "D245": self.__fixD243, |
|
100 "D246": self.__fixD144, |
99 "D247": self.__fixD247, |
101 "D247": self.__fixD247, |
100 "E101": self.__fixE101, |
102 "E101": self.__fixE101, |
101 "E111": self.__fixE101, |
103 "E111": self.__fixE101, |
102 "E121": self.__fixE121, |
104 "E121": self.__fixE121, |
103 "E122": self.__fixE122, |
105 "E122": self.__fixE122, |
575 self.__stack.append((id, code, line, pos)) |
577 self.__stack.append((id, code, line, pos)) |
576 return (-1, "", id) |
578 return (-1, "", id) |
577 |
579 |
578 def __fixD131(self, code, line, pos): |
580 def __fixD131(self, code, line, pos): |
579 """ |
581 """ |
580 Private method to fix a single line docstring on multiple lines (D121). |
582 Private method to fix a docstring summary not ending with a |
|
583 period (D131). |
581 |
584 |
582 @param code code of the issue (string) |
585 @param code code of the issue (string) |
583 @param line line number of the issue (integer) |
586 @param line line number of the issue (integer) |
584 @param pos position inside line (integer) |
587 @param pos position inside line (integer) |
585 @return value indicating an applied/deferred fix (-1, 0, 1), |
588 @return value indicating an applied/deferred fix (-1, 0, 1), |
589 line = line - 1 |
592 line = line - 1 |
590 newText = "" |
593 newText = "" |
591 if self.__source[line].rstrip().endswith(('"""', "'''")) and \ |
594 if self.__source[line].rstrip().endswith(('"""', "'''")) and \ |
592 self.__source[line].lstrip().startswith(('"""', 'r"""', 'u"""')): |
595 self.__source[line].lstrip().startswith(('"""', 'r"""', 'u"""')): |
593 # it is a one-liner |
596 # it is a one-liner |
594 newText = self.__source[line].rstrip()[:-3] + "." + \ |
597 newText = self.__source[line].rstrip()[:-3].rstrip() + "." + \ |
595 self.__source[line].rstrip()[-3:] + self.__getEol() |
598 self.__source[line].rstrip()[-3:] + self.__getEol() |
596 else: |
599 else: |
597 if line < len(self.__source) - 1 and \ |
600 if line < len(self.__source) - 1 and \ |
598 (not self.__source[line + 1].strip() or |
601 (not self.__source[line + 1].strip() or |
599 self.__source[line + 1].strip() in ('"""', "'''")): |
602 self.__source[line + 1].lstrip().startswith("@") or |
|
603 (self.__source[line + 1].strip() in ('"""', "'''") and |
|
604 not self.__source[line].lstrip().startswith("@"))): |
600 newText = self.__source[line].rstrip() + "." + self.__getEol() |
605 newText = self.__source[line].rstrip() + "." + self.__getEol() |
601 |
606 |
602 if newText: |
607 if newText: |
603 self.__source[line] = newText |
608 self.__source[line] = newText |
604 return (1, self.trUtf8("Period added to summary line."), 0) |
609 return (1, self.trUtf8("Period added to summary line."), 0) |
734 return ( |
739 return ( |
735 1, |
740 1, |
736 self.trUtf8("Blank line inserted after last paragraph" |
741 self.trUtf8("Blank line inserted after last paragraph" |
737 " of docstring."), |
742 " of docstring."), |
738 0) |
743 0) |
|
744 else: |
|
745 id = self.__getID() |
|
746 self.__stack.append((id, code, line, pos)) |
|
747 return (-1, "", id) |
|
748 |
|
749 def __fixD221(self, code, line, pos, apply=False): |
|
750 """ |
|
751 Private method to fix leading and trailing quotes of docstring |
|
752 not on separate lines (D221, D222). |
|
753 |
|
754 @param code code of the issue (string) |
|
755 @param line line number of the issue (integer) |
|
756 @param pos position inside line (integer) |
|
757 @keyparam apply flag indicating, that the fix should be applied |
|
758 (boolean) |
|
759 @return value indicating an applied/deferred fix (-1, 0, 1), |
|
760 a message for the fix (string) and an ID for a deferred |
|
761 fix (integer) |
|
762 """ |
|
763 if apply: |
|
764 line = line - 1 |
|
765 indent = self.__getIndent(self.__source[line]) |
|
766 source = self.__source[line].strip() |
|
767 if code == "D221": |
|
768 # leading |
|
769 if source.startswith(("r", "u")): |
|
770 first, second = source[:4], source[4:].strip() |
|
771 else: |
|
772 first, second = source[:3], source[3:].strip() |
|
773 else: |
|
774 # trailing |
|
775 first, second = source[:-3].strip(), source[-3:] |
|
776 newText = indent + first + self.__getEol() + \ |
|
777 indent + second + self.__getEol() |
|
778 self.__source[line] = newText |
|
779 if code == "D221": |
|
780 msg = self.trUtf8("Leading quotes put on separate line.") |
|
781 else: |
|
782 msg = self.trUtf8("Trailing quotes put on separate line.") |
|
783 return (1, msg, 0) |
739 else: |
784 else: |
740 id = self.__getID() |
785 id = self.__getID() |
741 self.__stack.append((id, code, line, pos)) |
786 self.__stack.append((id, code, line, pos)) |
742 return (-1, "", id) |
787 return (-1, "", id) |
743 |
788 |