eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py

Thu, 04 Jun 2020 17:57:20 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 04 Jun 2020 17:57:20 +0200
changeset 7609
d5aff4fd0ef8
parent 7360
9190402e4505
child 7610
df7025fe26a3
permissions
-rw-r--r--

Code Style Checker: changed the dialog to allow the selection of checker categories.

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
3 # Copyright (c) 2011 - 2020 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:
5147
d39dd5cee0c8 Renamed pep8.py to pycodestyle.py in order to track the upstream renaming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4830
diff changeset
24 import pycodestyle
3228
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",
6264
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
39 "E304", "E305", "E306", "E307", "E308", "E401",
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
40 "E501", "E502", "E701", "E702", "E703", "E711",
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
41 "E712",
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
42 "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
43 "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
44 ]
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 869
diff changeset
46
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
47 class CodeStyleFixer(object):
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 """
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
49 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
50 """
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
51 def __init__(self, filename, sourceLines, fixCodes, noFixCodes,
6264
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
52 maxLineLength, blankLines, inPlace, eol, backup=False):
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 Constructor
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
6264
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
56 @param filename name of the file to be fixed
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
57 @type str
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @param sourceLines list of source lines including eol marker
6264
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
59 @type list of str
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 @param fixCodes list of codes to be fixed as a comma separated
6264
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
61 string
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
62 @type str
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
63 @param noFixCodes list of codes not to be fixed as a comma
6264
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
64 separated string
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
65 @type str
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
66 @param maxLineLength maximum allowed line length
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
67 @type int
6265
56bd09c4c297 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6264
diff changeset
68 @param blankLines tuple containg the number of blank lines before
6264
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
69 a top level class or function and before a method or nested class
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
70 or function
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
71 @type tuple of (int, int)
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
72 @param inPlace flag indicating to modify the file in place
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
73 @type bool
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
74 @param eol end of line character(s)
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
75 @type str
3549
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
76 @param backup flag indicating to create a backup before fixing
6264
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
77 anything
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
78 @type bool
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
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
80 super(CodeStyleFixer, self).__init__()
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.__filename = filename
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.__origName = ""
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 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
85 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
86 self.__noFixCodes = [
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
87 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
88 self.__maxLineLength = maxLineLength
6264
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
89 self.__blankLines = {
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
90 "toplevel": blankLines[0],
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
91 "method": blankLines[1],
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
92 }
853
ec7dd115e26b Continued implementing a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 852
diff changeset
93 self.fixed = 0
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
95 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
96 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
97
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
98 if inPlace:
3549
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
99 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
100 else:
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 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
102 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
103 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
104 "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
105 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
106 self.__eol = eol
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
107
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 self.__fixes = {
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
109 "D111": self.__fixD111,
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
110 "D112": self.__fixD112,
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
111 "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
112 "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
113 "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
114 "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
115 "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
116 "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
117 "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
118 "D145": self.__fixD145,
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
119 "D221": self.__fixD221,
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
120 "D222": self.__fixD221,
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
121 "D231": self.__fixD131,
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
122 "D242": self.__fixD242,
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
123 "D243": self.__fixD243,
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
124 "D244": self.__fixD242,
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
125 "D245": self.__fixD243,
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
126 "D246": self.__fixD144,
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
127 "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
128 "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
129 "E111": self.__fixE101,
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
130 "E121": self.__fixE121,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
131 "E122": self.__fixE122,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
132 "E123": self.__fixE123,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
133 "E124": self.__fixE121,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
134 "E125": self.__fixE125,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
135 "E126": self.__fixE126,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
136 "E127": self.__fixE127,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
137 "E128": self.__fixE127,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
138 "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
139 "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
140 "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
141 "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
142 "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
143 "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
144 "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
145 "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
146 "E224": self.__fixE221,
4445
5636dc48e1a0 Own fixer for missing whitespaces around operators (1 pass fix) implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4150
diff changeset
147 "E225": self.__fixE225,
5636dc48e1a0 Own fixer for missing whitespaces around operators (1 pass fix) implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4150
diff changeset
148 "E226": self.__fixE225,
5636dc48e1a0 Own fixer for missing whitespaces around operators (1 pass fix) implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4150
diff changeset
149 "E227": self.__fixE225,
5636dc48e1a0 Own fixer for missing whitespaces around operators (1 pass fix) implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4150
diff changeset
150 "E228": self.__fixE225,
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 "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
152 "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
153 "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
154 "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
155 "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
156 "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
157 "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
158 "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
159 "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
160 "E274": self.__fixE221,
6264
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
161 "E301": self.__fixBlankLinesBefore,
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
162 "E302": self.__fixBlankLinesBefore,
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
163 "E303": self.__fixBlankLinesBefore,
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
164 "E304": self.__fixE304,
6264
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
165 "E305": self.__fixBlankLinesBefore,
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
166 "E306": self.__fixBlankLinesBefore,
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
167 "E307": self.__fixBlankLinesBefore,
04a671fa4adb code style checker: extended the dialog to be able to define the number of blank lines before class and function/method definitions
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6188
diff changeset
168 "E308": self.__fixBlankLinesBefore,
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
169 "E401": self.__fixE401,
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
170 "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
171 "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
172 "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
173 "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
174 "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
175 "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
176 "E712": self.__fixE711,
2895
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
177 "N804": self.__fixN804,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
178 "N805": self.__fixN804,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
179 "N806": self.__fixN806,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
180 "W191": self.__fixE101,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
181 "W291": self.__fixW291,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
182 "W292": self.__fixW292,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
183 "W293": self.__fixW291,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
184 "W391": self.__fixW391,
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
185 "W603": self.__fixW603,
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 }
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 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
188 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
189 # 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
190 # 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
191 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
192 # 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
193 # inline fixes.
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
194
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
195 self.__multiLineNumbers = None
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
196 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
197
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
198 self.__lastID = 0
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 def saveFile(self, encoding):
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 """
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 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
203
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 @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
205 @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
206 """
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
207 import codecs
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
208
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 if not self.__modified:
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 # no need to write
6891
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
211 return None
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212
3549
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
213 if self.__createBackup:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
214 # 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
215 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
216 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
217 else:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
218 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
219 try:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
220 os.remove(bfn)
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
221 except EnvironmentError:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
222 # 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
223 pass
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
224 try:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
225 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
226 except EnvironmentError:
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
227 # 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
228 pass
96ebf42cd960 Added the file backup functionality in the code style fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3546
diff changeset
229
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 txt = "".join(self.__source)
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 try:
3745
4c6f1782f530 Possible exception on fixing code styles fixed (only Python2).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3621
diff changeset
232 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
233 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
234 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
235 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
236
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
237 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
238 fp.write(txt)
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
239 except (IOError, UnicodeError) as err:
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
240 # Could not save the file! Skipping it. Reason: {0}
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
241 return ("FIXWRITE_ERROR", (str(err),))
6891
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
242
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
243 return None
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244
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
245 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
246 """
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 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
248
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 @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
250 @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
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 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
253 """
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
254 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
255 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
256
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
257 @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
258 (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
259 """
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
260 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
261
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
262 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
263 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
264 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
265 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
266
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
267 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
268 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
269 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
270 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
271 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
272
61042247f793 Added a button to the PEP-8 dialog to reset the default values.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2876
diff changeset
273 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
274
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 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
276 """
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 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
278
1031
c0f795aa71a7 Fixed an issue in the PEP-8 fixer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
279 @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
280 @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
281 @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
282 @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
283 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
284 fix (integer)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 """
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
286 if isinstance(message, (tuple, list)):
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
287 code = message[0].strip()
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
288 else:
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
289 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
290
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
291 if (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
292 line <= len(self.__source) and
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
293 self.__codeMatch(code) and
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
294 code in self.__fixes
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
295 ):
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 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
297 if res[0] == 1:
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 self.__modified = True
853
ec7dd115e26b Continued implementing a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 852
diff changeset
299 self.fixed += 1
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 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
301 res = (0, "", 0)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 return res
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304
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
305 def finalize(self):
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 """
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
307 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
308
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
309 @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
310 """
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
311 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
312
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
313 # 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
314 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
315 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
316 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
317 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
318 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
319 results[id_] = (res, msg)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
320
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
321 # 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
322 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
323 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
324 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
325 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
326 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
327 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
328
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
329 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
330
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
331 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
332 """
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
333 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
334
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
335 @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
336 """
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
337 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
338 return self.__lastID
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
340 def __findLogical(self):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
341 """
2883
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
342 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
343 lines.
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
344
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
345 @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
346 of lines
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
347 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
348 logical_start = []
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
349 logical_end = []
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
350 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
351 sio = StringIO("".join(self.__source))
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
352 parens = 0
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
353 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
354 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
355 tokenize.INDENT, tokenize.NL,
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
356 tokenize.ENDMARKER]:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
357 continue
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
358 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
359 last_newline = True
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
360 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
361 continue
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
362 if last_newline and not parens:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
363 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
364 last_newline = False
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
365 if t[0] == tokenize.OP:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
366 if t[1] in '([{':
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
367 parens += 1
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
368 elif t[1] in '}])':
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
369 parens -= 1
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
370 return logical_start, logical_end
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
371
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
372 def __getLogical(self, line, pos):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
373 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
374 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
375 position.
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
376
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
377 @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
378 @param pos position inside line (integer)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
379 @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
380 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
381 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
382 source lines
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
383 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
384 try:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
385 (logical_start, logical_end) = self.__findLogical()
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
386 except (SyntaxError, tokenize.TokenError):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
387 return None
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
388
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
389 line = line - 1
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
390 ls = None
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
391 le = None
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
392 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
393 x = logical_end[i]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
394 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
395 le = x
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
396 ls = logical_start[i]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
397 break
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
398 if ls is None:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
399 return None
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
400
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
401 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
402 return ls, le, original
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
403
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
404 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
405 """
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
406 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
407
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
408 @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
409 """
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
410 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
411 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
412 try:
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
413 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
414 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
415 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
416 break
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
417 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
418 pass
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
419 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
420
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
421 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
422 """
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
423 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
424
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
425 @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
426 @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
427 """
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
428 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
429
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
430 def __multilineStringLines(self):
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
431 """
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
432 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
433 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
434
2883
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
435 @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
436 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
437 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
438 """
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
439 if self.__multiLineNumbers is None:
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
440 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
441 sio = StringIO(source)
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
442 self.__multiLineNumbers = set()
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
443 self.__docLineNumbers = set()
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
444 previousTokenType = ''
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
445 try:
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
446 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
447 tokenType = t[0]
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
448 startRow = t[2][0]
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
449 endRow = t[3][0]
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
450
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
451 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
452 if previousTokenType != tokenize.INDENT:
2883
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
453 self.__multiLineNumbers |= set(
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
454 range(startRow, 1 + endRow))
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
455 else:
2883
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
456 self.__docLineNumbers |= set(
3c99a1db1506 Finished the PEP-8 line shortener.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2882
diff changeset
457 range(startRow, 1 + endRow))
2882
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
458
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
459 previousTokenType = tokenType
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
460 except (SyntaxError, tokenize.TokenError):
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
461 pass
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
462
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
463 return self.__multiLineNumbers, self.__docLineNumbers
9b97bc92fdda Continued implementing the PEP-8 line shortener class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2880
diff changeset
464
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
465 def __fixReindent(self, line, pos, logical):
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
466 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
467 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
468
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
469 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
470
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
471 @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
472 @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
473 @param logical logical line structure
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
474 @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
475 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
476 assert logical
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
477 ls, _, original = logical
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
478
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
479 rewrapper = IndentationWrapper(original)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
480 valid_indents = rewrapper.pep8Expected()
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
481 if not rewrapper.rel_indent:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
482 return False
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
483
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
484 if line > ls[0]:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
485 # got a valid continuation line number
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
486 row = line - ls[0] - 1
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
487 # always pick the first option for this
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
488 valid = valid_indents[row]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
489 got = rewrapper.rel_indent[row]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
490 else:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
491 return False
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
492
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
493 line1 = ls[0] + row
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
494 # always pick the expected indent, for now.
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
495 indent_to = valid[0]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
496
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
497 if got != indent_to:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
498 orig_line = self.__source[line1]
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
499 new_line = ' ' * (indent_to) + orig_line.lstrip()
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
500 if new_line == orig_line:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
501 return False
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
502 else:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
503 self.__source[line1] = new_line
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
504 return True
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
505 else:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
506 return False
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
507
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
508 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
509 """
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
510 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
511
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
512 @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
513 @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
514 @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
515 @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
516 """
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
517 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
518 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
519 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
520 return line
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
521 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
522 return left + replacement + right
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
523
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
524 def __fixD111(self, code, line, pos):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
525 """
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
526 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
527
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
528 Codes: D111
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
529
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
530 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
531 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
532 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
533 @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
534 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
535 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
536 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
537 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
538 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
539 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
540 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
541 self.__source[line] = left + '"""' + right
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
542 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
543 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
544 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
545 self.__source[line] = left + '"""' + right
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
546 break
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
547 line += 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
548
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
549 # Triple single quotes converted to triple double quotes.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
550 return (1, "FIXD111", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
551
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
552 def __fixD112(self, code, line, pos):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
553 """
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
554 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
555
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
556 Codes: D112, D113
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
557
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
558 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
559 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
560 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
561 @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
562 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
563 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
564 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
565 line = line - 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
566 if code == "D112":
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
567 insertChar = "r"
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
568 elif code == "D113":
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
569 insertChar = "u"
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
570 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
571 return (0, "", 0)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
572
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
573 newText = (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
574 self.__getIndent(self.__source[line]) +
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
575 insertChar +
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
576 self.__source[line].lstrip()
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
577 )
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
578 self.__source[line] = newText
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
579 # Introductory quotes corrected to be {0}"""
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
580 return (1, ('FIXD112', (insertChar,)), 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
581
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
582 def __fixD121(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
583 """
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
584 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
585
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
586 Codes: D121
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
587
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
588 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
589 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
590 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
591 @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
592 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
593 @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
594 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
595 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
596 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
597 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
598 line = line - 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
599 if not self.__source[line].lstrip().startswith(
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
600 ('"""', 'r"""', 'u"""')):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
601 # only correctly formatted docstrings will be fixed
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
602 return (0, "", 0)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
603
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
604 docstring = (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
605 self.__source[line].rstrip() +
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
606 self.__source[line + 1].strip()
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
607 )
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
608 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
609 docstring += self.__eol
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
610 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
611 docstring += self.__source[line + 2].lstrip()
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
612 self.__source[line + 2] = ""
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
613
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
614 self.__source[line] = docstring
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
615 self.__source[line + 1] = ""
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
616 # Single line docstring put on one line.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
617 return (1, "FIXD121", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
618 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
619 fixId = self.__getID()
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
620 self.__stack.append((fixId, code, line, pos))
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
621 return (-1, "", fixId)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
622
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
623 def __fixD131(self, code, line, pos):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
624 """
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
625 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
626 period.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
627
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
628 Codes: D131
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
629
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
630 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
631 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
632 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
633 @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
634 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
635 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
636 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
637 line = line - 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
638 newText = ""
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
639 if (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
640 self.__source[line].rstrip().endswith(('"""', "'''")) and
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
641 self.__source[line].lstrip().startswith(('"""', 'r"""', 'u"""'))
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
642 ):
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
643 # it is a one-liner
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
644 newText = (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
645 self.__source[line].rstrip()[:-3].rstrip() +
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
646 "." +
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
647 self.__source[line].rstrip()[-3:] +
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
648 self.__eol
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
649 )
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
650 else:
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
651 if (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
652 line < len(self.__source) - 1 and
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
653 (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
654 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
655 (self.__source[line + 1].strip() in ('"""', "'''") and
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
656 not self.__source[line].lstrip().startswith("@")))
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
657 ):
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
658 newText = self.__source[line].rstrip() + "." + self.__eol
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
659
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
660 if newText:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
661 self.__source[line] = newText
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
662 # Period added to summary line.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
663 return (1, "FIXD131", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
664 else:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
665 return (0, "", 0)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
666
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
667 def __fixD141(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
668 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
669 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
670 blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
671
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
672 Codes: D141
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
673
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
674 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
675 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
676 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
677 @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
678 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
679 @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
680 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
681 fix (integer)
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 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
684 line = line - 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
685 self.__source[line - 1] = ""
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
686 # Blank line before function/method docstring removed.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
687 return (1, "FIXD141", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
688 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
689 fixId = self.__getID()
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
690 self.__stack.append((fixId, code, line, pos))
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
691 return (-1, "", fixId)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
692
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
693 def __fixD142(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
694 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
695 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
696 blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
697
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
698 Codes: D142
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
699
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
700 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
701 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
702 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
703 @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
704 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
705 @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
706 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
707 fix (integer)
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 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
710 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
711 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
712 # Blank line inserted before class docstring.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
713 return (1, "FIXD142", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
714 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
715 fixId = self.__getID()
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
716 self.__stack.append((fixId, code, line, pos))
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
717 return (-1, "", fixId)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
718
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
719 def __fixD143(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
720 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
721 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
722 blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
723
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
724 Codes: D143
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
725
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
726 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
727 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
728 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
729 @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
730 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
731 @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
732 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
733 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
734 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
735 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
736 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
737 self.__source[line] += self.__eol
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
738 # Blank line inserted after class docstring.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
739 return (1, "FIXD143", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
740 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
741 fixId = self.__getID()
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
742 self.__stack.append((fixId, code, line, pos))
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
743 return (-1, "", fixId)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
744
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
745 def __fixD144(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
746 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
747 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
748 blank line.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
749
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
750 Codes: D144
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
751
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
752 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
753 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
754 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
755 @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
756 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
757 @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
758 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
759 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
760 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
761 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
762 line = line - 1
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
763 if not self.__source[line].rstrip().endswith("."):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
764 # only correct summary lines can be fixed here
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
765 return (0, "", 0)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
766
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
767 self.__source[line] += self.__eol
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
768 # Blank line inserted after docstring summary.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
769 return (1, "FIXD144", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
770 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
771 fixId = self.__getID()
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
772 self.__stack.append((fixId, code, line, pos))
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
773 return (-1, "", fixId)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
774
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
775 def __fixD145(self, code, line, pos, apply=False):
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
776 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
777 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
778 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
779
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
780 Codes: D143
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
781
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
782 @param code code of the issue (string)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
783 @param line line number of the issue (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
784 @param pos position inside line (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
785 @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
786 (boolean)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
787 @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
788 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
789 fix (integer)
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
790 """
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
791 if apply:
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
792 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
793 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
794 # Blank line inserted after last paragraph of docstring.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
795 return (1, "FIXD145", 0)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
796 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
797 fixId = self.__getID()
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
798 self.__stack.append((fixId, code, line, pos))
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
799 return (-1, "", fixId)
2925
04896af1b0e1 Completed the PEP-257 fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2923
diff changeset
800
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
801 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
802 """
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
803 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
804 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
805
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
806 Codes: D221, D222
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
807
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
808 @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
809 @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
810 @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
811 @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
812 (boolean)
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
813 @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
814 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
815 fix (integer)
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
816 """
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
817 if apply:
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
818 line = line - 1
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
819 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
820 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
821 if code == "D221":
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
822 # leading
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
823 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
824 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
825 else:
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
826 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
827 else:
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
828 # trailing
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
829 first, second = source[:-3].strip(), source[-3:]
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
830 newText = (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
831 indent +
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
832 first +
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
833 self.__eol +
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
834 indent +
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
835 second +
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
836 self.__eol
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
837 )
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
838 self.__source[line] = newText
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
839 if code == "D221":
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
840 # Leading quotes put on separate line.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
841 msg = "FIXD221"
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
842 else:
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
843 # Trailing quotes put on separate line.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
844 msg = "FIXD222"
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
845 return (1, msg, 0)
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
846 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
847 fixId = self.__getID()
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
848 self.__stack.append((fixId, code, line, pos))
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
849 return (-1, "", fixId)
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2936
diff changeset
850
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
851 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
852 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
853 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
854 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
855
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
856 Codes: D242, D244
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
857
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
858 @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
859 @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
860 @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
861 @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
862 (boolean)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
863 @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
864 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
865 fix (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
866 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
867 if apply:
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
868 line = line - 1
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
869 self.__source[line - 1] = ""
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
870 if code == "D242":
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
871 # Blank line before class docstring removed.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
872 msg = "FIXD242"
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
873 else:
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
874 # Blank line before function/method docstring removed.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
875 msg = "FIXD244"
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
876 return (1, msg, 0)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
877 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
878 fixId = self.__getID()
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
879 self.__stack.append((fixId, code, line, pos))
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
880 return (-1, "", fixId)
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
881
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
882 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
883 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
884 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
885 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
886
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
887 Codes: D243, D245
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
888
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
889 @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
890 @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
891 @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
892 @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
893 (boolean)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
894 @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
895 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
896 fix (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
897 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
898 if apply:
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
899 line = line - 1
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
900 self.__source[line + 1] = ""
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
901 if code == "D243":
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
902 # Blank line after class docstring removed.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
903 msg = "FIXD243"
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
904 else:
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
905 # Blank line after function/method docstring removed.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
906 msg = "FIXD245"
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
907 return (1, msg, 0)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
908 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
909 fixId = self.__getID()
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
910 self.__stack.append((fixId, code, line, pos))
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
911 return (-1, "", fixId)
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
912
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
913 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
914 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
915 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
916 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
917
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
918 Codes: D247
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
919
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
920 @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
921 @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
922 @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
923 @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
924 (boolean)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
925 @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
926 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
927 fix (integer)
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
928 """
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
929 if apply:
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
930 line = line - 1
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
931 self.__source[line - 1] = ""
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
932 # Blank line after last paragraph removed.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
933 return (1, "FIXD247", 0)
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
934 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
935 fixId = self.__getID()
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
936 self.__stack.append((fixId, code, line, pos))
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
937 return (-1, "", fixId)
2936
2ff273068a10 Started implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
938
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
939 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
940 """
2960
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
941 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
942
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
943 Codes: E101, E111, W191
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
944
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
945 @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
946 @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
947 @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
948 @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
949 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
950 fix (integer)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
951 """
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
952 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
953 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
954 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
955 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
956 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
957 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
958 if code in ["E101", "W191"]:
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
959 # Tab converted to 4 spaces.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
960 msg = "FIXE101"
2868
8d30ec21e9c7 Extended the PEP8 fixer and adjusted it to the updated PEP8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
961 else:
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
962 # Indentation adjusted to be a multiple of four.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
963 msg = "FIXE111"
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
964 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
965 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
966 return (0, "", 0)
849
996367a89673 Started to implement a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
967
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
968 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
969 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
970 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
971 closing brackets.
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
972
9453efa25fd5 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2937
diff changeset
973 Codes: E121, E124
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
974
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
975 @param code code of the issue (string)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
976 @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
977 @param pos position inside line (integer)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
978 @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
979 (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
980 @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
981 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
982 fix (integer)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
983 """
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
984 if apply:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
985 logical = self.__getLogical(line, pos)
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
986 if logical:
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
987 # 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
988 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
989 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
990 if code == "E121":
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
991 # Indentation of continuation line corrected.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
992 msg = "FIXE121"
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
993 elif code == "E124":
3413
5e63f809732a Code style checker: Translations extracted and refactored.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3228
diff changeset
994 # Indentation of closing bracket corrected.
7609
d5aff4fd0ef8 Code Style Checker: changed the dialog to allow the selection of checker categories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
995 msg = "FIXE124"
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
996 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
997 return (0, "", 0)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
998 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
999 fixId = self.__getID()
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
1000 self.__stackLogical.append((fixId, code, line, pos))
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
1001 return (-1, "", fixId)
2875
1267f0663801 Continued implementing PEP-8 fixer methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2868
diff changeset
1002