src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py

branch
eric7
changeset 10069
435cc5875135
parent 10060
b946699e9e79
child 10437
2f70ca07f0af
equal deleted inserted replaced
10068:7febcdccb2a1 10069:435cc5875135
518 518
519 previousTokenType = tokenType 519 previousTokenType = tokenType
520 520
521 return self.__multiLineNumbers, self.__docLineNumbers 521 return self.__multiLineNumbers, self.__docLineNumbers
522 522
523 def __fixReindent(self, line, pos, logical): 523 def __fixReindent(self, line, pos, logical): # noqa: U100
524 """ 524 """
525 Private method to fix a badly indented line. 525 Private method to fix a badly indented line.
526 526
527 This is done by adding or removing from its initial indent only. 527 This is done by adding or removing from its initial indent only.
528 528
580 if right.startswith("#"): 580 if right.startswith("#"):
581 return line 581 return line
582 else: 582 else:
583 return left + replacement + right 583 return left + replacement + right
584 584
585 def __fixD111(self, code, line, pos): 585 def __fixD111(self, code, line, pos): # noqa: U100
586 """ 586 """
587 Private method to fix docstring enclosed in wrong quotes. 587 Private method to fix docstring enclosed in wrong quotes.
588 588
589 Codes: D111 589 Codes: D111
590 590
611 line += 1 611 line += 1
612 612
613 # Triple single quotes converted to triple double quotes. 613 # Triple single quotes converted to triple double quotes.
614 return (1, "FIXD111", [], 0) 614 return (1, "FIXD111", [], 0)
615 615
616 def __fixD112(self, code, line, pos): 616 def __fixD112(self, code, line, pos): # noqa: U100
617 """ 617 """
618 Private method to fix docstring 'r' in leading quotes. 618 Private method to fix docstring 'r' in leading quotes.
619 619
620 Codes: D112 620 Codes: D112
621 621
684 else: 684 else:
685 fixId = self.__getID() 685 fixId = self.__getID()
686 self.__stack.append((fixId, code, line, pos)) 686 self.__stack.append((fixId, code, line, pos))
687 return (-1, "", [], fixId) 687 return (-1, "", [], fixId)
688 688
689 def __fixD131(self, code, line, pos): 689 def __fixD131(self, code, line, pos): # noqa: U100
690 """ 690 """
691 Private method to fix a docstring summary not ending with a 691 Private method to fix a docstring summary not ending with a
692 period. 692 period.
693 693
694 Codes: D131 694 Codes: D131
1033 else: 1033 else:
1034 fixId = self.__getID() 1034 fixId = self.__getID()
1035 self.__stack.append((fixId, code, line, pos)) 1035 self.__stack.append((fixId, code, line, pos))
1036 return (-1, "", [], fixId) 1036 return (-1, "", [], fixId)
1037 1037
1038 def __fixE101(self, code, line, pos): 1038 def __fixE101(self, code, line, pos): # noqa: U100
1039 """ 1039 """
1040 Private method to fix obsolete tab usage and indentation errors. 1040 Private method to fix obsolete tab usage and indentation errors.
1041 1041
1042 Codes: E101, E111, W191 1042 Codes: E101, E111, W191
1043 1043
1335 else: 1335 else:
1336 fixId = self.__getID() 1336 fixId = self.__getID()
1337 self.__stackLogical.append((fixId, code, line, pos)) 1337 self.__stackLogical.append((fixId, code, line, pos))
1338 return (-1, "", [], fixId) 1338 return (-1, "", [], fixId)
1339 1339
1340 def __fixE201(self, code, line, pos): 1340 def __fixE201(self, code, line, pos): # noqa: U100
1341 """ 1341 """
1342 Private method to fix extraneous whitespace. 1342 Private method to fix extraneous whitespace.
1343 1343
1344 Codes: E201, E202, E203, E211 1344 Codes: E201, E202, E203, E211
1345 1345
1366 1366
1367 self.__source[line] = newText 1367 self.__source[line] = newText
1368 # Extraneous whitespace removed. 1368 # Extraneous whitespace removed.
1369 return (1, "FIXE201", [], 0) 1369 return (1, "FIXE201", [], 0)
1370 1370
1371 def __fixE221(self, code, line, pos): 1371 def __fixE221(self, code, line, pos): # noqa: U100
1372 """ 1372 """
1373 Private method to fix extraneous whitespace around operator or 1373 Private method to fix extraneous whitespace around operator or
1374 keyword. 1374 keyword.
1375 1375
1376 Codes: E221, E222, E223, E224, E241, E242, E271, E272, E273, E274 1376 Codes: E221, E222, E223, E224, E241, E242, E271, E272, E273, E274
1397 return (0, "", [], 0) 1397 return (0, "", [], 0)
1398 1398
1399 self.__source[line] = newText 1399 self.__source[line] = newText
1400 return (1, "FIXE221", [], 0) 1400 return (1, "FIXE221", [], 0)
1401 1401
1402 def __fixE225(self, code, line, pos): 1402 def __fixE225(self, code, line, pos): # noqa: U100
1403 """ 1403 """
1404 Private method to fix extraneous whitespaces around operator. 1404 Private method to fix extraneous whitespaces around operator.
1405 1405
1406 Codes: E225, E226, E227, E228 1406 Codes: E225, E226, E227, E228
1407 1407
1442 1442
1443 self.__source[line] = newText 1443 self.__source[line] = newText
1444 # Missing whitespaces added. 1444 # Missing whitespaces added.
1445 return (1, "FIXE225", [], 0) 1445 return (1, "FIXE225", [], 0)
1446 1446
1447 def __fixE231(self, code, line, pos): 1447 def __fixE231(self, code, line, pos): # noqa: U100
1448 """ 1448 """
1449 Private method to fix missing whitespace after ',;:'. 1449 Private method to fix missing whitespace after ',;:'.
1450 1450
1451 Codes: E231 1451 Codes: E231
1452 1452
1467 self.__source[line][:pos] + " " + self.__source[line][pos:] 1467 self.__source[line][:pos] + " " + self.__source[line][pos:]
1468 ) 1468 )
1469 # Missing whitespace added. 1469 # Missing whitespace added.
1470 return (1, "FIXE231", [], 0) 1470 return (1, "FIXE231", [], 0)
1471 1471
1472 def __fixE251(self, code, line, pos): 1472 def __fixE251(self, code, line, pos): # noqa: U100
1473 """ 1473 """
1474 Private method to fix extraneous whitespace around keyword and 1474 Private method to fix extraneous whitespace around keyword and
1475 default parameter equals. 1475 default parameter equals.
1476 1476
1477 Codes: E251 1477 Codes: E251
1505 else: 1505 else:
1506 self.__source[line] = newText 1506 self.__source[line] = newText
1507 # Extraneous whitespace removed. 1507 # Extraneous whitespace removed.
1508 return (1, "FIXE251", [], 0) 1508 return (1, "FIXE251", [], 0)
1509 1509
1510 def __fixE261(self, code, line, pos): 1510 def __fixE261(self, code, line, pos): # noqa: U100
1511 """ 1511 """
1512 Private method to fix whitespace before or after inline comment. 1512 Private method to fix whitespace before or after inline comment.
1513 1513
1514 Codes: E261, E262 1514 Codes: E261, E262
1515 1515
1732 else: 1732 else:
1733 fixId = self.__getID() 1733 fixId = self.__getID()
1734 self.__stack.append((fixId, code, line, pos)) 1734 self.__stack.append((fixId, code, line, pos))
1735 return (-1, "", [], fixId) 1735 return (-1, "", [], fixId)
1736 1736
1737 def __fixE502(self, code, line, pos): 1737 def __fixE502(self, code, line, pos): # noqa: U100
1738 """ 1738 """
1739 Private method to fix redundant backslash within brackets. 1739 Private method to fix redundant backslash within brackets.
1740 1740
1741 Codes: E502 1741 Codes: E502
1742 1742
1835 else: 1835 else:
1836 fixId = self.__getID() 1836 fixId = self.__getID()
1837 self.__stack.append((fixId, code, line, pos)) 1837 self.__stack.append((fixId, code, line, pos))
1838 return (-1, "", [], fixId) 1838 return (-1, "", [], fixId)
1839 1839
1840 def __fixE711(self, code, line, pos): 1840 def __fixE711(self, code, line, pos): # noqa: U100
1841 """ 1841 """
1842 Private method to fix comparison with None. 1842 Private method to fix comparison with None.
1843 1843
1844 Codes: E711, E712 1844 Codes: E711, E712
1845 1845
1995 else: 1995 else:
1996 fixId = self.__getID() 1996 fixId = self.__getID()
1997 self.__stack.append((fixId, code, line, pos)) 1997 self.__stack.append((fixId, code, line, pos))
1998 return (-1, "", [], fixId) 1998 return (-1, "", [], fixId)
1999 1999
2000 def __fixW291(self, code, line, pos): 2000 def __fixW291(self, code, line, pos): # noqa: U100
2001 """ 2001 """
2002 Private method to fix trailing whitespace. 2002 Private method to fix trailing whitespace.
2003 2003
2004 Codes: W291, W293 2004 Codes: W291, W293
2005 2005
2018 r"[\t ]+(\r?)$", r"\1", self.__source[line - 1] 2018 r"[\t ]+(\r?)$", r"\1", self.__source[line - 1]
2019 ) 2019 )
2020 # Whitespace stripped from end of line. 2020 # Whitespace stripped from end of line.
2021 return (1, "FIXW291", [], 0) 2021 return (1, "FIXW291", [], 0)
2022 2022
2023 def __fixW292(self, code, line, pos): 2023 def __fixW292(self, code, line, pos): # noqa: U100
2024 """ 2024 """
2025 Private method to fix a missing newline at the end of file. 2025 Private method to fix a missing newline at the end of file.
2026 2026
2027 Codes: W292 2027 Codes: W292
2028 2028
2039 """ 2039 """
2040 self.__source[line - 1] += self.__eol 2040 self.__source[line - 1] += self.__eol
2041 # newline added to end of file. 2041 # newline added to end of file.
2042 return (1, "FIXW292", [], 0) 2042 return (1, "FIXW292", [], 0)
2043 2043
2044 def __fixW391(self, code, line, pos): 2044 def __fixW391(self, code, line, pos): # noqa: U100
2045 """ 2045 """
2046 Private method to fix trailing blank lines. 2046 Private method to fix trailing blank lines.
2047 2047
2048 Codes: W391 2048 Codes: W391
2049 2049
2066 else: 2066 else:
2067 break 2067 break
2068 # Superfluous trailing blank lines removed from end of file. 2068 # Superfluous trailing blank lines removed from end of file.
2069 return (1, "FIXW391", [], 0) 2069 return (1, "FIXW391", [], 0)
2070 2070
2071 def __fixW603(self, code, line, pos): 2071 def __fixW603(self, code, line, pos): # noqa: U100
2072 """ 2072 """
2073 Private method to fix the not equal notation. 2073 Private method to fix the not equal notation.
2074 2074
2075 Codes: W603 2075 Codes: W603
2076 2076

eric ide

mercurial