Plugins/CheckerPlugins/Pep8/Pep8Dialog.py

changeset 2915
9da653363d07
parent 2914
6b30a602e404
child 2916
a8628dfdfe04
equal deleted inserted replaced
2914:6b30a602e404 2915:9da653363d07
25 from . import pep8 25 from . import pep8
26 from .Pep8NamingChecker import Pep8NamingChecker 26 from .Pep8NamingChecker import Pep8NamingChecker
27 27
28 # register the name checker 28 # register the name checker
29 pep8.register_check(Pep8NamingChecker, Pep8NamingChecker.Codes) 29 pep8.register_check(Pep8NamingChecker, Pep8NamingChecker.Codes)
30
31 from .Pep257Checker import Pep257Checker
30 32
31 33
32 class Pep8Report(pep8.BaseReport): 34 class Pep8Report(pep8.BaseReport):
33 """ 35 """
34 Class implementing a special report to be used with our dialog. 36 Class implementing a special report to be used with our dialog.
150 ["{0:6}".format(line), code, message]) 152 ["{0:6}".format(line), code, message])
151 if code.startswith("W"): 153 if code.startswith("W"):
152 itm.setIcon(1, UI.PixmapCache.getIcon("warning.png")) 154 itm.setIcon(1, UI.PixmapCache.getIcon("warning.png"))
153 elif code.startswith("N"): 155 elif code.startswith("N"):
154 itm.setIcon(1, UI.PixmapCache.getIcon("namingError.png")) 156 itm.setIcon(1, UI.PixmapCache.getIcon("namingError.png"))
157 elif code.startswith("D"):
158 itm.setIcon(1, UI.PixmapCache.getIcon("docstringError.png"))
155 else: 159 else:
156 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png")) 160 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png"))
157 if fixed: 161 if fixed:
158 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixed.png")) 162 itm.setIcon(0, UI.PixmapCache.getIcon("issueFixed.png"))
159 elif code in Pep8FixableIssues and not autofixing: 163 elif code in Pep8FixableIssues and not autofixing:
404 ignore=excludeMessages, 408 ignore=excludeMessages,
405 max_line_length=maxLineLength, 409 max_line_length=maxLineLength,
406 hang_closing=hangClosing, 410 hang_closing=hangClosing,
407 ) 411 )
408 report.errors.sort(key=lambda a: a[1]) 412 report.errors.sort(key=lambda a: a[1])
413 # TODO: add PEP-257 check for Py2
409 else: 414 else:
410 if includeMessages: 415 if includeMessages:
411 select = [s.strip() for s in includeMessages.split(',') 416 select = [s.strip() for s in includeMessages.split(',')
412 if s.strip()] 417 if s.strip()]
413 else: 418 else:
415 if excludeMessages: 420 if excludeMessages:
416 ignore = [i.strip() for i in excludeMessages.split(',') 421 ignore = [i.strip() for i in excludeMessages.split(',')
417 if i.strip()] 422 if i.strip()]
418 else: 423 else:
419 ignore = [] 424 ignore = []
425
426 # check PEP-8
420 styleGuide = pep8.StyleGuide( 427 styleGuide = pep8.StyleGuide(
421 reporter=Pep8Report, 428 reporter=Pep8Report,
422 repeat=repeatMessages, 429 repeat=repeatMessages,
423 select=select, 430 select=select,
424 ignore=ignore, 431 ignore=ignore,
425 max_line_length=maxLineLength, 432 max_line_length=maxLineLength,
426 hang_closing=hangClosing, 433 hang_closing=hangClosing,
427 ) 434 )
428 report = styleGuide.check_files([file]) 435 report = styleGuide.check_files([file])
429 report.errors.sort(key=lambda a: a[1]) 436 report.errors.sort(key=lambda a: a[1])
437
438 # check PEP-257
439 pep257Checker = Pep257Checker(
440 source, file, select, ignore, [], repeatMessages)
441 pep257Checker.run()
442 pep257Checker.errors.sort(key=lambda a: a[1])
443
430 deferredFixes = {} 444 deferredFixes = {}
431 for error in report.errors: 445 for error in report.errors + pep257Checker.errors:
432 fname, lineno, position, text = error 446 fname, lineno, position, text = error
433 if lineno > len(source): 447 if lineno > len(source):
434 lineno = len(source) 448 lineno = len(source)
435 if "__IGNORE_WARNING__" not in Utilities.extractLineFlags( 449 if "__IGNORE_WARNING__" not in Utilities.extractLineFlags(
436 source[lineno - 1].strip()): 450 source[lineno - 1].strip()):
462 text = "\n" + self.trUtf8("Fix: {0}").format(msg) 476 text = "\n" + self.trUtf8("Fix: {0}").format(msg)
463 self.__modifyFixedResultItem(itm, text, True) 477 self.__modifyFixedResultItem(itm, text, True)
464 else: 478 else:
465 self.__modifyFixedResultItem(itm, "", False) 479 self.__modifyFixedResultItem(itm, "", False)
466 fixer.saveFile(encoding) 480 fixer.saveFile(encoding)
467 self.__updateStatistics(report.counters, fixer) 481 stats = {}
482 stats.update(report.counters)
483 stats.update(pep257Checker.counters)
484 self.__updateStatistics(stats, fixer)
468 progress += 1 485 progress += 1
469 finally: 486 finally:
470 # reenable updates of the list 487 # reenable updates of the list
471 self.resultList.setSortingEnabled(True) 488 self.resultList.setSortingEnabled(True)
472 self.resultList.setUpdatesEnabled(True) 489 self.resultList.setUpdatesEnabled(True)

eric ide

mercurial