eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8043
0acf98cd089a
child 8207
d359172d11be
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

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