eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py

changeset 7609
d5aff4fd0ef8
parent 7360
9190402e4505
child 7610
df7025fe26a3
equal deleted inserted replaced
7606:a3a4760b59ec 7609:d5aff4fd0ef8
236 236
237 with open(self.__filename, "wb") as fp: 237 with open(self.__filename, "wb") as fp:
238 fp.write(txt) 238 fp.write(txt)
239 except (IOError, UnicodeError) as err: 239 except (IOError, UnicodeError) as err:
240 # Could not save the file! Skipping it. Reason: {0} 240 # Could not save the file! Skipping it. Reason: {0}
241 return ("FWRITE_ERROR", (str(err),)) 241 return ("FIXWRITE_ERROR", (str(err),))
242 242
243 return None 243 return None
244 244
245 def __codeMatch(self, code): 245 def __codeMatch(self, code):
246 """ 246 """
545 self.__source[line] = left + '"""' + right 545 self.__source[line] = left + '"""' + right
546 break 546 break
547 line += 1 547 line += 1
548 548
549 # Triple single quotes converted to triple double quotes. 549 # Triple single quotes converted to triple double quotes.
550 return (1, "FD111", 0) 550 return (1, "FIXD111", 0)
551 551
552 def __fixD112(self, code, line, pos): 552 def __fixD112(self, code, line, pos):
553 """ 553 """
554 Private method to fix docstring 'r' or 'u' in leading quotes. 554 Private method to fix docstring 'r' or 'u' in leading quotes.
555 555
575 insertChar + 575 insertChar +
576 self.__source[line].lstrip() 576 self.__source[line].lstrip()
577 ) 577 )
578 self.__source[line] = newText 578 self.__source[line] = newText
579 # Introductory quotes corrected to be {0}""" 579 # Introductory quotes corrected to be {0}"""
580 return (1, ('FD112', (insertChar,)), 0) 580 return (1, ('FIXD112', (insertChar,)), 0)
581 581
582 def __fixD121(self, code, line, pos, apply=False): 582 def __fixD121(self, code, line, pos, apply=False):
583 """ 583 """
584 Private method to fix a single line docstring on multiple lines. 584 Private method to fix a single line docstring on multiple lines.
585 585
612 self.__source[line + 2] = "" 612 self.__source[line + 2] = ""
613 613
614 self.__source[line] = docstring 614 self.__source[line] = docstring
615 self.__source[line + 1] = "" 615 self.__source[line + 1] = ""
616 # Single line docstring put on one line. 616 # Single line docstring put on one line.
617 return (1, "FD121", 0) 617 return (1, "FIXD121", 0)
618 else: 618 else:
619 fixId = self.__getID() 619 fixId = self.__getID()
620 self.__stack.append((fixId, code, line, pos)) 620 self.__stack.append((fixId, code, line, pos))
621 return (-1, "", fixId) 621 return (-1, "", fixId)
622 622
658 newText = self.__source[line].rstrip() + "." + self.__eol 658 newText = self.__source[line].rstrip() + "." + self.__eol
659 659
660 if newText: 660 if newText:
661 self.__source[line] = newText 661 self.__source[line] = newText
662 # Period added to summary line. 662 # Period added to summary line.
663 return (1, "FD131", 0) 663 return (1, "FIXD131", 0)
664 else: 664 else:
665 return (0, "", 0) 665 return (0, "", 0)
666 666
667 def __fixD141(self, code, line, pos, apply=False): 667 def __fixD141(self, code, line, pos, apply=False):
668 """ 668 """
682 """ 682 """
683 if apply: 683 if apply:
684 line = line - 1 684 line = line - 1
685 self.__source[line - 1] = "" 685 self.__source[line - 1] = ""
686 # Blank line before function/method docstring removed. 686 # Blank line before function/method docstring removed.
687 return (1, "FD141", 0) 687 return (1, "FIXD141", 0)
688 else: 688 else:
689 fixId = self.__getID() 689 fixId = self.__getID()
690 self.__stack.append((fixId, code, line, pos)) 690 self.__stack.append((fixId, code, line, pos))
691 return (-1, "", fixId) 691 return (-1, "", fixId)
692 692
708 """ 708 """
709 if apply: 709 if apply:
710 line = line - 1 710 line = line - 1
711 self.__source[line] = self.__eol + self.__source[line] 711 self.__source[line] = self.__eol + self.__source[line]
712 # Blank line inserted before class docstring. 712 # Blank line inserted before class docstring.
713 return (1, "FD142", 0) 713 return (1, "FIXD142", 0)
714 else: 714 else:
715 fixId = self.__getID() 715 fixId = self.__getID()
716 self.__stack.append((fixId, code, line, pos)) 716 self.__stack.append((fixId, code, line, pos))
717 return (-1, "", fixId) 717 return (-1, "", fixId)
718 718
734 """ 734 """
735 if apply: 735 if apply:
736 line = line - 1 736 line = line - 1
737 self.__source[line] += self.__eol 737 self.__source[line] += self.__eol
738 # Blank line inserted after class docstring. 738 # Blank line inserted after class docstring.
739 return (1, "FD143", 0) 739 return (1, "FIXD143", 0)
740 else: 740 else:
741 fixId = self.__getID() 741 fixId = self.__getID()
742 self.__stack.append((fixId, code, line, pos)) 742 self.__stack.append((fixId, code, line, pos))
743 return (-1, "", fixId) 743 return (-1, "", fixId)
744 744
764 # only correct summary lines can be fixed here 764 # only correct summary lines can be fixed here
765 return (0, "", 0) 765 return (0, "", 0)
766 766
767 self.__source[line] += self.__eol 767 self.__source[line] += self.__eol
768 # Blank line inserted after docstring summary. 768 # Blank line inserted after docstring summary.
769 return (1, "FD144", 0) 769 return (1, "FIXD144", 0)
770 else: 770 else:
771 fixId = self.__getID() 771 fixId = self.__getID()
772 self.__stack.append((fixId, code, line, pos)) 772 self.__stack.append((fixId, code, line, pos))
773 return (-1, "", fixId) 773 return (-1, "", fixId)
774 774
790 """ 790 """
791 if apply: 791 if apply:
792 line = line - 1 792 line = line - 1
793 self.__source[line] = self.__eol + self.__source[line] 793 self.__source[line] = self.__eol + self.__source[line]
794 # Blank line inserted after last paragraph of docstring. 794 # Blank line inserted after last paragraph of docstring.
795 return (1, "FD145", 0) 795 return (1, "FIXD145", 0)
796 else: 796 else:
797 fixId = self.__getID() 797 fixId = self.__getID()
798 self.__stack.append((fixId, code, line, pos)) 798 self.__stack.append((fixId, code, line, pos))
799 return (-1, "", fixId) 799 return (-1, "", fixId)
800 800
836 self.__eol 836 self.__eol
837 ) 837 )
838 self.__source[line] = newText 838 self.__source[line] = newText
839 if code == "D221": 839 if code == "D221":
840 # Leading quotes put on separate line. 840 # Leading quotes put on separate line.
841 msg = "FD221" 841 msg = "FIXD221"
842 else: 842 else:
843 # Trailing quotes put on separate line. 843 # Trailing quotes put on separate line.
844 msg = "FD222" 844 msg = "FIXD222"
845 return (1, msg, 0) 845 return (1, msg, 0)
846 else: 846 else:
847 fixId = self.__getID() 847 fixId = self.__getID()
848 self.__stack.append((fixId, code, line, pos)) 848 self.__stack.append((fixId, code, line, pos))
849 return (-1, "", fixId) 849 return (-1, "", fixId)
867 if apply: 867 if apply:
868 line = line - 1 868 line = line - 1
869 self.__source[line - 1] = "" 869 self.__source[line - 1] = ""
870 if code == "D242": 870 if code == "D242":
871 # Blank line before class docstring removed. 871 # Blank line before class docstring removed.
872 msg = "FD242" 872 msg = "FIXD242"
873 else: 873 else:
874 # Blank line before function/method docstring removed. 874 # Blank line before function/method docstring removed.
875 msg = "FD244" 875 msg = "FIXD244"
876 return (1, msg, 0) 876 return (1, msg, 0)
877 else: 877 else:
878 fixId = self.__getID() 878 fixId = self.__getID()
879 self.__stack.append((fixId, code, line, pos)) 879 self.__stack.append((fixId, code, line, pos))
880 return (-1, "", fixId) 880 return (-1, "", fixId)
898 if apply: 898 if apply:
899 line = line - 1 899 line = line - 1
900 self.__source[line + 1] = "" 900 self.__source[line + 1] = ""
901 if code == "D243": 901 if code == "D243":
902 # Blank line after class docstring removed. 902 # Blank line after class docstring removed.
903 msg = "FD243" 903 msg = "FIXD243"
904 else: 904 else:
905 # Blank line after function/method docstring removed. 905 # Blank line after function/method docstring removed.
906 msg = "FD245" 906 msg = "FIXD245"
907 return (1, msg, 0) 907 return (1, msg, 0)
908 else: 908 else:
909 fixId = self.__getID() 909 fixId = self.__getID()
910 self.__stack.append((fixId, code, line, pos)) 910 self.__stack.append((fixId, code, line, pos))
911 return (-1, "", fixId) 911 return (-1, "", fixId)
928 """ 928 """
929 if apply: 929 if apply:
930 line = line - 1 930 line = line - 1
931 self.__source[line - 1] = "" 931 self.__source[line - 1] = ""
932 # Blank line after last paragraph removed. 932 # Blank line after last paragraph removed.
933 return (1, "FD247", 0) 933 return (1, "FIXD247", 0)
934 else: 934 else:
935 fixId = self.__getID() 935 fixId = self.__getID()
936 self.__stack.append((fixId, code, line, pos)) 936 self.__stack.append((fixId, code, line, pos))
937 return (-1, "", fixId) 937 return (-1, "", fixId)
938 938
955 fixedLine = self.__reindenter.fixedLine(line - 1) 955 fixedLine = self.__reindenter.fixedLine(line - 1)
956 if fixedLine is not None and fixedLine != self.__source[line - 1]: 956 if fixedLine is not None and fixedLine != self.__source[line - 1]:
957 self.__source[line - 1] = fixedLine 957 self.__source[line - 1] = fixedLine
958 if code in ["E101", "W191"]: 958 if code in ["E101", "W191"]:
959 # Tab converted to 4 spaces. 959 # Tab converted to 4 spaces.
960 msg = "FE101" 960 msg = "FIXE101"
961 else: 961 else:
962 # Indentation adjusted to be a multiple of four. 962 # Indentation adjusted to be a multiple of four.
963 msg = "FE111" 963 msg = "FIXE111"
964 return (1, msg, 0) 964 return (1, msg, 0)
965 else: 965 else:
966 return (0, "", 0) 966 return (0, "", 0)
967 967
968 def __fixE121(self, code, line, pos, apply=False): 968 def __fixE121(self, code, line, pos, apply=False):
987 # Fix by adjusting initial indent level. 987 # Fix by adjusting initial indent level.
988 changed = self.__fixReindent(line, pos, logical) 988 changed = self.__fixReindent(line, pos, logical)
989 if changed: 989 if changed:
990 if code == "E121": 990 if code == "E121":
991 # Indentation of continuation line corrected. 991 # Indentation of continuation line corrected.
992 msg = "FE121" 992 msg = "FIXE121"
993 elif code == "E124": 993 elif code == "E124":
994 # Indentation of closing bracket corrected. 994 # Indentation of closing bracket corrected.
995 msg = "FE124" 995 msg = "FIXE124"
996 return (1, msg, 0) 996 return (1, msg, 0)
997 return (0, "", 0) 997 return (0, "", 0)
998 else: 998 else:
999 fixId = self.__getID() 999 fixId = self.__getID()
1000 self.__stackLogical.append((fixId, code, line, pos)) 1000 self.__stackLogical.append((fixId, code, line, pos))
1028 self.__source[line] = ( 1028 self.__source[line] = (
1029 indentation + 1029 indentation +
1030 self.__indentWord + text.lstrip() 1030 self.__indentWord + text.lstrip()
1031 ) 1031 )
1032 # Missing indentation of continuation line corrected. 1032 # Missing indentation of continuation line corrected.
1033 return (1, "FE122", 0) 1033 return (1, "FIXE122", 0)
1034 return (0, "", 0) 1034 return (0, "", 0)
1035 else: 1035 else:
1036 fixId = self.__getID() 1036 fixId = self.__getID()
1037 self.__stackLogical.append((fixId, code, line, pos)) 1037 self.__stackLogical.append((fixId, code, line, pos))
1038 return (-1, "", fixId) 1038 return (-1, "", fixId)
1066 else: 1066 else:
1067 self.__source[row] = newText 1067 self.__source[row] = newText
1068 changed = True 1068 changed = True
1069 if changed: 1069 if changed:
1070 # Closing bracket aligned to opening bracket. 1070 # Closing bracket aligned to opening bracket.
1071 return (1, "FE123", 0) 1071 return (1, "FIXE123", 0)
1072 return (0, "", 0) 1072 return (0, "", 0)
1073 else: 1073 else:
1074 fixId = self.__getID() 1074 fixId = self.__getID()
1075 self.__stackLogical.append((fixId, code, line, pos)) 1075 self.__stackLogical.append((fixId, code, line, pos))
1076 return (-1, "", fixId) 1076 return (-1, "", fixId)
1102 self.__source[row] = ( 1102 self.__source[row] = (
1103 self.__getIndent(text) + 1103 self.__getIndent(text) +
1104 self.__indentWord + text.lstrip() 1104 self.__indentWord + text.lstrip()
1105 ) 1105 )
1106 # Indentation level changed. 1106 # Indentation level changed.
1107 return (1, "FE125", 0) 1107 return (1, "FIXE125", 0)
1108 return (0, "", 0) 1108 return (0, "", 0)
1109 else: 1109 else:
1110 fixId = self.__getID() 1110 fixId = self.__getID()
1111 self.__stackLogical.append((fixId, code, line, pos)) 1111 self.__stackLogical.append((fixId, code, line, pos))
1112 return (-1, "", fixId) 1112 return (-1, "", fixId)
1144 else: 1144 else:
1145 self.__source[row] = newText 1145 self.__source[row] = newText
1146 changed = True 1146 changed = True
1147 if changed: 1147 if changed:
1148 # Indentation level of hanging indentation changed. 1148 # Indentation level of hanging indentation changed.
1149 return (1, "FE126", 0) 1149 return (1, "FIXE126", 0)
1150 return (0, "", 0) 1150 return (0, "", 0)
1151 else: 1151 else:
1152 fixId = self.__getID() 1152 fixId = self.__getID()
1153 self.__stackLogical.append((fixId, code, line, pos)) 1153 self.__stackLogical.append((fixId, code, line, pos))
1154 return (-1, "", fixId) 1154 return (-1, "", fixId)
1202 else: 1202 else:
1203 self.__source[row] = newText 1203 self.__source[row] = newText
1204 changed = True 1204 changed = True
1205 if changed: 1205 if changed:
1206 # Visual indentation corrected. 1206 # Visual indentation corrected.
1207 return (1, "FE127", 0) 1207 return (1, "FIXE127", 0)
1208 return (0, "", 0) 1208 return (0, "", 0)
1209 else: 1209 else:
1210 fixId = self.__getID() 1210 fixId = self.__getID()
1211 self.__stackLogical.append((fixId, code, line, pos)) 1211 self.__stackLogical.append((fixId, code, line, pos))
1212 return (-1, "", fixId) 1212 return (-1, "", fixId)
1234 if newText == text: 1234 if newText == text:
1235 return (0, "", 0) 1235 return (0, "", 0)
1236 1236
1237 self.__source[line] = newText 1237 self.__source[line] = newText
1238 # Extraneous whitespace removed. 1238 # Extraneous whitespace removed.
1239 return (1, "FE201", 0) 1239 return (1, "FIXE201", 0)
1240 1240
1241 def __fixE221(self, code, line, pos): 1241 def __fixE221(self, code, line, pos):
1242 """ 1242 """
1243 Private method to fix extraneous whitespace around operator or 1243 Private method to fix extraneous whitespace around operator or
1244 keyword. 1244 keyword.
1261 newText = self.__fixWhitespace(text, pos, ' ') 1261 newText = self.__fixWhitespace(text, pos, ' ')
1262 if newText == text: 1262 if newText == text:
1263 return (0, "", 0) 1263 return (0, "", 0)
1264 1264
1265 self.__source[line] = newText 1265 self.__source[line] = newText
1266 return (1, "FE221", 0) 1266 return (1, "FIXE221", 0)
1267 1267
1268 def __fixE225(self, code, line, pos): 1268 def __fixE225(self, code, line, pos):
1269 """ 1269 """
1270 Private method to fix extraneous whitespaces around operator. 1270 Private method to fix extraneous whitespaces around operator.
1271 1271
1302 if newText == text: 1302 if newText == text:
1303 return (0, "", 0) 1303 return (0, "", 0)
1304 1304
1305 self.__source[line] = newText 1305 self.__source[line] = newText
1306 # Missing whitespaces added. 1306 # Missing whitespaces added.
1307 return (1, "FE225", 0) 1307 return (1, "FIXE225", 0)
1308 1308
1309 def __fixE231(self, code, line, pos): 1309 def __fixE231(self, code, line, pos):
1310 """ 1310 """
1311 Private method to fix missing whitespace after ',;:'. 1311 Private method to fix missing whitespace after ',;:'.
1312 1312
1325 self.__source[line][:pos] + 1325 self.__source[line][:pos] +
1326 " " + 1326 " " +
1327 self.__source[line][pos:] 1327 self.__source[line][pos:]
1328 ) 1328 )
1329 # Missing whitespace added. 1329 # Missing whitespace added.
1330 return (1, "FE231", 0) 1330 return (1, "FIXE231", 0)
1331 1331
1332 def __fixE251(self, code, line, pos): 1332 def __fixE251(self, code, line, pos):
1333 """ 1333 """
1334 Private method to fix extraneous whitespace around keyword and 1334 Private method to fix extraneous whitespace around keyword and
1335 default parameter equals. 1335 default parameter equals.
1360 self.__source[line] = newText.rstrip("\n\r \t\\") 1360 self.__source[line] = newText.rstrip("\n\r \t\\")
1361 self.__source[line + 1] = self.__source[line + 1].lstrip() 1361 self.__source[line + 1] = self.__source[line + 1].lstrip()
1362 else: 1362 else:
1363 self.__source[line] = newText 1363 self.__source[line] = newText
1364 # Extraneous whitespace removed. 1364 # Extraneous whitespace removed.
1365 return (1, "FE251", 0) 1365 return (1, "FIXE251", 0)
1366 1366
1367 def __fixE261(self, code, line, pos): 1367 def __fixE261(self, code, line, pos):
1368 """ 1368 """
1369 Private method to fix whitespace before or after inline comment. 1369 Private method to fix whitespace before or after inline comment.
1370 1370
1382 left = text[:pos].rstrip(' \t#') 1382 left = text[:pos].rstrip(' \t#')
1383 right = text[pos:].lstrip(' \t#') 1383 right = text[pos:].lstrip(' \t#')
1384 newText = left + (" # " + right if right.strip() else right) 1384 newText = left + (" # " + right if right.strip() else right)
1385 self.__source[line] = newText 1385 self.__source[line] = newText
1386 # Whitespace around comment sign corrected. 1386 # Whitespace around comment sign corrected.
1387 return (1, "FE261", 0) 1387 return (1, "FIXE261", 0)
1388 1388
1389 def __fixBlankLinesBefore(self, code, line, pos, apply=False): 1389 def __fixBlankLinesBefore(self, code, line, pos, apply=False):
1390 """ 1390 """
1391 Private method to fix the need for blank lines before class, function 1391 Private method to fix the need for blank lines before class, function
1392 and method definitions. 1392 and method definitions.
1426 # insert blank lines (one or two) 1426 # insert blank lines (one or two)
1427 while delta < 0: 1427 while delta < 0:
1428 self.__source.insert(line, self.__eol) 1428 self.__source.insert(line, self.__eol)
1429 delta += 1 1429 delta += 1
1430 # %n blank line(s) inserted. 1430 # %n blank line(s) inserted.
1431 return (1, ("FE302+", blankLinesBefore - blanks), 0) 1431 return (1, ("FIXE302+", blankLinesBefore - blanks), 0)
1432 elif delta > 0: 1432 elif delta > 0:
1433 # delete superfluous blank lines 1433 # delete superfluous blank lines
1434 while delta > 0: 1434 while delta > 0:
1435 del self.__source[line - 1] 1435 del self.__source[line - 1]
1436 line -= 1 1436 line -= 1
1437 delta -= 1 1437 delta -= 1
1438 # %n superfluous line(s) removed. 1438 # %n superfluous line(s) removed.
1439 return (1, ("FE302-", blanks - blankLinesBefore), 0) 1439 return (1, ("FIXE302-", blanks - blankLinesBefore), 0)
1440 else: 1440 else:
1441 return (0, "", 0) 1441 return (0, "", 0)
1442 else: 1442 else:
1443 fixId = self.__getID() 1443 fixId = self.__getID()
1444 self.__stack.append((fixId, code, line, pos)) 1444 self.__stack.append((fixId, code, line, pos))
1467 del self.__source[index] 1467 del self.__source[index]
1468 index -= 1 1468 index -= 1
1469 else: 1469 else:
1470 break 1470 break
1471 # Superfluous blank lines after function decorator removed. 1471 # Superfluous blank lines after function decorator removed.
1472 return (1, "FE304", 0) 1472 return (1, "FIXE304", 0)
1473 else: 1473 else:
1474 fixId = self.__getID() 1474 fixId = self.__getID()
1475 self.__stack.append((fixId, code, line, pos)) 1475 self.__stack.append((fixId, code, line, pos))
1476 return (-1, "", fixId) 1476 return (-1, "", fixId)
1477 1477
1509 "import " + 1509 "import " +
1510 text[pos:].lstrip("\t ,") 1510 text[pos:].lstrip("\t ,")
1511 ) 1511 )
1512 self.__source[line] = newText 1512 self.__source[line] = newText
1513 # Imports were put on separate lines. 1513 # Imports were put on separate lines.
1514 return (1, "FE401", 0) 1514 return (1, "FIXE401", 0)
1515 else: 1515 else:
1516 fixId = self.__getID() 1516 fixId = self.__getID()
1517 self.__stack.append((fixId, code, line, pos)) 1517 self.__stack.append((fixId, code, line, pos))
1518 return (-1, "", fixId) 1518 return (-1, "", fixId)
1519 1519
1558 if newNextText and newNextText != nextText: 1558 if newNextText and newNextText != nextText:
1559 if newNextText == " ": 1559 if newNextText == " ":
1560 newNextText = "" 1560 newNextText = ""
1561 self.__source[line + 1] = newNextText 1561 self.__source[line + 1] = newNextText
1562 # Long lines have been shortened. 1562 # Long lines have been shortened.
1563 return (1, "FE501", 0) 1563 return (1, "FIXE501", 0)
1564 else: 1564 else:
1565 return (0, "", 0) 1565 return (0, "", 0)
1566 else: 1566 else:
1567 fixId = self.__getID() 1567 fixId = self.__getID()
1568 self.__stack.append((fixId, code, line, pos)) 1568 self.__stack.append((fixId, code, line, pos))
1584 self.__source[line - 1] = ( 1584 self.__source[line - 1] = (
1585 self.__source[line - 1].rstrip("\n\r \t\\") + 1585 self.__source[line - 1].rstrip("\n\r \t\\") +
1586 self.__eol 1586 self.__eol
1587 ) 1587 )
1588 # Redundant backslash in brackets removed. 1588 # Redundant backslash in brackets removed.
1589 return (1, "FE502", 0) 1589 return (1, "FIXE502", 0)
1590 1590
1591 def __fixE701(self, code, line, pos, apply=False): 1591 def __fixE701(self, code, line, pos, apply=False):
1592 """ 1592 """
1593 Private method to fix colon-separated compound statements. 1593 Private method to fix colon-separated compound statements.
1594 1594
1616 text[pos:].lstrip("\n\r \t\\") + 1616 text[pos:].lstrip("\n\r \t\\") +
1617 self.__eol 1617 self.__eol
1618 ) 1618 )
1619 self.__source[line] = newText 1619 self.__source[line] = newText
1620 # Compound statement corrected. 1620 # Compound statement corrected.
1621 return (1, "FE701", 0) 1621 return (1, "FIXE701", 0)
1622 else: 1622 else:
1623 fixId = self.__getID() 1623 fixId = self.__getID()
1624 self.__stack.append((fixId, code, line, pos)) 1624 self.__stack.append((fixId, code, line, pos))
1625 return (-1, "", fixId) 1625 return (-1, "", fixId)
1626 1626
1652 else: 1652 else:
1653 first = text[:pos].rstrip("\n\r \t;") + self.__eol 1653 first = text[:pos].rstrip("\n\r \t;") + self.__eol
1654 second = text[pos:].lstrip("\n\r \t;") 1654 second = text[pos:].lstrip("\n\r \t;")
1655 self.__source[line] = first + self.__getIndent(text) + second 1655 self.__source[line] = first + self.__getIndent(text) + second
1656 # Compound statement corrected. 1656 # Compound statement corrected.
1657 return (1, "FE702", 0) 1657 return (1, "FIXE702", 0)
1658 else: 1658 else:
1659 fixId = self.__getID() 1659 fixId = self.__getID()
1660 self.__stack.append((fixId, code, line, pos)) 1660 self.__stack.append((fixId, code, line, pos))
1661 return (-1, "", fixId) 1661 return (-1, "", fixId)
1662 1662
1694 else: 1694 else:
1695 return (0, "", 0) 1695 return (0, "", 0)
1696 1696
1697 self.__source[line] = " ".join([left, center, right]) 1697 self.__source[line] = " ".join([left, center, right])
1698 # Comparison to None/True/False corrected. 1698 # Comparison to None/True/False corrected.
1699 return (1, "FE711", 0) 1699 return (1, "FIXE711", 0)
1700 1700
1701 def __fixN804(self, code, line, pos, apply=False): 1701 def __fixN804(self, code, line, pos, apply=False):
1702 """ 1702 """
1703 Private method to fix a wrong first argument of normal and 1703 Private method to fix a wrong first argument of normal and
1704 class methods. 1704 class methods.
1740 else: 1740 else:
1741 center = arg + ", " 1741 center = arg + ", "
1742 newText = left + center + right 1742 newText = left + center + right
1743 self.__source[line] = newText 1743 self.__source[line] = newText
1744 # '{0}' argument added. 1744 # '{0}' argument added.
1745 return (1, ("FN804", (arg,)), 0) 1745 return (1, ("FIXN804", (arg,)), 0)
1746 else: 1746 else:
1747 fixId = self.__getID() 1747 fixId = self.__getID()
1748 self.__stack.append((fixId, code, line, pos)) 1748 self.__stack.append((fixId, code, line, pos))
1749 return (-1, "", fixId) 1749 return (-1, "", fixId)
1750 1750
1802 self.__source[line] = "" 1802 self.__source[line] = ""
1803 else: 1803 else:
1804 self.__source[line] = indent + right 1804 self.__source[line] = indent + right
1805 1805
1806 # '{0}' argument removed. 1806 # '{0}' argument removed.
1807 return (1, ("FN806", arg), 0) 1807 return (1, ("FIXN806", arg), 0)
1808 else: 1808 else:
1809 fixId = self.__getID() 1809 fixId = self.__getID()
1810 self.__stack.append((fixId, code, line, pos)) 1810 self.__stack.append((fixId, code, line, pos))
1811 return (-1, "", fixId) 1811 return (-1, "", fixId)
1812 1812
1824 fix (integer) 1824 fix (integer)
1825 """ 1825 """
1826 self.__source[line - 1] = re.sub(r'[\t ]+(\r?)$', r"\1", 1826 self.__source[line - 1] = re.sub(r'[\t ]+(\r?)$', r"\1",
1827 self.__source[line - 1]) 1827 self.__source[line - 1])
1828 # Whitespace stripped from end of line. 1828 # Whitespace stripped from end of line.
1829 return (1, "FW291", 0) 1829 return (1, "FIXW291", 0)
1830 1830
1831 def __fixW292(self, code, line, pos): 1831 def __fixW292(self, code, line, pos):
1832 """ 1832 """
1833 Private method to fix a missing newline at the end of file. 1833 Private method to fix a missing newline at the end of file.
1834 1834
1841 a message for the fix (string) and an ID for a deferred 1841 a message for the fix (string) and an ID for a deferred
1842 fix (integer) 1842 fix (integer)
1843 """ 1843 """
1844 self.__source[line - 1] += self.__eol 1844 self.__source[line - 1] += self.__eol
1845 # newline added to end of file. 1845 # newline added to end of file.
1846 return (1, "FW292", 0) 1846 return (1, "FIXW292", 0)
1847 1847
1848 def __fixW391(self, code, line, pos): 1848 def __fixW391(self, code, line, pos):
1849 """ 1849 """
1850 Private method to fix trailing blank lines. 1850 Private method to fix trailing blank lines.
1851 1851
1864 del self.__source[index] 1864 del self.__source[index]
1865 index -= 1 1865 index -= 1
1866 else: 1866 else:
1867 break 1867 break
1868 # Superfluous trailing blank lines removed from end of file. 1868 # Superfluous trailing blank lines removed from end of file.
1869 return (1, "FW391", 0) 1869 return (1, "FIXW391", 0)
1870 1870
1871 def __fixW603(self, code, line, pos): 1871 def __fixW603(self, code, line, pos):
1872 """ 1872 """
1873 Private method to fix the not equal notation. 1873 Private method to fix the not equal notation.
1874 1874
1881 a message for the fix (string) and an ID for a deferred 1881 a message for the fix (string) and an ID for a deferred
1882 fix (integer) 1882 fix (integer)
1883 """ 1883 """
1884 self.__source[line - 1] = self.__source[line - 1].replace("<>", "!=") 1884 self.__source[line - 1] = self.__source[line - 1].replace("<>", "!=")
1885 # '<>' replaced by '!='. 1885 # '<>' replaced by '!='.
1886 return (1, "FW603", 0) 1886 return (1, "FIXW603", 0)
1887 1887
1888 1888
1889 class Reindenter(object): 1889 class Reindenter(object):
1890 """ 1890 """
1891 Class to reindent badly-indented code to uniformly use four-space 1891 Class to reindent badly-indented code to uniformly use four-space

eric ide

mercurial