~adiroiban/pocket-lint/pep-in-memory

« back to all changes in this revision

Viewing changes to pocketlint/formatcheck.py

  • Committer: Curtis Hovey
  • Date: 2014-03-09 19:13:09 UTC
  • mfrom: (397.15.3 1237862-pep-257)
  • Revision ID: curtis@hovey.name-20140309191309-ligdwuqamkvy83e8
Merge support fot pep257.

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
except ImportError:
84
84
    closure_linter = None
85
85
 
 
86
try:
 
87
    import pep257
 
88
    # Shut up the linter.
 
89
    pep257
 
90
except ImportError:
 
91
    pep257 = None
 
92
 
86
93
 
87
94
IS_PY3 = True if sys.version_info >= (3,) else False
88
95
 
627
634
        self.check_text()
628
635
        self.check_flakes()
629
636
        self.check_pep8()
 
637
        self.check_pep257()
630
638
        self.check_windows_endlines()
631
639
 
632
640
    def check_flakes(self):
665
673
            message = "%s: %s" % (message, location[3].strip())
666
674
            self.message(location[1], message, icon='error')
667
675
 
 
676
    def check_pep257(self):
 
677
        """PEP 257 docstring style checker."""
 
678
        if not pep257:
 
679
            # PEP257 is not available.
 
680
            return
 
681
 
 
682
        ignore_list = getattr(self.options, 'pep257_ignore', [])
 
683
 
 
684
        results = pep257.check_source(self.text, self.file_path)
 
685
 
 
686
        for error in results:
 
687
            # PEP257 message contains the short error as first line from
 
688
            # the long docstring explanation.
 
689
            error_message = error.explanation.splitlines()[0]
 
690
            if error_message in ignore_list:
 
691
                continue
 
692
            self.message(error.line, error_message, icon='error')
 
693
 
668
694
    def check_text(self):
669
695
        """Call each line_method for each line in text."""
670
696
        for line_no, line in enumerate(self.text.splitlines()):
678
704
            self.check_ascii(line_no, line)
679
705
 
680
706
    def check_pdb(self, line_no, line):
681
 
        """Check the length of the line."""
 
707
        """Check for pdb breakpoints."""
 
708
        # Set trace call is split so that this file will pass the linter.
682
709
        pdb_call = 'pdb.' + 'set_trace'
683
710
        if pdb_call in line:
684
711
            self.message(