Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py

Mon, 02 Mar 2015 19:02:05 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 02 Mar 2015 19:02:05 +0100
changeset 4150
a0cece581ad0
parent 4021
195a471c327b
child 4445
5636dc48e1a0
permissions
-rw-r--r--

Fixed an issue in the code style fixer related to docstrings enclosed in ' or " quotes.

849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
4021
195a471c327b Updated copyright for 2015.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3745
diff changeset
3 # Copyright (c) 2011 - 2015 Detlev Offenbach <detlev@die-offenbachs.de>
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
2912
9ff696796092 Changed some display and source docu strings in the code style checker to make them more universal because the scope goes beyond PEP-8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2895
diff changeset
7 Module implementing a class to fix certain code style issues.
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3745
4c6f1782f530 Possible exception on fixing code styles fixed (only Python2).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3621
diff changeset
10 from __future__ import unicode_literals
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
11 try:
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
12 # Python 2
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
13 from StringIO import StringIO # __IGNORE_EXCEPTION__
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
14 except ImportError:
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
15 # Python 3
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
16 from io import StringIO # __IGNORE_WARNING__
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import os
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import re
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
19 import tokenize
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
3228
f489068e51e8 Bugfixes to work under Python3 and unicode issues for Python2 fixed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
21 # CodeStyleCheckerDialog tries to import FixableCodeStyleIssues what fail under
f489068e51e8 Bugfixes to work under Python3 and unicode issues for Python2 fixed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
22 # Python3. So ignore it.
f489068e51e8 Bugfixes to work under Python3 and unicode issues for Python2 fixed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
23 try:
f489068e51e8 Bugfixes to work under Python3 and unicode issues for Python2 fixed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
24 import pep8
f489068e51e8 Bugfixes to work under Python3 and unicode issues for Python2 fixed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
25 except ImportError:
f489068e51e8 Bugfixes to work under Python3 and unicode issues for Python2 fixed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
26 pass
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
2978
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
28 FixableCodeStyleIssues = [
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
29 "D111", "D112", "D113", "D121", "D131", "D141",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
30 "D142", "D143", "D144", "D145",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
31 "D221", "D222", "D231", "D242", "D243", "D244",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
32 "D245", "D246", "D247",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
33 "E101", "E111", "E121", "E122", "E123", "E124",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
34 "E125", "E126", "E127", "E128", "E133", "E201",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
35 "E202", "E203", "E211", "E221", "E222", "E223",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
36 "E224", "E225", "E226", "E227", "E228", "E231",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
37 "E241", "E242", "E251", "E261", "E262", "E271",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
38 "E272", "E273", "E274", "E301", "E302", "E303",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
39 "E304", "E401", "E501", "E502", "E701", "E702",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
40 "E703", "E711", "E712",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
41 "N804", "N805", "N806",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
42 "W191", "W291", "W292", "W293", "W391", "W603",
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
43 ]
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 869
diff changeset
45
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
46 class CodeStyleFixer(object):
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
2912
9ff696796092 Changed some display and source docu strings in the code style checker to make them more universal because the scope goes beyond PEP-8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2895
diff changeset
48 Class implementing a fixer for certain code style issues.
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
50 def __init__(self, filename, sourceLines, fixCodes, noFixCodes,
3549
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
51 maxLineLength, inPlace, eol, backup=False):
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 Constructor
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 @param filename name of the file to be fixed (string)
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 @param sourceLines list of source lines including eol marker
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 (list of string)
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @param fixCodes list of codes to be fixed as a comma separated
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 string (string)
2876
bfa39cf40277 Extended the PEP-8 dialog to select fixable issues manually (i.e. fix only the selected issues).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2875
diff changeset
60 @param noFixCodes list of codes not to be fixed as a comma
bfa39cf40277 Extended the PEP-8 dialog to select fixable issues manually (i.e. fix only the selected issues).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2875
diff changeset
61 separated string (string)
bfa39cf40277 Extended the PEP-8 dialog to select fixable issues manually (i.e. fix only the selected issues).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2875
diff changeset
62 @param maxLineLength maximum allowed line length (integer)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 @param inPlace flag indicating to modify the file in place (boolean)
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
64 @param eol end of line character(s) (string)
3549
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
65 @param backup flag indicating to create a backup before fixing
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
66 anything (boolean)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 """
3057
10516539f238 Merge with default branch after shorten the code lines to max. 79 characters.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3056 2982
diff changeset
68 super(CodeStyleFixer, self).__init__()
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 self.__filename = filename
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__origName = ""
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__source = sourceLines[:] # save a copy
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__fixCodes = [c.strip() for c in fixCodes.split(",") if c.strip()]
2883
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
74 self.__noFixCodes = [
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
75 c.strip() for c in noFixCodes.split(",") if c.strip()]
2876
bfa39cf40277 Extended the PEP-8 dialog to select fixable issues manually (i.e. fix only the selected issues).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2875
diff changeset
76 self.__maxLineLength = maxLineLength
853
ec7dd115e26b Continued implementing a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 852
diff changeset
77 self.fixed = 0
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
79 self.__reindenter = None
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
80 self.__indentWord = self.__getIndentWord()
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
81
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
82 if inPlace:
3549
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
83 self.__createBackup = backup
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
84 else:
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.__origName = self.__filename
2892
b601ede6dbbf Fixed a few issues in the PEP-8 fixer and made it PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2891
diff changeset
86 self.__filename = os.path.join(
b601ede6dbbf Fixed a few issues in the PEP-8 fixer and made it PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2891
diff changeset
87 os.path.dirname(self.__filename),
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 "fixed_" + os.path.basename(self.__filename))
3549
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
89 self.__createBackup = False
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
90 self.__eol = eol
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
91
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.__fixes = {
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
93 "D111": self.__fixD111,
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
94 "D112": self.__fixD112,
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
95 "D113": self.__fixD112,
2923
01ac1f364b38 Started extending the PEP-8 fixer to correct PEP-257 issues as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2921
diff changeset
96 "D121": self.__fixD121,
01ac1f364b38 Started extending the PEP-8 fixer to correct PEP-257 issues as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2921
diff changeset
97 "D131": self.__fixD131,
01ac1f364b38 Started extending the PEP-8 fixer to correct PEP-257 issues as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2921
diff changeset
98 "D141": self.__fixD141,
01ac1f364b38 Started extending the PEP-8 fixer to correct PEP-257 issues as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2921
diff changeset
99 "D142": self.__fixD142,
01ac1f364b38 Started extending the PEP-8 fixer to correct PEP-257 issues as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2921
diff changeset
100 "D143": self.__fixD143,
01ac1f364b38 Started extending the PEP-8 fixer to correct PEP-257 issues as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2921
diff changeset
101 "D144": self.__fixD144,
01ac1f364b38 Started extending the PEP-8 fixer to correct PEP-257 issues as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2921
diff changeset
102 "D145": self.__fixD145,
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
103 "D221": self.__fixD221,
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
104 "D222": self.__fixD221,
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
105 "D231": self.__fixD131,
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
106 "D242": self.__fixD242,
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
107 "D243": self.__fixD243,
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
108 "D244": self.__fixD242,
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
109 "D245": self.__fixD243,
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
110 "D246": self.__fixD144,
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
111 "D247": self.__fixD247,
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
112 "E101": self.__fixE101,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
113 "E111": self.__fixE101,
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
114 "E121": self.__fixE121,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
115 "E122": self.__fixE122,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
116 "E123": self.__fixE123,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
117 "E124": self.__fixE121,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
118 "E125": self.__fixE125,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
119 "E126": self.__fixE126,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
120 "E127": self.__fixE127,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
121 "E128": self.__fixE127,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
122 "E133": self.__fixE126,
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
123 "E201": self.__fixE201,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
124 "E202": self.__fixE201,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
125 "E203": self.__fixE201,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
126 "E211": self.__fixE201,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
127 "E221": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
128 "E222": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
129 "E223": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
130 "E224": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
131 "E225": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
132 "E226": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
133 "E227": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
134 "E228": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
135 "E231": self.__fixE231,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
136 "E241": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
137 "E242": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
138 "E251": self.__fixE251,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
139 "E261": self.__fixE261,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
140 "E262": self.__fixE261,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
141 "E271": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
142 "E272": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
143 "E273": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
144 "E274": self.__fixE221,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
145 "E301": self.__fixE301,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
146 "E302": self.__fixE302,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
147 "E303": self.__fixE303,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
148 "E304": self.__fixE304,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
149 "E401": self.__fixE401,
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
150 "E501": self.__fixE501,
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
151 "E502": self.__fixE502,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
152 "E701": self.__fixE701,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
153 "E702": self.__fixE702,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
154 "E703": self.__fixE702,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
155 "E711": self.__fixE711,
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
156 "E712": self.__fixE711,
2895
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
157 "N804": self.__fixN804,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
158 "N805": self.__fixN804,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
159 "N806": self.__fixN806,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
160 "W191": self.__fixE101,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
161 "W291": self.__fixW291,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
162 "W292": self.__fixW292,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
163 "W293": self.__fixW291,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
164 "W391": self.__fixW391,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
165 "W603": self.__fixW603,
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 }
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 self.__modified = False
3621
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3549
diff changeset
168 self.__stackLogical = []
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3549
diff changeset
169 # These need to be fixed before the file is saved but after all
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3549
diff changeset
170 # other inline fixes. These work with logical lines.
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3549
diff changeset
171 self.__stack = []
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3549
diff changeset
172 # These need to be fixed before the file is saved but after all
15f23ed3f216 Fixed a few source code style issues found by the updated pe8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3549
diff changeset
173 # inline fixes.
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
174
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
175 self.__multiLineNumbers = None
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
176 self.__docLineNumbers = None
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
177
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
178 self.__lastID = 0
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 def saveFile(self, encoding):
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 """
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 Public method to save the modified file.
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 @param encoding encoding of the source file (string)
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
185 @return error message on failure (tuple of str)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
187 import codecs
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
188
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 if not self.__modified:
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 # no need to write
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
191 return
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192
3549
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
193 if self.__createBackup:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
194 # create a backup file before writing any changes
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
195 if os.path.islink(self.__filename):
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
196 bfn = '{0}~'.format(os.path.realpath(self.__filename))
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
197 else:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
198 bfn = '{0}~'.format(self.__filename)
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
199 try:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
200 os.remove(bfn)
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
201 except EnvironmentError:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
202 # if there was an error, ignore it
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
203 pass
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
204 try:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
205 os.rename(self.__filename, bfn)
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
206 except EnvironmentError:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
207 # if there was an error, ignore it
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
208 pass
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
209
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 txt = "".join(self.__source)
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 try:
3745
4c6f1782f530 Possible exception on fixing code styles fixed (only Python2).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3621
diff changeset
212 enc = 'utf-8' if encoding == 'utf-8-bom' else encoding
4c6f1782f530 Possible exception on fixing code styles fixed (only Python2).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3621
diff changeset
213 txt = txt.encode(enc)
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
214 if encoding == 'utf-8-bom':
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
215 txt = codecs.BOM_UTF8 + txt
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
216
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
217 with open(self.__filename, "wb") as fp:
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
218 fp.write(txt)
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
219 except (IOError, UnicodeError) as err:
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
220 # Could not save the file! Skipping it. Reason: {0}
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
221 return ("FWRITE_ERROR", (str(err),))
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
222 return
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223
2878
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
224 def __codeMatch(self, code):
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
225 """
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
226 Private method to check, if the code should be fixed.
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
227
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
228 @param code to check (string)
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
229 @return flag indicating it should be fixed (boolean)
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
230 """
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
231 def mutualStartswith(a, b):
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
232 """
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
233 Local helper method to compare the beginnings of two strings
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
234 against each other.
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
235
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
236 @return flag indicating that one string starts with the other
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
237 (boolean)
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
238 """
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
239 return b.startswith(a) or a.startswith(b)
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
240
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
241 if self.__noFixCodes:
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
242 for noFixCode in [c.strip() for c in self.__noFixCodes]:
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
243 if mutualStartswith(code.lower(), noFixCode.lower()):
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
244 return False
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
245
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
246 if self.__fixCodes:
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
247 for fixCode in [c.strip() for c in self.__fixCodes]:
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
248 if mutualStartswith(code.lower(), fixCode.lower()):
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
249 return True
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
250 return False
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
251
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
252 return True
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
253
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 def fixIssue(self, line, pos, message):
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 """
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 Public method to fix the fixable issues.
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257
1031
c0f795aa71a7 Fixed an issue in the PEP-8 fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
258 @param line line number of issue (integer)
c0f795aa71a7 Fixed an issue in the PEP-8 fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
259 @param pos character position of issue (integer)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 @param message message text (string)
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
261 @return value indicating an applied/deferred fix (-1, 0, 1),
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
262 a message for the fix (string) and an ID for a deferred
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
263 fix (integer)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 """
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
265 if isinstance(message, (tuple, list)):
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
266 code = message[0].strip()
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
267 else:
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
268 code = message.split(None, 1)[0].strip()
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269
1031
c0f795aa71a7 Fixed an issue in the PEP-8 fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
270 if line <= len(self.__source) and \
2878
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
271 self.__codeMatch(code) and \
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 code in self.__fixes:
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 res = self.__fixes[code](code, line, pos)
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
274 if res[0] == 1:
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 self.__modified = True
853
ec7dd115e26b Continued implementing a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 852
diff changeset
276 self.fixed += 1
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 else:
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
278 res = (0, "", 0)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 return res
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
282 def finalize(self):
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 """
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
284 Public method to apply all deferred fixes.
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
285
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
286 @return dictionary containing the fix results
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 """
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
288 results = {}
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
289
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
290 # step 1: do fixes operating on logical lines first
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
291 for id_, code, line, pos in self.__stackLogical:
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
292 res, msg, _ = self.__fixes[code](code, line, pos, apply=True)
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
293 if res == 1:
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
294 self.__modified = True
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
295 self.fixed += 1
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
296 results[id_] = (res, msg)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
297
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
298 # step 2: do fixes that change the number of lines
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
299 for id_, code, line, pos in reversed(self.__stack):
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
300 res, msg, _ = self.__fixes[code](code, line, pos, apply=True)
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
301 if res == 1:
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
302 self.__modified = True
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
303 self.fixed += 1
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
304 results[id_] = (res, msg)
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
305
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
306 return results
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
307
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
308 def __getID(self):
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
309 """
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
310 Private method to get the ID for a deferred fix.
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
311
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
312 @return ID for a deferred fix (integer)
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
313 """
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
314 self.__lastID += 1
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
315 return self.__lastID
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
317 def __findLogical(self):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
318 """
2883
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
319 Private method to extract the index of all the starts and ends of
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
320 lines.
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
321
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
322 @return tuple containing two lists of integer with start and end tuples
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
323 of lines
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
324 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
325 logical_start = []
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
326 logical_end = []
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
327 last_newline = True
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
328 sio = StringIO("".join(self.__source))
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
329 parens = 0
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
330 for t in tokenize.generate_tokens(sio.readline):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
331 if t[0] in [tokenize.COMMENT, tokenize.DEDENT,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
332 tokenize.INDENT, tokenize.NL,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
333 tokenize.ENDMARKER]:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
334 continue
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
335 if not parens and t[0] in [tokenize.NEWLINE, tokenize.SEMI]:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
336 last_newline = True
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
337 logical_end.append((t[3][0] - 1, t[2][1]))
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
338 continue
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
339 if last_newline and not parens:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
340 logical_start.append((t[2][0] - 1, t[2][1]))
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
341 last_newline = False
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
342 if t[0] == tokenize.OP:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
343 if t[1] in '([{':
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
344 parens += 1
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
345 elif t[1] in '}])':
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
346 parens -= 1
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
347 return logical_start, logical_end
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
348
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
349 def __getLogical(self, line, pos):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
350 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
351 Private method to get the logical line corresponding to the given
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
352 position.
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
353
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
354 @param line line number of the issue (integer)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
355 @param pos position inside line (integer)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
356 @return tuple of a tuple of two integers giving the start of the
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
357 logical line, another tuple of two integers giving the end
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
358 of the logical line and a list of strings with the original
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
359 source lines
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
360 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
361 try:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
362 (logical_start, logical_end) = self.__findLogical()
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
363 except (SyntaxError, tokenize.TokenError):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
364 return None
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
365
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
366 line = line - 1
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
367 ls = None
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
368 le = None
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
369 for i in range(0, len(logical_start)):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
370 x = logical_end[i]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
371 if x[0] > line or (x[0] == line and x[1] > pos):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
372 le = x
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
373 ls = logical_start[i]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
374 break
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
375 if ls is None:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
376 return None
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
377
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
378 original = self.__source[ls[0]:le[0] + 1]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
379 return ls, le, original
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
380
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
381 def __getIndentWord(self):
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
382 """
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
383 Private method to determine the indentation type.
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
385 @return string to be used for an indentation (string)
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
386 """
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
387 sio = StringIO("".join(self.__source))
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
388 indentWord = " " # default in case of failure
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
389 try:
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
390 for token in tokenize.generate_tokens(sio.readline):
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
391 if token[0] == tokenize.INDENT:
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
392 indentWord = token[1]
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
393 break
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
394 except (SyntaxError, tokenize.TokenError):
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
395 pass
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
396 return indentWord
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
397
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
398 def __getIndent(self, line):
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
399 """
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
400 Private method to get the indentation string.
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
401
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
402 @param line line to determine the indentation string from (string)
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
403 @return indentation string (string)
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
404 """
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
405 return line.replace(line.lstrip(), "")
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
406
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
407 def __multilineStringLines(self):
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
408 """
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
409 Private method to determine the line numbers that are within multi line
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
410 strings and these which are part of a documentation string.
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
411
2883
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
412 @return tuple of a set of line numbers belonging to a multi line
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
413 string and a set of line numbers belonging to a multi line
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
414 documentation string (tuple of two set of integer)
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
415 """
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
416 if self.__multiLineNumbers is None:
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
417 source = "".join(self.__source)
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
418 sio = StringIO(source)
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
419 self.__multiLineNumbers = set()
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
420 self.__docLineNumbers = set()
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
421 previousTokenType = ''
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
422 try:
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
423 for t in tokenize.generate_tokens(sio.readline):
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
424 tokenType = t[0]
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
425 startRow = t[2][0]
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
426 endRow = t[3][0]
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
427
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
428 if (tokenType == tokenize.STRING and startRow != endRow):
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
429 if previousTokenType != tokenize.INDENT:
2883
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
430 self.__multiLineNumbers |= set(
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
431 range(startRow, 1 + endRow))
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
432 else:
2883
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
433 self.__docLineNumbers |= set(
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
434 range(startRow, 1 + endRow))
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
435
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
436 previousTokenType = tokenType
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
437 except (SyntaxError, tokenize.TokenError):
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
438 pass
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
439
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
440 return self.__multiLineNumbers, self.__docLineNumbers
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
441
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
442 def __fixReindent(self, line, pos, logical):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
443 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
444 Private method to fix a badly indented line.
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
445
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
446 This is done by adding or removing from its initial indent only.
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
447
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
448 @param line line number of the issue (integer)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
449 @param pos position inside line (integer)
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
450 @param logical logical line structure
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
451 @return flag indicating a change was done (boolean)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
452 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
453 assert logical
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
454 ls, _, original = logical
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
455
2978
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
456 rewrapper = IndentationWrapper(original)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
457 valid_indents = rewrapper.pep8Expected()
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
458 if not rewrapper.rel_indent:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
459 return False
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
460
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
461 if line > ls[0]:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
462 # got a valid continuation line number
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
463 row = line - ls[0] - 1
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
464 # always pick the first option for this
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
465 valid = valid_indents[row]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
466 got = rewrapper.rel_indent[row]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
467 else:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
468 return False
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
469
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
470 line1 = ls[0] + row
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
471 # always pick the expected indent, for now.
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
472 indent_to = valid[0]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
473
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
474 if got != indent_to:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
475 orig_line = self.__source[line1]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
476 new_line = ' ' * (indent_to) + orig_line.lstrip()
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
477 if new_line == orig_line:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
478 return False
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
479 else:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
480 self.__source[line1] = new_line
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
481 return True
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
482 else:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
483 return False
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
484
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
485 def __fixWhitespace(self, line, offset, replacement):
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
486 """
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
487 Private method to correct whitespace at the given offset.
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
488
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
489 @param line line to be corrected (string)
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
490 @param offset offset within line (integer)
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
491 @param replacement replacement string (string)
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
492 @return corrected line
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
493 """
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
494 left = line[:offset].rstrip(" \t")
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
495 right = line[offset:].lstrip(" \t")
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
496 if right.startswith("#"):
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
497 return line
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 else:
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
499 return left + replacement + right
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
501 def __fixD111(self, code, line, pos):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
502 """
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
503 Private method to fix docstring enclosed in wrong quotes.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
504
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
505 Codes: D111
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
506
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
507 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
508 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
509 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
510 @return value indicating an applied/deferred fix (-1, 0, 1),
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
511 a message for the fix (string) and an ID for a deferred
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
512 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
513 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
514 line = line - 1
4150
a0cece581ad0 Fixed an issue in the code style fixer related to docstrings enclosed in ' or " quotes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
515 quotes = re.match(r"""\s*[ru]?('''|'|\")""",
a0cece581ad0 Fixed an issue in the code style fixer related to docstrings enclosed in ' or " quotes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
516 self.__source[line]).group(1)
a0cece581ad0 Fixed an issue in the code style fixer related to docstrings enclosed in ' or " quotes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
517 left, right = self.__source[line].split(quotes, 1)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
518 self.__source[line] = left + '"""' + right
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
519 while line < len(self.__source):
4150
a0cece581ad0 Fixed an issue in the code style fixer related to docstrings enclosed in ' or " quotes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
520 if self.__source[line].rstrip().endswith(quotes):
a0cece581ad0 Fixed an issue in the code style fixer related to docstrings enclosed in ' or " quotes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
521 left, right = self.__source[line].rsplit(quotes, 1)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
522 self.__source[line] = left + '"""' + right
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
523 break
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
524 line += 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
525
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
526 # Triple single quotes converted to triple double quotes.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
527 return (1, "FD111", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
528
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
529 def __fixD112(self, code, line, pos):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
530 """
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
531 Private method to fix docstring 'r' or 'u' in leading quotes.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
532
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
533 Codes: D112, D113
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
534
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
535 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
536 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
537 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
538 @return value indicating an applied/deferred fix (-1, 0, 1),
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
539 a message for the fix (string) and an ID for a deferred
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
540 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
541 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
542 line = line - 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
543 if code == "D112":
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
544 insertChar = "r"
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
545 elif code == "D113":
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
546 insertChar = "u"
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
547 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
548 return (0, "", 0)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
549
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
550 newText = self.__getIndent(self.__source[line]) + \
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
551 insertChar + self.__source[line].lstrip()
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
552 self.__source[line] = newText
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
553 # Introductory quotes corrected to be {0}"""
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
554 return (1, ('FD112', (insertChar,)), 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
555
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
556 def __fixD121(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
557 """
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
558 Private method to fix a single line docstring on multiple lines.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
559
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
560 Codes: D121
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
561
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
562 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
563 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
564 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
565 @keyparam apply flag indicating, that the fix should be applied
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
566 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
567 @return value indicating an applied/deferred fix (-1, 0, 1),
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
568 a message for the fix (string) and an ID for a deferred
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
569 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
570 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
571 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
572 line = line - 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
573 if not self.__source[line].lstrip().startswith(
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
574 ('"""', 'r"""', 'u"""')):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
575 # only correctly formatted docstrings will be fixed
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
576 return (0, "", 0)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
577
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
578 docstring = self.__source[line].rstrip() + \
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
579 self.__source[line + 1].strip()
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
580 if docstring.endswith('"""'):
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
581 docstring += self.__eol
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
582 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
583 docstring += self.__source[line + 2].lstrip()
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
584 self.__source[line + 2] = ""
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
585
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
586 self.__source[line] = docstring
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
587 self.__source[line + 1] = ""
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
588 # Single line docstring put on one line.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
589 return (1, "FD121", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
590 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
591 id = self.__getID()
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
592 self.__stack.append((id, code, line, pos))
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
593 return (-1, "", id)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
594
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
595 def __fixD131(self, code, line, pos):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
596 """
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
597 Private method to fix a docstring summary not ending with a
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
598 period.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
599
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
600 Codes: D131
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
601
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
602 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
603 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
604 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
605 @return value indicating an applied/deferred fix (-1, 0, 1),
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
606 a message for the fix (string) and an ID for a deferred
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
607 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
608 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
609 line = line - 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
610 newText = ""
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
611 if self.__source[line].rstrip().endswith(('"""', "'''")) and \
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
612 self.__source[line].lstrip().startswith(('"""', 'r"""', 'u"""')):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
613 # it is a one-liner
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
614 newText = self.__source[line].rstrip()[:-3].rstrip() + "." + \
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
615 self.__source[line].rstrip()[-3:] + self.__eol
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
616 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
617 if line < len(self.__source) - 1 and \
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
618 (not self.__source[line + 1].strip() or
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
619 self.__source[line + 1].lstrip().startswith("@") or
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
620 (self.__source[line + 1].strip() in ('"""', "'''") and
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
621 not self.__source[line].lstrip().startswith("@"))):
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
622 newText = self.__source[line].rstrip() + "." + self.__eol
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
623
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
624 if newText:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
625 self.__source[line] = newText
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
626 # Period added to summary line.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
627 return (1, "FD131", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
628 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
629 return (0, "", 0)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
630
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
631 def __fixD141(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
632 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
633 Private method to fix a function/method docstring preceded by a
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
634 blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
635
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
636 Codes: D141
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
637
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
638 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
639 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
640 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
641 @keyparam apply flag indicating, that the fix should be applied
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
642 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
643 @return value indicating an applied/deferred fix (-1, 0, 1),
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
644 a message for the fix (string) and an ID for a deferred
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
645 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
646 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
647 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
648 line = line - 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
649 self.__source[line - 1] = ""
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
650 # Blank line before function/method docstring removed.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
651 return (1, "FD141", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
652 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
653 id = self.__getID()
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
654 self.__stack.append((id, code, line, pos))
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
655 return (-1, "", id)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
656
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
657 def __fixD142(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
658 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
659 Private method to fix a class docstring not preceded by a
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
660 blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
661
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
662 Codes: D142
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
663
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
664 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
665 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
666 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
667 @keyparam apply flag indicating, that the fix should be applied
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
668 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
669 @return value indicating an applied/deferred fix (-1, 0, 1),
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
670 a message for the fix (string) and an ID for a deferred
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
671 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
672 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
673 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
674 line = line - 1
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
675 self.__source[line] = self.__eol + self.__source[line]
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
676 # Blank line inserted before class docstring.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
677 return (1, "FD142", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
678 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
679 id = self.__getID()
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
680 self.__stack.append((id, code, line, pos))
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
681 return (-1, "", id)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
682
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
683 def __fixD143(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
684 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
685 Private method to fix a class docstring not followed by a
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
686 blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
687
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
688 Codes: D143
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
689
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
690 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
691 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
692 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
693 @keyparam apply flag indicating, that the fix should be applied
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
694 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
695 @return value indicating an applied/deferred fix (-1, 0, 1),
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
696 a message for the fix (string) and an ID for a deferred
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
697 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
698 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
699 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
700 line = line - 1
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
701 self.__source[line] += self.__eol
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
702 # Blank line inserted after class docstring.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
703 return (1, "FD143", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
704 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
705 id = self.__getID()
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
706 self.__stack.append((id, code, line, pos))
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
707 return (-1, "", id)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
708
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
709 def __fixD144(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
710 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
711 Private method to fix a docstring summary not followed by a
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
712 blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
713
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
714 Codes: D144
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
715
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
716 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
717 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
718 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
719 @keyparam apply flag indicating, that the fix should be applied
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
720 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
721 @return value indicating an applied/deferred fix (-1, 0, 1),
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
722 a message for the fix (string) and an ID for a deferred
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
723 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
724 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
725 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
726 line = line - 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
727 if not self.__source[line].rstrip().endswith("."):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
728 # only correct summary lines can be fixed here
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
729 return (0, "", 0)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
730
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
731 self.__source[line] += self.__eol
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
732 # Blank line inserted after docstring summary.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
733 return (1, "FD144", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
734 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
735 id = self.__getID()
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
736 self.__stack.append((id, code, line, pos))
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
737 return (-1, "", id)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
738
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
739 def __fixD145(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
740 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
741 Private method to fix the last paragraph of a multi-line docstring
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
742 not followed by a blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
743
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
744 Codes: D143
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
745
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
746 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
747 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
748 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
749 @keyparam apply flag indicating, that the fix should be applied
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
750 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
751 @return value indicating an applied/deferred fix (-1, 0, 1),
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
752 a message for the fix (string) and an ID for a deferred
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
753 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
754 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
755 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
756 line = line - 1
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
757 self.__source[line] = self.__eol + self.__source[line]
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
758 # Blank line inserted after last paragraph of docstring.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
759 return (1, "FD145", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
760 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
761 id = self.__getID()
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
762 self.__stack.append((id, code, line, pos))
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
763 return (-1, "", id)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
764
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
765 def __fixD221(self, code, line, pos, apply=False):
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
766 """
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
767 Private method to fix leading and trailing quotes of docstring
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
768 not on separate lines.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
769
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
770 Codes: D221, D222
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
771
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
772 @param code code of the issue (string)
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
773 @param line line number of the issue (integer)
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
774 @param pos position inside line (integer)
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
775 @keyparam apply flag indicating, that the fix should be applied
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
776 (boolean)
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
777 @return value indicating an applied/deferred fix (-1, 0, 1),
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
778 a message for the fix (string) and an ID for a deferred
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
779 fix (integer)
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
780 """
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
781 if apply:
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
782 line = line - 1
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
783 indent = self.__getIndent(self.__source[line])
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
784 source = self.__source[line].strip()
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
785 if code == "D221":
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
786 # leading
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
787 if source.startswith(("r", "u")):
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
788 first, second = source[:4], source[4:].strip()
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
789 else:
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
790 first, second = source[:3], source[3:].strip()
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
791 else:
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
792 # trailing
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
793 first, second = source[:-3].strip(), source[-3:]
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
794 newText = indent + first + self.__eol + \
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
795 indent + second + self.__eol
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
796 self.__source[line] = newText
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
797 if code == "D221":
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
798 # Leading quotes put on separate line.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
799 msg = "FD221"
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
800 else:
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
801 # Trailing quotes put on separate line.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
802 msg = "FD222"
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
803 return (1, msg, 0)
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
804 else:
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
805 id = self.__getID()
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
806 self.__stack.append((id, code, line, pos))
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
807 return (-1, "", id)
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
808
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
809 def __fixD242(self, code, line, pos, apply=False):
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
810 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
811 Private method to fix a class or function/method docstring preceded
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
812 by a blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
813
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
814 Codes: D242, D244
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
815
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
816 @param code code of the issue (string)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
817 @param line line number of the issue (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
818 @param pos position inside line (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
819 @keyparam apply flag indicating, that the fix should be applied
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
820 (boolean)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
821 @return value indicating an applied/deferred fix (-1, 0, 1),
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
822 a message for the fix (string) and an ID for a deferred
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
823 fix (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
824 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
825 if apply:
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
826 line = line - 1
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
827 self.__source[line - 1] = ""
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
828 if code == "D242":
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
829 # Blank line before class docstring removed.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
830 msg = "FD242"
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
831 else:
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
832 # Blank line before function/method docstring removed.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
833 msg = "FD244"
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
834 return (1, msg, 0)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
835 else:
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
836 id = self.__getID()
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
837 self.__stack.append((id, code, line, pos))
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
838 return (-1, "", id)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
839
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
840 def __fixD243(self, code, line, pos, apply=False):
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
841 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
842 Private method to fix a class or function/method docstring followed
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
843 by a blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
844
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
845 Codes: D243, D245
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
846
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
847 @param code code of the issue (string)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
848 @param line line number of the issue (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
849 @param pos position inside line (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
850 @keyparam apply flag indicating, that the fix should be applied
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
851 (boolean)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
852 @return value indicating an applied/deferred fix (-1, 0, 1),
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
853 a message for the fix (string) and an ID for a deferred
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
854 fix (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
855 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
856 if apply:
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
857 line = line - 1
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
858 self.__source[line + 1] = ""
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
859 if code == "D243":
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
860 # Blank line after class docstring removed.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
861 msg = "FD243"
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
862 else:
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
863 # Blank line after function/method docstring removed.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
864 msg = "FD245"
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
865 return (1, msg, 0)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
866 else:
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
867 id = self.__getID()
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
868 self.__stack.append((id, code, line, pos))
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
869 return (-1, "", id)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
870
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
871 def __fixD247(self, code, line, pos, apply=False):
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
872 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
873 Private method to fix a last paragraph of a docstring followed
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
874 by a blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
875
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
876 Codes: D247
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
877
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
878 @param code code of the issue (string)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
879 @param line line number of the issue (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
880 @param pos position inside line (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
881 @keyparam apply flag indicating, that the fix should be applied
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
882 (boolean)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
883 @return value indicating an applied/deferred fix (-1, 0, 1),
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
884 a message for the fix (string) and an ID for a deferred
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
885 fix (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
886 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
887 if apply:
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
888 line = line - 1
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
889 self.__source[line - 1] = ""
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
890 # Blank line after last paragraph removed.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
891 return (1, "FD247", 0)
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
892 else:
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
893 id = self.__getID()
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
894 self.__stack.append((id, code, line, pos))
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
895 return (-1, "", id)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
896
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
897 def __fixE101(self, code, line, pos):
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
898 """
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
899 Private method to fix obsolete tab usage and indentation errors.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
900
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
901 Codes: E101, E111, W191
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
902
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
903 @param code code of the issue (string)
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
904 @param line line number of the issue (integer)
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
905 @param pos position inside line (integer)
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
906 @return value indicating an applied/deferred fix (-1, 0, 1),
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
907 a message for the fix (string) and an ID for a deferred
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
908 fix (integer)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
909 """
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
910 if self.__reindenter is None:
2978
9d63132a23e0 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2976
diff changeset
911 self.__reindenter = Reindenter(self.__source)
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
912 self.__reindenter.run()
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
913 fixedLine = self.__reindenter.fixedLine(line - 1)
2892
b601ede6dbbf Fixed a few issues in the PEP-8 fixer and made it PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2891
diff changeset
914 if fixedLine is not None and fixedLine != self.__source[line - 1]:
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
915 self.__source[line - 1] = fixedLine
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
916 if code in ["E101", "W191"]:
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
917 # Tab converted to 4 spaces.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
918 msg = "FE101"
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
919 else:
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
920 # Indentation adjusted to be a multiple of four.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
921 msg = "FE111"
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
922 return (1, msg, 0)
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
923 else:
2892
b601ede6dbbf Fixed a few issues in the PEP-8 fixer and made it PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2891
diff changeset
924 return (0, "", 0)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
925
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
926 def __fixE121(self, code, line, pos, apply=False):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
927 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
928 Private method to fix the indentation of continuation lines and
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
929 closing brackets.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
930
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
931 Codes: E121, E124
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
932
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
933 @param code code of the issue (string)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
934 @param line line number of the issue (integer)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
935 @param pos position inside line (integer)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
936 @keyparam apply flag indicating, that the fix should be applied
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
937 (boolean)
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
938 @return value indicating an applied/deferred fix (-1, 0, 1),
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
939 a message for the fix (string) and an ID for a deferred
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
940 fix (integer)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
941 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
942 if apply:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
943 logical = self.__getLogical(line, pos)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
944 if logical:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
945 # Fix by adjusting initial indent level.
2892
b601ede6dbbf Fixed a few issues in the PEP-8 fixer and made it PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2891
diff changeset
946 changed = self.__fixReindent(line, pos, logical)
b601ede6dbbf Fixed a few issues in the PEP-8 fixer and made it PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2891
diff changeset
947 if changed:
b601ede6dbbf Fixed a few issues in the PEP-8 fixer and made it PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2891
diff changeset
948 if code == "E121":
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
949 # Indentation of continuation line corrected.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
950 msg = "FE121"
2892
b601ede6dbbf Fixed a few issues in the PEP-8 fixer and made it PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2891
diff changeset
951 elif code == "E124":
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
952 # Indentation of closing bracket corrected.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
953 msg = "FE124"
2892
b601ede6dbbf Fixed a few issues in the PEP-8 fixer and made it PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2891
diff changeset
954 return (1, msg, 0)
b601ede6dbbf Fixed a few issues in the PEP-8 fixer and made it PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2891
diff changeset
955 return (0, "", 0)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
956 else:
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
957 id = self.__getID()
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
958 self.__stackLogical.append((id, code, line, pos))
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
959 return (-1, "", id)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
960
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
961 def __fixE122(self, code, line, pos, apply=False):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
962 """
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
963 Private method to fix a missing indentation of continuation lines.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
964
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
965 Codes: E122
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
966
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
967 @param code code of the issue (string)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
968 @param line line number of the issue (integer)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
969 @param pos position inside line (integer)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
970 @keyparam apply flag indicating, that the fix should be applied
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
971 (boolean)
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
972 @return value indicating an applied/deferred fix (-1, 0, 1),
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
973 a message for the fix (string) and an ID for a deferred
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
974 fix (integer)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
975 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
976 if apply:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
977 logical = self.__getLogical(line, pos)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
978 if logical:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
979 # Fix by adding an initial indent.
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
980 modified = self.__fixReindent(line, pos, logical)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
981 if not modified:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
982 # fall back to simple method
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
983 line = line - 1
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
984 text = self.__source[line]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
985 indentation = self.__getIndent(text)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
986 self.__source[line] = indentation + \
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
987 self.__indentWord + text.lstrip()
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
988 # Missing indentation of continuation line corrected.
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
989 return (1, "FE122", 0)
2892
b601ede6dbbf Fixed a few issues in the PEP-8 fixer and made it PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2891
diff changeset
990 return (0, "", 0)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
991 else:
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
992 id = self.__getID()
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
993 self.__stackLogical.append((id, code, line, pos))
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
994 return (-1, "", id)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
995
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
996 def __fixE123(self, code, line, pos, apply=False):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
997 """
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
998 Private method to fix the indentation of a closing bracket lines.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
999
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
1000 Codes: E123
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1001
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1002 @param code code of the issue (string)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1003 @param line line number of the issue (integer)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1004 @param pos position inside line (integer)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1005 @keyparam apply flag indicating, that the fix should be applied
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1006 (boolean)
2891
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
1007 @return value indicating an applied/deferred fix (-1, 0, 1),
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
1008 a message for the fix (string) and an ID for a deferred
6843b7d23279 Changed the PEP-8 fixer and dialog to decouple the indication of the fixed status from the generation of the PEP-8 status.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2890
diff changeset
1009 fix (integer)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1010 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1011 if apply:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1012 logical = self.__getLogical(line, pos)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1013 if logical:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1014 # Fix by deleting whitespace to the correct level.
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1015 logicalLines = logical[2]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1016 row = line - 1
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1017 text = self.__source[row]