Plugins/CheckerPlugins/Pep8/Pep8Fixer.py

changeset 851
321d29b93238
parent 849
996367a89673
child 852
257a6f80b96c
equal deleted inserted replaced
850:8b9f09e7d5d9 851:321d29b93238
14 14
15 from E5Gui import E5MessageBox 15 from E5Gui import E5MessageBox
16 16
17 import Utilities 17 import Utilities
18 18
19 Pep8FixableIssues = ["W191", "W291", "W292", "W293", "E301", "E303", "E304", "W391", "W603"] 19 Pep8FixableIssues = ["E101", "W191", "E201", "E202", "E203", "W291", "W292", "W293", "E301", "E303", "E304", "W391", "W603"]
20 20
21 class Pep8Fixer(QObject): 21 class Pep8Fixer(QObject):
22 """ 22 """
23 Class implementing a fixer for certain PEP 8 issues. 23 Class implementing a fixer for certain PEP 8 issues.
24 """ 24 """
46 self.__origName = self.__filename 46 self.__origName = self.__filename
47 self.__filename = os.path.join(os.path.dirname(self.__filename), 47 self.__filename = os.path.join(os.path.dirname(self.__filename),
48 "fixed_" + os.path.basename(self.__filename)) 48 "fixed_" + os.path.basename(self.__filename))
49 49
50 self.__fixes = { 50 self.__fixes = {
51 "W191" : self.__fixTabs, 51 "E101" : self.__fixTabs,
52 "W191" : self.__fixTabs,
53 "E201" : self.__fixWhitespaceAfter,
54 "E202" : self.__fixWhitespaceBefore,
55 "E203" : self.__fixWhitespaceBefore,
52 "W291" : self.__fixWhitespace, 56 "W291" : self.__fixWhitespace,
53 "W292" : self.__fixNewline, 57 "W292" : self.__fixNewline,
54 "W293" : self.__fixWhitespace, 58 "W293" : self.__fixWhitespace,
55 "E301" : self.__fixOneBlankLine, 59 "E301" : self.__fixOneBlankLine,
56 "E303" : self.__fixTooManyBlankLines, 60 "E303" : self.__fixTooManyBlankLines,
275 if apply: 279 if apply:
276 self.__source.insert(line - 1, self.__getEol()) 280 self.__source.insert(line - 1, self.__getEol())
277 else: 281 else:
278 self.__stack.append((code, line, pos)) 282 self.__stack.append((code, line, pos))
279 return (True, self.trUtf8("One blank line inserted.")) 283 return (True, self.trUtf8("One blank line inserted."))
284
285 def __fixWhitespaceAfter(self, code, line, pos, apply=False):
286 """
287 Private method to fix superfluous whitespace after '([{'.
288
289 @param code code of the issue (string)
290 @param line line number of the issue (integer)
291 @param pos position inside line (integer)
292 @keyparam apply flag indicating, that the fix should be applied
293 (boolean)
294 @return flag indicating an applied fix (boolean) and a message for
295 the fix (string)
296 """
297 line = line - 1
298 pos = pos - 1
299 while self.__source[line][pos] in [" ", "\t"]:
300 self.__source[line] = self.__source[line][:pos] + \
301 self.__source[line][pos + 1:]
302 return (True, self.trUtf8("Superfluous whitespace removed."))
303
304 def __fixWhitespaceBefore(self, code, line, pos, apply=False):
305 """
306 Private method to fix superfluous whitespace before '}])'
307 and ',;:'.
308
309 @param code code of the issue (string)
310 @param line line number of the issue (integer)
311 @param pos position inside line (integer)
312 @keyparam apply flag indicating, that the fix should be applied
313 (boolean)
314 @return flag indicating an applied fix (boolean) and a message for
315 the fix (string)
316 """
317 line = line - 1
318 pos = pos - 1
319 while self.__source[line][pos] in [" ", "\t"]:
320 self.__source[line] = self.__source[line][:pos] + \
321 self.__source[line][pos + 1:]
322 pos -= 1
323 return (True, self.trUtf8("Superfluous whitespace removed."))

eric ide

mercurial