182 try: |
182 try: |
183 Utilities.writeEncodedFile(self.__filename, txt, encoding) |
183 Utilities.writeEncodedFile(self.__filename, txt, encoding) |
184 except (IOError, Utilities.CodingError, UnicodeError) as err: |
184 except (IOError, Utilities.CodingError, UnicodeError) as err: |
185 E5MessageBox.critical( |
185 E5MessageBox.critical( |
186 self, |
186 self, |
187 self.trUtf8("Fix Code Style Issues"), |
187 self.tr("Fix Code Style Issues"), |
188 self.trUtf8( |
188 self.tr( |
189 """<p>Could not save the file <b>{0}</b>.""" |
189 """<p>Could not save the file <b>{0}</b>.""" |
190 """ Skipping it.</p><p>Reason: {1}</p>""") |
190 """ Skipping it.</p><p>Reason: {1}</p>""") |
191 .format(self.__filename, str(err)) |
191 .format(self.__filename, str(err)) |
192 ) |
192 ) |
193 return False |
193 return False |
539 newText = self.__getIndent(self.__source[line]) + \ |
539 newText = self.__getIndent(self.__source[line]) + \ |
540 insertChar + self.__source[line].lstrip() |
540 insertChar + self.__source[line].lstrip() |
541 self.__source[line] = newText |
541 self.__source[line] = newText |
542 return ( |
542 return ( |
543 1, |
543 1, |
544 self.trUtf8('Introductory quotes corrected to be {0}"""') |
544 self.tr('Introductory quotes corrected to be {0}"""') |
545 .format(insertChar), |
545 .format(insertChar), |
546 0) |
546 0) |
547 |
547 |
548 def __fixD121(self, code, line, pos, apply=False): |
548 def __fixD121(self, code, line, pos, apply=False): |
549 """ |
549 """ |
577 |
577 |
578 self.__source[line] = docstring |
578 self.__source[line] = docstring |
579 self.__source[line + 1] = "" |
579 self.__source[line + 1] = "" |
580 return ( |
580 return ( |
581 1, |
581 1, |
582 self.trUtf8("Single line docstring put on one line."), |
582 self.tr("Single line docstring put on one line."), |
583 0) |
583 0) |
584 else: |
584 else: |
585 id = self.__getID() |
585 id = self.__getID() |
586 self.__stack.append((id, code, line, pos)) |
586 self.__stack.append((id, code, line, pos)) |
587 return (-1, "", id) |
587 return (-1, "", id) |
615 not self.__source[line].lstrip().startswith("@"))): |
615 not self.__source[line].lstrip().startswith("@"))): |
616 newText = self.__source[line].rstrip() + "." + self.__getEol() |
616 newText = self.__source[line].rstrip() + "." + self.__getEol() |
617 |
617 |
618 if newText: |
618 if newText: |
619 self.__source[line] = newText |
619 self.__source[line] = newText |
620 return (1, self.trUtf8("Period added to summary line."), 0) |
620 return (1, self.tr("Period added to summary line."), 0) |
621 else: |
621 else: |
622 return (0, "", 0) |
622 return (0, "", 0) |
623 |
623 |
624 def __fixD141(self, code, line, pos, apply=False): |
624 def __fixD141(self, code, line, pos, apply=False): |
625 """ |
625 """ |
669 if apply: |
669 if apply: |
670 line = line - 1 |
670 line = line - 1 |
671 self.__source[line] = self.__getEol() + self.__source[line] |
671 self.__source[line] = self.__getEol() + self.__source[line] |
672 return ( |
672 return ( |
673 1, |
673 1, |
674 self.trUtf8("Blank line inserted before class docstring."), |
674 self.tr("Blank line inserted before class docstring."), |
675 0) |
675 0) |
676 else: |
676 else: |
677 id = self.__getID() |
677 id = self.__getID() |
678 self.__stack.append((id, code, line, pos)) |
678 self.__stack.append((id, code, line, pos)) |
679 return (-1, "", id) |
679 return (-1, "", id) |
697 if apply: |
697 if apply: |
698 line = line - 1 |
698 line = line - 1 |
699 self.__source[line] += self.__getEol() |
699 self.__source[line] += self.__getEol() |
700 return ( |
700 return ( |
701 1, |
701 1, |
702 self.trUtf8("Blank line inserted after class docstring."), |
702 self.tr("Blank line inserted after class docstring."), |
703 0) |
703 0) |
704 else: |
704 else: |
705 id = self.__getID() |
705 id = self.__getID() |
706 self.__stack.append((id, code, line, pos)) |
706 self.__stack.append((id, code, line, pos)) |
707 return (-1, "", id) |
707 return (-1, "", id) |
729 return (0, "", 0) |
729 return (0, "", 0) |
730 |
730 |
731 self.__source[line] += self.__getEol() |
731 self.__source[line] += self.__getEol() |
732 return ( |
732 return ( |
733 1, |
733 1, |
734 self.trUtf8("Blank line inserted after docstring summary."), |
734 self.tr("Blank line inserted after docstring summary."), |
735 0) |
735 0) |
736 else: |
736 else: |
737 id = self.__getID() |
737 id = self.__getID() |
738 self.__stack.append((id, code, line, pos)) |
738 self.__stack.append((id, code, line, pos)) |
739 return (-1, "", id) |
739 return (-1, "", id) |
798 first, second = source[:-3].strip(), source[-3:] |
798 first, second = source[:-3].strip(), source[-3:] |
799 newText = indent + first + self.__getEol() + \ |
799 newText = indent + first + self.__getEol() + \ |
800 indent + second + self.__getEol() |
800 indent + second + self.__getEol() |
801 self.__source[line] = newText |
801 self.__source[line] = newText |
802 if code == "D221": |
802 if code == "D221": |
803 msg = self.trUtf8("Leading quotes put on separate line.") |
803 msg = self.tr("Leading quotes put on separate line.") |
804 else: |
804 else: |
805 msg = self.trUtf8("Trailing quotes put on separate line.") |
805 msg = self.tr("Trailing quotes put on separate line.") |
806 return (1, msg, 0) |
806 return (1, msg, 0) |
807 else: |
807 else: |
808 id = self.__getID() |
808 id = self.__getID() |
809 self.__stack.append((id, code, line, pos)) |
809 self.__stack.append((id, code, line, pos)) |
810 return (-1, "", id) |
810 return (-1, "", id) |
827 """ |
827 """ |
828 if apply: |
828 if apply: |
829 line = line - 1 |
829 line = line - 1 |
830 self.__source[line - 1] = "" |
830 self.__source[line - 1] = "" |
831 if code == "D242": |
831 if code == "D242": |
832 msg = self.trUtf8("Blank line before class docstring removed.") |
832 msg = self.tr("Blank line before class docstring removed.") |
833 else: |
833 else: |
834 msg = self.trUtf8( |
834 msg = self.tr( |
835 "Blank line before function/method docstring removed.") |
835 "Blank line before function/method docstring removed.") |
836 return (1, msg, 0) |
836 return (1, msg, 0) |
837 else: |
837 else: |
838 id = self.__getID() |
838 id = self.__getID() |
839 self.__stack.append((id, code, line, pos)) |
839 self.__stack.append((id, code, line, pos)) |
857 """ |
857 """ |
858 if apply: |
858 if apply: |
859 line = line - 1 |
859 line = line - 1 |
860 self.__source[line + 1] = "" |
860 self.__source[line + 1] = "" |
861 if code == "D243": |
861 if code == "D243": |
862 msg = self.trUtf8("Blank line after class docstring removed.") |
862 msg = self.tr("Blank line after class docstring removed.") |
863 else: |
863 else: |
864 msg = self.trUtf8( |
864 msg = self.tr( |
865 "Blank line after function/method docstring removed.") |
865 "Blank line after function/method docstring removed.") |
866 return (1, msg, 0) |
866 return (1, msg, 0) |
867 else: |
867 else: |
868 id = self.__getID() |
868 id = self.__getID() |
869 self.__stack.append((id, code, line, pos)) |
869 self.__stack.append((id, code, line, pos)) |
915 self.__reindenter.run() |
915 self.__reindenter.run() |
916 fixedLine = self.__reindenter.fixedLine(line - 1) |
916 fixedLine = self.__reindenter.fixedLine(line - 1) |
917 if fixedLine is not None and fixedLine != self.__source[line - 1]: |
917 if fixedLine is not None and fixedLine != self.__source[line - 1]: |
918 self.__source[line - 1] = fixedLine |
918 self.__source[line - 1] = fixedLine |
919 if code in ["E101", "W191"]: |
919 if code in ["E101", "W191"]: |
920 msg = self.trUtf8("Tab converted to 4 spaces.") |
920 msg = self.tr("Tab converted to 4 spaces.") |
921 else: |
921 else: |
922 msg = self.trUtf8( |
922 msg = self.tr( |
923 "Indentation adjusted to be a multiple of four.") |
923 "Indentation adjusted to be a multiple of four.") |
924 return (1, msg, 0) |
924 return (1, msg, 0) |
925 else: |
925 else: |
926 return (0, "", 0) |
926 return (0, "", 0) |
927 |
927 |
946 if logical: |
946 if logical: |
947 # Fix by adjusting initial indent level. |
947 # Fix by adjusting initial indent level. |
948 changed = self.__fixReindent(line, pos, logical) |
948 changed = self.__fixReindent(line, pos, logical) |
949 if changed: |
949 if changed: |
950 if code == "E121": |
950 if code == "E121": |
951 msg = self.trUtf8( |
951 msg = self.tr( |
952 "Indentation of continuation line corrected.") |
952 "Indentation of continuation line corrected.") |
953 elif code == "E124": |
953 elif code == "E124": |
954 msg = self.trUtf8( |
954 msg = self.tr( |
955 "Indentation of closing bracket corrected.") |
955 "Indentation of closing bracket corrected.") |
956 return (1, msg, 0) |
956 return (1, msg, 0) |
957 return (0, "", 0) |
957 return (0, "", 0) |
958 else: |
958 else: |
959 id = self.__getID() |
959 id = self.__getID() |
1026 changed = self.__fixReindent(line, pos, logical) |
1026 changed = self.__fixReindent(line, pos, logical) |
1027 else: |
1027 else: |
1028 self.__source[row] = newText |
1028 self.__source[row] = newText |
1029 changed = True |
1029 changed = True |
1030 if changed: |
1030 if changed: |
1031 return (1, self.trUtf8( |
1031 return (1, self.tr( |
1032 "Closing bracket aligned to opening bracket."), |
1032 "Closing bracket aligned to opening bracket."), |
1033 0) |
1033 0) |
1034 return (0, "", 0) |
1034 return (0, "", 0) |
1035 else: |
1035 else: |
1036 id = self.__getID() |
1036 id = self.__getID() |
1061 if not modified: |
1061 if not modified: |
1062 row = line - 1 |
1062 row = line - 1 |
1063 text = self.__source[row] |
1063 text = self.__source[row] |
1064 self.__source[row] = self.__getIndent(text) + \ |
1064 self.__source[row] = self.__getIndent(text) + \ |
1065 self.__indentWord + text.lstrip() |
1065 self.__indentWord + text.lstrip() |
1066 return (1, self.trUtf8("Indentation level changed."), 0) |
1066 return (1, self.tr("Indentation level changed."), 0) |
1067 return (0, "", 0) |
1067 return (0, "", 0) |
1068 else: |
1068 else: |
1069 id = self.__getID() |
1069 id = self.__getID() |
1070 self.__stackLogical.append((id, code, line, pos)) |
1070 self.__stackLogical.append((id, code, line, pos)) |
1071 return (-1, "", id) |
1071 return (-1, "", id) |
1100 changed = self.__fixReindent(line, pos, logical) |
1100 changed = self.__fixReindent(line, pos, logical) |
1101 else: |
1101 else: |
1102 self.__source[row] = newText |
1102 self.__source[row] = newText |
1103 changed = True |
1103 changed = True |
1104 if changed: |
1104 if changed: |
1105 return (1, self.trUtf8( |
1105 return (1, self.tr( |
1106 "Indentation level of hanging indentation changed."), |
1106 "Indentation level of hanging indentation changed."), |
1107 0) |
1107 0) |
1108 return (0, "", 0) |
1108 return (0, "", 0) |
1109 else: |
1109 else: |
1110 id = self.__getID() |
1110 id = self.__getID() |
1156 changed = self.__fixReindent(line, pos, logical) |
1156 changed = self.__fixReindent(line, pos, logical) |
1157 else: |
1157 else: |
1158 self.__source[row] = newText |
1158 self.__source[row] = newText |
1159 changed = True |
1159 changed = True |
1160 if changed: |
1160 if changed: |
1161 return (1, self.trUtf8("Visual indentation corrected."), 0) |
1161 return (1, self.tr("Visual indentation corrected."), 0) |
1162 return (0, "", 0) |
1162 return (0, "", 0) |
1163 else: |
1163 else: |
1164 id = self.__getID() |
1164 id = self.__getID() |
1165 self.__stackLogical.append((id, code, line, pos)) |
1165 self.__stackLogical.append((id, code, line, pos)) |
1166 return (-1, "", id) |
1166 return (-1, "", id) |
1187 newText = self.__fixWhitespace(text, pos, '') |
1187 newText = self.__fixWhitespace(text, pos, '') |
1188 if newText == text: |
1188 if newText == text: |
1189 return (0, "", 0) |
1189 return (0, "", 0) |
1190 |
1190 |
1191 self.__source[line] = newText |
1191 self.__source[line] = newText |
1192 return (1, self.trUtf8("Extraneous whitespace removed."), 0) |
1192 return (1, self.tr("Extraneous whitespace removed."), 0) |
1193 |
1193 |
1194 def __fixE221(self, code, line, pos): |
1194 def __fixE221(self, code, line, pos): |
1195 """ |
1195 """ |
1196 Private method to fix extraneous whitespace around operator or |
1196 Private method to fix extraneous whitespace around operator or |
1197 keyword. |
1197 keyword. |
1216 if newText == text: |
1216 if newText == text: |
1217 return (0, "", 0) |
1217 return (0, "", 0) |
1218 |
1218 |
1219 self.__source[line] = newText |
1219 self.__source[line] = newText |
1220 if code in ["E225", "E226", "E227", "E228"]: |
1220 if code in ["E225", "E226", "E227", "E228"]: |
1221 return (1, self.trUtf8("Missing whitespace added."), 0) |
1221 return (1, self.tr("Missing whitespace added."), 0) |
1222 else: |
1222 else: |
1223 return (1, self.trUtf8("Extraneous whitespace removed."), 0) |
1223 return (1, self.tr("Extraneous whitespace removed."), 0) |
1224 |
1224 |
1225 def __fixE231(self, code, line, pos): |
1225 def __fixE231(self, code, line, pos): |
1226 """ |
1226 """ |
1227 Private method to fix missing whitespace after ',;:'. |
1227 Private method to fix missing whitespace after ',;:'. |
1228 |
1228 |
1237 """ |
1237 """ |
1238 line = line - 1 |
1238 line = line - 1 |
1239 pos = pos + 1 |
1239 pos = pos + 1 |
1240 self.__source[line] = self.__source[line][:pos] + \ |
1240 self.__source[line] = self.__source[line][:pos] + \ |
1241 " " + self.__source[line][pos:] |
1241 " " + self.__source[line][pos:] |
1242 return (1, self.trUtf8("Missing whitespace added."), 0) |
1242 return (1, self.tr("Missing whitespace added."), 0) |
1243 |
1243 |
1244 def __fixE251(self, code, line, pos): |
1244 def __fixE251(self, code, line, pos): |
1245 """ |
1245 """ |
1246 Private method to fix extraneous whitespace around keyword and |
1246 Private method to fix extraneous whitespace around keyword and |
1247 default parameter equals. |
1247 default parameter equals. |
1274 if newText.endswith(('=\\\n', '=\\\r\n', '=\\\r')): |
1274 if newText.endswith(('=\\\n', '=\\\r\n', '=\\\r')): |
1275 self.__source[line] = newText.rstrip("\n\r \t\\") |
1275 self.__source[line] = newText.rstrip("\n\r \t\\") |
1276 self.__source[line + 1] = self.__source[line + 1].lstrip() |
1276 self.__source[line + 1] = self.__source[line + 1].lstrip() |
1277 else: |
1277 else: |
1278 self.__source[line] = newText |
1278 self.__source[line] = newText |
1279 return (1, self.trUtf8("Extraneous whitespace removed."), 0) |
1279 return (1, self.tr("Extraneous whitespace removed."), 0) |
1280 |
1280 |
1281 def __fixE261(self, code, line, pos): |
1281 def __fixE261(self, code, line, pos): |
1282 """ |
1282 """ |
1283 Private method to fix whitespace before or after inline comment. |
1283 Private method to fix whitespace before or after inline comment. |
1284 |
1284 |
1295 text = self.__source[line] |
1295 text = self.__source[line] |
1296 left = text[:pos].rstrip(' \t#') |
1296 left = text[:pos].rstrip(' \t#') |
1297 right = text[pos:].lstrip(' \t#') |
1297 right = text[pos:].lstrip(' \t#') |
1298 newText = left + (" # " + right if right.strip() else right) |
1298 newText = left + (" # " + right if right.strip() else right) |
1299 self.__source[line] = newText |
1299 self.__source[line] = newText |
1300 return (1, self.trUtf8("Whitespace around comment sign corrected."), 0) |
1300 return (1, self.tr("Whitespace around comment sign corrected."), 0) |
1301 |
1301 |
1302 def __fixE301(self, code, line, pos, apply=False): |
1302 def __fixE301(self, code, line, pos, apply=False): |
1303 """ |
1303 """ |
1304 Private method to fix the need for one blank line. |
1304 Private method to fix the need for one blank line. |
1305 |
1305 |
1314 a message for the fix (string) and an ID for a deferred |
1314 a message for the fix (string) and an ID for a deferred |
1315 fix (integer) |
1315 fix (integer) |
1316 """ |
1316 """ |
1317 if apply: |
1317 if apply: |
1318 self.__source.insert(line - 1, self.__getEol()) |
1318 self.__source.insert(line - 1, self.__getEol()) |
1319 return (1, self.trUtf8("One blank line inserted."), 0) |
1319 return (1, self.tr("One blank line inserted."), 0) |
1320 else: |
1320 else: |
1321 id = self.__getID() |
1321 id = self.__getID() |
1322 self.__stack.append((id, code, line, pos)) |
1322 self.__stack.append((id, code, line, pos)) |
1323 return (-1, "", id) |
1323 return (-1, "", id) |
1324 |
1324 |
1403 if self.__source[index].strip() == "": |
1403 if self.__source[index].strip() == "": |
1404 del self.__source[index] |
1404 del self.__source[index] |
1405 index -= 1 |
1405 index -= 1 |
1406 else: |
1406 else: |
1407 break |
1407 break |
1408 return (1, self.trUtf8("Superfluous blank lines removed."), 0) |
1408 return (1, self.tr("Superfluous blank lines removed."), 0) |
1409 else: |
1409 else: |
1410 id = self.__getID() |
1410 id = self.__getID() |
1411 self.__stack.append((id, code, line, pos)) |
1411 self.__stack.append((id, code, line, pos)) |
1412 return (-1, "", id) |
1412 return (-1, "", id) |
1413 |
1413 |
1433 if self.__source[index].strip() == "": |
1433 if self.__source[index].strip() == "": |
1434 del self.__source[index] |
1434 del self.__source[index] |
1435 index -= 1 |
1435 index -= 1 |
1436 else: |
1436 else: |
1437 break |
1437 break |
1438 return (1, self.trUtf8( |
1438 return (1, self.tr( |
1439 "Superfluous blank lines after function decorator removed."), |
1439 "Superfluous blank lines after function decorator removed."), |
1440 0) |
1440 0) |
1441 else: |
1441 else: |
1442 id = self.__getID() |
1442 id = self.__getID() |
1443 self.__stack.append((id, code, line, pos)) |
1443 self.__stack.append((id, code, line, pos)) |
1471 return (0, "", 0) |
1471 return (0, "", 0) |
1472 |
1472 |
1473 newText = text[:pos].rstrip("\t ,") + self.__getEol() + \ |
1473 newText = text[:pos].rstrip("\t ,") + self.__getEol() + \ |
1474 self.__getIndent(text) + "import " + text[pos:].lstrip("\t ,") |
1474 self.__getIndent(text) + "import " + text[pos:].lstrip("\t ,") |
1475 self.__source[line] = newText |
1475 self.__source[line] = newText |
1476 return (1, self.trUtf8("Imports were put on separate lines."), 0) |
1476 return (1, self.tr("Imports were put on separate lines."), 0) |
1477 else: |
1477 else: |
1478 id = self.__getID() |
1478 id = self.__getID() |
1479 self.__stack.append((id, code, line, pos)) |
1479 self.__stack.append((id, code, line, pos)) |
1480 return (-1, "", id) |
1480 return (-1, "", id) |
1481 |
1481 |
1518 self.__source[line] = newText |
1518 self.__source[line] = newText |
1519 if newNextText and newNextText != nextText: |
1519 if newNextText and newNextText != nextText: |
1520 if newNextText == " ": |
1520 if newNextText == " ": |
1521 newNextText = "" |
1521 newNextText = "" |
1522 self.__source[line + 1] = newNextText |
1522 self.__source[line + 1] = newNextText |
1523 return (1, self.trUtf8("Long lines have been shortened."), 0) |
1523 return (1, self.tr("Long lines have been shortened."), 0) |
1524 else: |
1524 else: |
1525 return (0, "", 0) |
1525 return (0, "", 0) |
1526 else: |
1526 else: |
1527 id = self.__getID() |
1527 id = self.__getID() |
1528 self.__stack.append((id, code, line, pos)) |
1528 self.__stack.append((id, code, line, pos)) |
1541 a message for the fix (string) and an ID for a deferred |
1541 a message for the fix (string) and an ID for a deferred |
1542 fix (integer) |
1542 fix (integer) |
1543 """ |
1543 """ |
1544 self.__source[line - 1] = \ |
1544 self.__source[line - 1] = \ |
1545 self.__source[line - 1].rstrip("\n\r \t\\") + self.__getEol() |
1545 self.__source[line - 1].rstrip("\n\r \t\\") + self.__getEol() |
1546 return (1, self.trUtf8("Redundant backslash in brackets removed."), 0) |
1546 return (1, self.tr("Redundant backslash in brackets removed."), 0) |
1547 |
1547 |
1548 def __fixE701(self, code, line, pos, apply=False): |
1548 def __fixE701(self, code, line, pos, apply=False): |
1549 """ |
1549 """ |
1550 Private method to fix colon-separated compound statements. |
1550 Private method to fix colon-separated compound statements. |
1551 |
1551 |
1567 |
1567 |
1568 newText = text[:pos] + self.__getEol() + self.__getIndent(text) + \ |
1568 newText = text[:pos] + self.__getEol() + self.__getIndent(text) + \ |
1569 self.__indentWord + text[pos:].lstrip("\n\r \t\\") + \ |
1569 self.__indentWord + text[pos:].lstrip("\n\r \t\\") + \ |
1570 self.__getEol() |
1570 self.__getEol() |
1571 self.__source[line] = newText |
1571 self.__source[line] = newText |
1572 return (1, self.trUtf8("Compound statement corrected."), 0) |
1572 return (1, self.tr("Compound statement corrected."), 0) |
1573 else: |
1573 else: |
1574 id = self.__getID() |
1574 id = self.__getID() |
1575 self.__stack.append((id, code, line, pos)) |
1575 self.__stack.append((id, code, line, pos)) |
1576 return (-1, "", id) |
1576 return (-1, "", id) |
1577 |
1577 |
1602 self.__source[line] = text.rstrip("\n\r \t;") + self.__getEol() |
1602 self.__source[line] = text.rstrip("\n\r \t;") + self.__getEol() |
1603 else: |
1603 else: |
1604 first = text[:pos].rstrip("\n\r \t;") + self.__getEol() |
1604 first = text[:pos].rstrip("\n\r \t;") + self.__getEol() |
1605 second = text[pos:].lstrip("\n\r \t;") |
1605 second = text[pos:].lstrip("\n\r \t;") |
1606 self.__source[line] = first + self.__getIndent(text) + second |
1606 self.__source[line] = first + self.__getIndent(text) + second |
1607 return (1, self.trUtf8("Compound statement corrected."), 0) |
1607 return (1, self.tr("Compound statement corrected."), 0) |
1608 else: |
1608 else: |
1609 id = self.__getID() |
1609 id = self.__getID() |
1610 self.__stack.append((id, code, line, pos)) |
1610 self.__stack.append((id, code, line, pos)) |
1611 return (-1, "", id) |
1611 return (-1, "", id) |
1612 |
1612 |
1643 center = "is not" |
1643 center = "is not" |
1644 else: |
1644 else: |
1645 return (0, "", 0) |
1645 return (0, "", 0) |
1646 |
1646 |
1647 self.__source[line] = " ".join([left, center, right]) |
1647 self.__source[line] = " ".join([left, center, right]) |
1648 return (1, self.trUtf8("Comparison to None/True/False corrected."), 0) |
1648 return (1, self.tr("Comparison to None/True/False corrected."), 0) |
1649 |
1649 |
1650 def __fixN804(self, code, line, pos, apply=False): |
1650 def __fixN804(self, code, line, pos, apply=False): |
1651 """ |
1651 """ |
1652 Private method to fix a wrong first argument of normal and |
1652 Private method to fix a wrong first argument of normal and |
1653 class methods. |
1653 class methods. |
1682 center = arg |
1682 center = arg |
1683 else: |
1683 else: |
1684 center = arg + ", " |
1684 center = arg + ", " |
1685 newText = left + center + right |
1685 newText = left + center + right |
1686 self.__source[line] = newText |
1686 self.__source[line] = newText |
1687 return (1, self.trUtf8("'{0}' argument added.").format(arg), 0) |
1687 return (1, self.tr("'{0}' argument added.").format(arg), 0) |
1688 else: |
1688 else: |
1689 id = self.__getID() |
1689 id = self.__getID() |
1690 self.__stack.append((id, code, line, pos)) |
1690 self.__stack.append((id, code, line, pos)) |
1691 return (-1, "", id) |
1691 return (-1, "", id) |
1692 |
1692 |
1742 self.__source[line - 1].rstrip() + right |
1742 self.__source[line - 1].rstrip() + right |
1743 self.__source[line] = "" |
1743 self.__source[line] = "" |
1744 else: |
1744 else: |
1745 self.__source[line] = indent + right |
1745 self.__source[line] = indent + right |
1746 |
1746 |
1747 return (1, self.trUtf8("'{0}' argument removed.").format(arg), 0) |
1747 return (1, self.tr("'{0}' argument removed.").format(arg), 0) |
1748 else: |
1748 else: |
1749 id = self.__getID() |
1749 id = self.__getID() |
1750 self.__stack.append((id, code, line, pos)) |
1750 self.__stack.append((id, code, line, pos)) |
1751 return (-1, "", id) |
1751 return (-1, "", id) |
1752 |
1752 |
1763 a message for the fix (string) and an ID for a deferred |
1763 a message for the fix (string) and an ID for a deferred |
1764 fix (integer) |
1764 fix (integer) |
1765 """ |
1765 """ |
1766 self.__source[line - 1] = re.sub(r'[\t ]+(\r?)$', r"\1", |
1766 self.__source[line - 1] = re.sub(r'[\t ]+(\r?)$', r"\1", |
1767 self.__source[line - 1]) |
1767 self.__source[line - 1]) |
1768 return (1, self.trUtf8("Whitespace stripped from end of line."), 0) |
1768 return (1, self.tr("Whitespace stripped from end of line."), 0) |
1769 |
1769 |
1770 def __fixW292(self, code, line, pos): |
1770 def __fixW292(self, code, line, pos): |
1771 """ |
1771 """ |
1772 Private method to fix a missing newline at the end of file. |
1772 Private method to fix a missing newline at the end of file. |
1773 |
1773 |
1779 @return value indicating an applied/deferred fix (-1, 0, 1), |
1779 @return value indicating an applied/deferred fix (-1, 0, 1), |
1780 a message for the fix (string) and an ID for a deferred |
1780 a message for the fix (string) and an ID for a deferred |
1781 fix (integer) |
1781 fix (integer) |
1782 """ |
1782 """ |
1783 self.__source[line - 1] += self.__getEol() |
1783 self.__source[line - 1] += self.__getEol() |
1784 return (1, self.trUtf8("newline added to end of file."), 0) |
1784 return (1, self.tr("newline added to end of file."), 0) |
1785 |
1785 |
1786 def __fixW391(self, code, line, pos): |
1786 def __fixW391(self, code, line, pos): |
1787 """ |
1787 """ |
1788 Private method to fix trailing blank lines. |
1788 Private method to fix trailing blank lines. |
1789 |
1789 |
1801 if self.__source[index].strip() == "": |
1801 if self.__source[index].strip() == "": |
1802 del self.__source[index] |
1802 del self.__source[index] |
1803 index -= 1 |
1803 index -= 1 |
1804 else: |
1804 else: |
1805 break |
1805 break |
1806 return (1, self.trUtf8( |
1806 return (1, self.tr( |
1807 "Superfluous trailing blank lines removed from end of file."), 0) |
1807 "Superfluous trailing blank lines removed from end of file."), 0) |
1808 |
1808 |
1809 def __fixW603(self, code, line, pos): |
1809 def __fixW603(self, code, line, pos): |
1810 """ |
1810 """ |
1811 Private method to fix the not equal notation. |
1811 Private method to fix the not equal notation. |
1818 @return value indicating an applied/deferred fix (-1, 0, 1), |
1818 @return value indicating an applied/deferred fix (-1, 0, 1), |
1819 a message for the fix (string) and an ID for a deferred |
1819 a message for the fix (string) and an ID for a deferred |
1820 fix (integer) |
1820 fix (integer) |
1821 """ |
1821 """ |
1822 self.__source[line - 1] = self.__source[line - 1].replace("<>", "!=") |
1822 self.__source[line - 1] = self.__source[line - 1].replace("<>", "!=") |
1823 return (1, self.trUtf8("'<>' replaced by '!='."), 0) |
1823 return (1, self.tr("'<>' replaced by '!='."), 0) |
1824 |
1824 |
1825 |
1825 |
1826 class Reindenter(object): |
1826 class Reindenter(object): |
1827 """ |
1827 """ |
1828 Class to reindent badly-indented code to uniformly use four-space |
1828 Class to reindent badly-indented code to uniformly use four-space |