~afrantzis/bzr-text-checker/empty-line-at-eof

« back to all changes in this revision

Viewing changes to text_checker.py

  • Committer: Marius Kruger
  • Date: 2009-05-04 22:10:53 UTC
  • Revision ID: amanic@gmail.com-20090504221053-5a2mcgv0isnpymhl
Always store line numbers as 1-based like editors show it, 
and don't increment it when displaying.
Fixup the bad tests that where wrong.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
            dict_[fname].append(line_no)
59
59
 
60
60
    def _format_message(self, dict_, message):
61
 
        files = ["%s: %s" % (f, ', '.join([str(i+1) for i in lines]))
 
61
        files = ["%s: %s" % (f, ', '.join([str(i) for i in lines]))
62
62
                for f, lines in dict_.items()]
63
63
        files.sort()
64
64
        return message + '\n    %s' % ('\n    '.join(files))
100
100
 
101
101
        def check_newlines(j1, j2):
102
102
            for i, line in enumerate(newlines[j1:j2]):
 
103
                line_no = i+1+j1
103
104
                trailing_ws_match = re.match(r'^((.*?)([\t ]*))(\r?\n)?$',
104
105
                    line)
105
106
                if '\t' in line:
106
 
                    self._push_file_line(self.tabs, new_filename, i+1+j1)
 
107
                    self._push_file_line(self.tabs, new_filename, line_no)
107
108
                if trailing_ws_match:
108
109
                    line_content = trailing_ws_match.group(1)
109
110
                    has_trailing_whitespace = bool(trailing_ws_match.group(3))
110
111
                    if has_trailing_whitespace:
111
112
                        self._push_file_line(self.trailing_whitespace,
112
 
                            new_filename, i+1+j1)
 
113
                            new_filename, line_no)
113
114
                    if len(line_content) > self.long_line_length:
114
115
                        self._push_file_line(self.long_lines,
115
 
                            new_filename, i+1+j1)
 
116
                            new_filename, line_no)
116
117
 
117
118
        for group in sequence_matcher(None, oldlines, newlines
118
119
                ).get_grouped_opcodes(0):