Beispiel #1
0
    def compute(self, code, annotations):
        start_line = 0
        no_whitespace_run = 0
        levels = None

        for line_no, line in enumerate(code.lines):

            level = code.levels[line_no]
            if no_whitespace_run > 0:
                if not code.levels[line_no]:
                    if no_whitespace_run > MAX_NON_WHITESPACE_LINES:
                        error = "Not enough whitespace"
                        self.add_to_annotations(start_line, error, annotations)
                    no_whitespace_run = 0
                    continue

                levels = levels & set(level)  # check for consistent indent
                if len(levels) == 0 or is_whitespace_line(line):
                    if no_whitespace_run > MAX_NON_WHITESPACE_LINES:
                        error = "Not enough whitespace"
                        self.add_to_annotations(start_line, error, annotations)
                    no_whitespace_run = 0
                else:
                    if 0 not in code.levels[line_no]:
                        no_whitespace_run += 1

            elif not is_whitespace_line(line) and not is_comment(line) and level:
                levels = set(level)
                no_whitespace_run = 1
                start_line = line_no
Beispiel #2
0
 def compute(self, code, annotations):
     start_line = 0
     whitespace_run = 0
     for line_no, line in enumerate(code.lines):
         if is_whitespace_line(line):
             if whitespace_run > 0:
                 whitespace_run += 1
             else:
                 whitespace_run = 1
                 start_line = line_no
         else:
             # end of run
             if whitespace_run > MAX_WHITESPACE_LINES:
                 error = "Excess whitespace"
                 self.add_to_annotations(start_line, error, annotations)
             whitespace_run = 0
Beispiel #3
0
    def test_is_whitespace_line(self):
        from utils.line_features import is_whitespace_line

        self.assertEqual(is_whitespace_line(""), True)
        self.assertEqual(is_whitespace_line("\t\t  \t"), True)
        self.assertEqual(is_whitespace_line("\t\t {\t"), False)